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.
CommandBase.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="CommandBase.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>This is the base class from which command </summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.ComponentModel;
11using Csla.Server;
12using Csla.Properties;
13using Csla.Core;
16using System.Linq.Expressions;
17using Csla.Reflection;
18using System.Reflection;
19using System.Threading.Tasks;
20
21namespace Csla
22{
46 public abstract class CommandBase<T> : ManagedObjectBase,
47 ICommandObject, ICloneable,
48 Csla.Server.IDataPortalTarget, Csla.Core.IManageProperties,
50 where T : CommandBase<T>
51 {
55 public CommandBase()
56 {
57 Initialize();
58 }
59
60 #region Initialize
61
67 protected virtual void Initialize()
68 { /* allows subclass to initialize events before any other activity occurs */ }
69
70 #endregion
71
72 #region Identity
73
75 {
76 get { return 0; }
77 }
78
79 #endregion
80
81 #region Data Access
82
83 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "criteria")]
84 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
85 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
86 private void DataPortal_Create(object criteria)
87 {
88 throw new NotSupportedException(Resources.CreateNotSupportedException);
89 }
90
91 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "criteria")]
92 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
93 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
94 private void DataPortal_Fetch(object criteria)
95 {
96 throw new NotSupportedException(Resources.FetchNotSupportedException);
97 }
98
99 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
100 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
101 private void DataPortal_Update()
102 {
103 throw new NotSupportedException(Resources.UpdateNotSupportedException);
104 }
105
106 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "criteria")]
107 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
108 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
109 [Delete]
110 private void DataPortal_Delete(object criteria)
111 {
112 throw new NotSupportedException(Resources.DeleteNotSupportedException);
113 }
114
120 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
121 [EditorBrowsable(EditorBrowsableState.Advanced)]
123 {
124
125 }
126
132 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
133 [EditorBrowsable(EditorBrowsableState.Advanced)]
135 {
136
137 }
138
145 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores", MessageId = "Member")]
146 [EditorBrowsable(EditorBrowsableState.Advanced)]
147 protected virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
148 {
149
150 }
151
152 #endregion
153
154 #region IDataPortalTarget Members
155
156 void IDataPortalTarget.CheckRules()
157 { }
158
159 void IDataPortalTarget.MarkAsChild()
160 { }
161
162 void IDataPortalTarget.MarkNew()
163 { }
164
165 void IDataPortalTarget.MarkOld()
166 { }
167
168 void IDataPortalTarget.DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
169 {
171 }
172
173 void IDataPortalTarget.DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
174 {
176 }
177
178 void IDataPortalTarget.DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
179 {
181 }
182
183 void IDataPortalTarget.Child_OnDataPortalInvoke(DataPortalEventArgs e)
184 { }
185
186 void IDataPortalTarget.Child_OnDataPortalInvokeComplete(DataPortalEventArgs e)
187 { }
188
189 void IDataPortalTarget.Child_OnDataPortalException(DataPortalEventArgs e, Exception ex)
190 { }
191
192 #endregion
193
194 #region ICloneable
195
196 object ICloneable.Clone()
197 {
198 return GetClone();
199 }
200
207 [EditorBrowsable(EditorBrowsableState.Advanced)]
208 protected virtual object GetClone()
209 {
210 return Core.ObjectCloner.GetInstance(ApplicationContext).Clone(this);
211 }
212
219 public T Clone()
220 {
221 return (T)GetClone();
222 }
223
224 #endregion
225
226 #region Register Properties
227
242 {
243 return Core.FieldManager.PropertyInfoManager.RegisterProperty<P>(typeof(T), info);
244 }
245
253 protected static PropertyInfo<P> RegisterProperty<P>(string propertyName)
254 {
255 return RegisterProperty(Csla.Core.FieldManager.PropertyInfoFactory.Factory.Create<P>(typeof(T), propertyName));
256 }
257
265 protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>> propertyLambdaExpression)
266 {
267 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
268 return RegisterProperty<P>(reflectedPropertyInfo.Name);
269 }
270
279 protected static PropertyInfo<P> RegisterProperty<P>(string propertyName, RelationshipTypes relationship)
280 {
281 return RegisterProperty(Csla.Core.FieldManager.PropertyInfoFactory.Factory.Create<P>(typeof(T), propertyName, string.Empty, relationship));
282 }
283
292 protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>> propertyLambdaExpression, RelationshipTypes relationship)
293 {
294 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
295 return RegisterProperty<P>(reflectedPropertyInfo.Name, relationship);
296 }
297
306 protected static PropertyInfo<P> RegisterProperty<P>(string propertyName, string friendlyName)
307 {
308 return RegisterProperty(Csla.Core.FieldManager.PropertyInfoFactory.Factory.Create<P>(typeof(T), propertyName, friendlyName));
309 }
310
319 protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>> propertyLambdaExpression, string friendlyName)
320 {
321 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
322 return RegisterProperty<P>(reflectedPropertyInfo.Name, friendlyName);
323 }
324
334 protected static PropertyInfo<P> RegisterProperty<P>(string propertyName, string friendlyName, P defaultValue)
335 {
336 return RegisterProperty(Csla.Core.FieldManager.PropertyInfoFactory.Factory.Create<P>(typeof(T), propertyName, friendlyName, defaultValue));
337 }
338
348 protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>> propertyLambdaExpression, string friendlyName, P defaultValue)
349 {
350 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
351 return RegisterProperty<P>(reflectedPropertyInfo.Name, friendlyName, defaultValue);
352 }
353
364 protected static PropertyInfo<P> RegisterProperty<P>(string propertyName, string friendlyName, P defaultValue, RelationshipTypes relationship)
365 {
366 return RegisterProperty(Csla.Core.FieldManager.PropertyInfoFactory.Factory.Create<P>(typeof(T), propertyName, friendlyName, defaultValue, relationship));
367 }
368
379 protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>> propertyLambdaExpression, string friendlyName, P defaultValue, RelationshipTypes relationship)
380 {
381 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
382 return RegisterProperty<P>(reflectedPropertyInfo.Name, friendlyName, defaultValue, relationship);
383 }
384
385 #endregion
386
387 #region IManageProperties Members
388
389 bool IManageProperties.HasManagedProperties
390 {
391 get { return (FieldManager != null && FieldManager.HasFields); }
392 }
393
394 List<IPropertyInfo> IManageProperties.GetManagedProperties()
395 {
396 return FieldManager.GetRegisteredProperties();
397 }
398
399 object IManageProperties.GetProperty(IPropertyInfo propertyInfo)
400 {
401 return ReadProperty(propertyInfo);
402 }
403
404 object IManageProperties.ReadProperty(IPropertyInfo propertyInfo)
405 {
406 return ReadProperty(propertyInfo);
407 }
408
409 P IManageProperties.ReadProperty<P>(PropertyInfo<P> propertyInfo)
410 {
411 return ReadProperty<P>(propertyInfo);
412 }
413
414 void IManageProperties.SetProperty(IPropertyInfo propertyInfo, object newValue)
415 {
416 FieldManager.SetFieldData(propertyInfo, newValue);
417 }
418
419 void IManageProperties.LoadProperty(IPropertyInfo propertyInfo, object newValue)
420 {
421 LoadProperty(propertyInfo, newValue);
422 }
423
424 void IManageProperties.LoadProperty<P>(PropertyInfo<P> propertyInfo, P newValue)
425 {
426 LoadProperty<P>(propertyInfo, newValue);
427 }
428
429 bool IManageProperties.LoadPropertyMarkDirty(IPropertyInfo propertyInfo, object newValue)
430 {
431 LoadProperty(propertyInfo, newValue);
432 return false;
433 }
434
435 List<object> IManageProperties.GetChildren()
436 {
437 return FieldManager.GetChildren();
438 }
439
440 bool IManageProperties.FieldExists(Core.IPropertyInfo property)
441 {
442 return FieldManager.FieldExists(property);
443 }
444
445 object IManageProperties.LazyGetProperty<P>(PropertyInfo<P> propertyInfo, Func<P> valueGenerator)
446 {
447 throw new NotImplementedException();
448 }
449
450 object IManageProperties.LazyGetPropertyAsync<P>(PropertyInfo<P> propertyInfo, Task<P> factory)
451 {
452 throw new NotImplementedException();
453 }
454
455 P IManageProperties.LazyReadProperty<P>(PropertyInfo<P> propertyInfo, Func<P> valueGenerator)
456 {
457 throw new NotImplementedException();
458 }
459
460 P IManageProperties.LazyReadPropertyAsync<P>(PropertyInfo<P> propertyInfo, Task<P> factory)
461 {
462 throw new NotImplementedException();
463 }
464
465 #endregion
466 }
467}
Provides consistent context information between the client and server DataPortal objects.
This is the base class from which command objects will be derived.
Definition: CommandBase.cs:51
CommandBase()
Creates an instance of the type.
Definition: CommandBase.cs:55
static PropertyInfo< P > RegisterProperty< P >(PropertyInfo< P > info)
Indicates that the specified property belongs to the business object type.
Definition: CommandBase.cs:241
virtual void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
Called by the server-side DataPortal after calling the requested DataPortal_xyz method.
Definition: CommandBase.cs:134
T Clone()
Creates a clone of the object.
Definition: CommandBase.cs:219
virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
Called by the server-side DataPortal if an exception occurs during server-side processing.
Definition: CommandBase.cs:147
virtual void DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
Called by the server-side DataPortal prior to calling the requested DataPortal_xyz method.
Definition: CommandBase.cs:122
virtual void Initialize()
Override this method to set up event handlers so user code in a partial class can respond to events r...
Definition: CommandBase.cs:67
virtual object GetClone()
Creates a clone of the object.
Definition: CommandBase.cs:208
Base class for an object that is serializable using SerializationFormatterFactory....
FieldDataManager FieldManager
Gets a reference to the field mananger for this object.
Provides information about the DataPortal call.
A strongly-typed resource class, for looking up localized strings, etc.
static string CreateNotSupportedException
Looks up a localized string similar to Invalid operation - create not allowed.
static string FetchNotSupportedException
Looks up a localized string similar to Invalid operation - fetch not allowed.
static string DeleteNotSupportedException
Looks up a localized string similar to Invalid operation - delete not allowed.
static string UpdateNotSupportedException
Looks up a localized string similar to Invalid operation - update not allowed.
Maintains metadata about a property.
string Name
Gets the property name value.
This is the core interface implemented by all CSLA .NET base classes.
int Identity
Gets a value representing this object instance's unique identity value within the business object gra...
This interface is implemented by all Command objects.
Maintains metadata about a property.
This is the base class from which command objects will be derived.
Definition: ICommandBase.cs:19
RelationshipTypes
List of valid relationship types between a parent object and another object through a managed propert...
@ Serializable
Prevents updating or inserting until the transaction is complete.
@ Delete
Delete operation.