CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
RevalidatingInterceptor.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="RevalidatingInterceptor.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Initiates revalidation on business objects during data portal operations</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections;
10using System.Collections.Generic;
11using System.Linq;
12using System.Text;
13using System.Threading.Tasks;
14using Csla.Core;
15using Csla.Properties;
16
18{
23 {
24 private readonly ApplicationContext _applicationContext;
25
31 {
32 _applicationContext = applicationContext;
33 }
34
41 {
42 ITrackStatus checkableObject;
43
44 if (_applicationContext.ExecutionLocation != ApplicationContext.ExecutionLocations.Server
45 || _applicationContext.LogicalExecutionLocation != ApplicationContext.LogicalExecutionLocations.Server)
46 {
47 return;
48 }
49
50 checkableObject = e.Parameter as ITrackStatus;
51 if (checkableObject is null) return;
52
53 RevalidateObject(checkableObject);
54 if (!checkableObject.IsValid)
55 {
56 throw new Rules.ValidationException(Resources.NoSaveInvalidException);
57 }
58 }
59
64 public void Complete(InterceptArgs e)
65 {
66 }
67
72 private void RevalidateObject(object parameter)
73 {
74 if (parameter is IEnumerable list)
75 {
76 // Handle the object being a collection
77 foreach (object item in list)
78 {
79 RevalidateObject(item);
80 }
81 }
82 else
83 {
84 if (parameter is ICheckRules checkableObject)
85 {
86 // object not a collection, see if it has rules
87 var task = checkableObject.CheckRulesAsync();
88 // wait for all async rules to complete before proceeding
89 while (!task.IsCompleted)
90 Task.Delay(1);
91 }
92
93 // Cascade to any child objects
94 if (parameter is IUseFieldManager fieldHolder)
95 {
96 var properties = fieldHolder.FieldManager.GetRegisteredProperties();
97 foreach (var property in properties.Where(r=>r.IsChild && fieldHolder.FieldManager.FieldExists(r)))
98 {
99 RevalidateObject(fieldHolder.FieldManager.GetFieldData(property).Value);
100 }
101 }
102 else if (parameter is IManageProperties propertyHolder)
103 {
104 foreach (object child in propertyHolder.GetChildren())
105 {
106 RevalidateObject(child);
107 }
108 }
109 }
110 }
111 }
112}
Provides consistent context information between the client and server DataPortal objects.
ExecutionLocations
Enum representing the locations code can execute.
LogicalExecutionLocations
Enum representing the logical execution location The setting is set to server when server is execting...
A strongly-typed resource class, for looking up localized strings, etc.
static string NoSaveInvalidException
Looks up a localized string similar to Object is not valid and can not be saved.
Arguments parameter passed to the interceptor methods.
object Parameter
Gets or sets the criteria or business object paramter provided to the data portal from the client.
DataPortal interceptor to perform revalidation on business objects
void Initialize(InterceptArgs e)
Interception handler run before a DataPortal operation
RevalidatingInterceptor(ApplicationContext applicationContext)
Public constructor, intended to be executed by DI
void Complete(InterceptArgs e)
Interception handler run after a DataPortal operation
Defines the common methods for any business object which exposes means to supress and check business ...
Definition: ICheckRules.cs:18
Defines the common properties required objects that track their own status.
Definition: ITrackStatus.cs:17
bool IsValid
Returns true if the object and its child objects are currently valid, false if the object or any of i...
Definition: ITrackStatus.cs:37
Implement this interface to create a data portal interceptor that is notified each time the data port...