CSLA.NET 5.4.2
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 ObjectCloner.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 [Obsolete]
280 protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>> propertyLambdaExpression, P defaultValue)
281 {
282 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
283
284 return RegisterProperty(Csla.Core.FieldManager.PropertyInfoFactory.Factory.Create<P>(typeof(T), reflectedPropertyInfo.Name, reflectedPropertyInfo.Name, defaultValue));
285 }
286
295 protected static PropertyInfo<P> RegisterProperty<P>(string propertyName, RelationshipTypes relationship)
296 {
297 return RegisterProperty(Csla.Core.FieldManager.PropertyInfoFactory.Factory.Create<P>(typeof(T), propertyName, string.Empty, relationship));
298 }
299
308 protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>> propertyLambdaExpression, RelationshipTypes relationship)
309 {
310 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
311 return RegisterProperty<P>(reflectedPropertyInfo.Name, relationship);
312 }
313
322 protected static PropertyInfo<P> RegisterProperty<P>(string propertyName, string friendlyName)
323 {
324 return RegisterProperty(Csla.Core.FieldManager.PropertyInfoFactory.Factory.Create<P>(typeof(T), propertyName, friendlyName));
325 }
326
335 protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>> propertyLambdaExpression, string friendlyName)
336 {
337 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
338 return RegisterProperty<P>(reflectedPropertyInfo.Name, friendlyName);
339 }
340
350 [Obsolete]
351 protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>> propertyLambdaExpression, string friendlyName, RelationshipTypes relationship)
352 {
353 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
354
355 return RegisterProperty(Csla.Core.FieldManager.PropertyInfoFactory.Factory.Create<P>(typeof(T), reflectedPropertyInfo.Name, friendlyName, relationship));
356 }
357
367 protected static PropertyInfo<P> RegisterProperty<P>(string propertyName, string friendlyName, P defaultValue)
368 {
369 return RegisterProperty(Csla.Core.FieldManager.PropertyInfoFactory.Factory.Create<P>(typeof(T), propertyName, friendlyName, defaultValue));
370 }
371
381 protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>> propertyLambdaExpression, string friendlyName, P defaultValue)
382 {
383 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
384 return RegisterProperty<P>(reflectedPropertyInfo.Name, friendlyName, defaultValue);
385 }
386
397 protected static PropertyInfo<P> RegisterProperty<P>(string propertyName, string friendlyName, P defaultValue, RelationshipTypes relationship)
398 {
399 return RegisterProperty(Csla.Core.FieldManager.PropertyInfoFactory.Factory.Create<P>(typeof(T), propertyName, friendlyName, defaultValue, relationship));
400 }
401
412 protected static PropertyInfo<P> RegisterProperty<P>(Expression<Func<T, object>> propertyLambdaExpression, string friendlyName, P defaultValue, RelationshipTypes relationship)
413 {
414 PropertyInfo reflectedPropertyInfo = Reflect<T>.GetProperty(propertyLambdaExpression);
415 return RegisterProperty<P>(reflectedPropertyInfo.Name, friendlyName, defaultValue, relationship);
416 }
417
418 #endregion
419
420 #region IManageProperties Members
421
422 bool IManageProperties.HasManagedProperties
423 {
424 get { return (FieldManager != null && FieldManager.HasFields); }
425 }
426
427 List<IPropertyInfo> IManageProperties.GetManagedProperties()
428 {
429 return FieldManager.GetRegisteredProperties();
430 }
431
432 object IManageProperties.GetProperty(IPropertyInfo propertyInfo)
433 {
434 return ReadProperty(propertyInfo);
435 }
436
437 object IManageProperties.ReadProperty(IPropertyInfo propertyInfo)
438 {
439 return ReadProperty(propertyInfo);
440 }
441
442 P IManageProperties.ReadProperty<P>(PropertyInfo<P> propertyInfo)
443 {
444 return ReadProperty<P>(propertyInfo);
445 }
446
447 void IManageProperties.SetProperty(IPropertyInfo propertyInfo, object newValue)
448 {
449 FieldManager.SetFieldData(propertyInfo, newValue);
450 }
451
452 void IManageProperties.LoadProperty(IPropertyInfo propertyInfo, object newValue)
453 {
454 LoadProperty(propertyInfo, newValue);
455 }
456
457 void IManageProperties.LoadProperty<P>(PropertyInfo<P> propertyInfo, P newValue)
458 {
459 LoadProperty<P>(propertyInfo, newValue);
460 }
461
462 bool IManageProperties.LoadPropertyMarkDirty(IPropertyInfo propertyInfo, object newValue)
463 {
464 LoadProperty(propertyInfo, newValue);
465 return false;
466 }
467
468 List<object> IManageProperties.GetChildren()
469 {
470 return FieldManager.GetChildren();
471 }
472
473 bool IManageProperties.FieldExists(Core.IPropertyInfo property)
474 {
475 return FieldManager.FieldExists(property);
476 }
477
478 object IManageProperties.LazyGetProperty<P>(PropertyInfo<P> propertyInfo, Func<P> valueGenerator)
479 {
480 throw new NotImplementedException();
481 }
482
483 object IManageProperties.LazyGetPropertyAsync<P>(PropertyInfo<P> propertyInfo, Task<P> factory)
484 {
485 throw new NotImplementedException();
486 }
487
488 P IManageProperties.LazyReadProperty<P>(PropertyInfo<P> propertyInfo, Func<P> valueGenerator)
489 {
490 throw new NotImplementedException();
491 }
492
493 P IManageProperties.LazyReadPropertyAsync<P>(PropertyInfo<P> propertyInfo, Task<P> factory)
494 {
495 throw new NotImplementedException();
496 }
497
498 #endregion
499 }
500}
This is the base class from which command objects will be derived.
Definition: CommandBase.cs:51
CommandBase()
Creates an instance of the object.
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.