9using System.ComponentModel;
10using System.Collections.Generic;
13using System.Threading.Tasks;
23 [System.Diagnostics.CodeAnalysis.SuppressMessage(
24 "Microsoft.Naming",
"CA1710:IdentifiersShouldHaveCorrectSuffix")]
74 private int _identity = -1;
78 get {
return _identity; }
81 private void InitializeIdentity()
83 _identity = ((
IParent)
this).GetNextIdentity(_identity);
92 if (this.Parent !=
null)
98 if (_identityManager ==
null)
106 #region IsDirty, IsValid, IsSavable
111 bool Core.ITrackStatus.IsSelfDirty
120 [System.ComponentModel.DataAnnotations.Display(AutoGenerateField =
false)]
121 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
134 foreach (C child
in this)
141 bool Core.ITrackStatus.IsSelfValid
143 get {
return IsSelfValid; }
150 protected virtual bool IsSelfValid
160 [System.ComponentModel.DataAnnotations.Display(AutoGenerateField =
false)]
161 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
169 foreach (C child
in this)
181 [System.ComponentModel.DataAnnotations.Display(AutoGenerateField =
false)]
193#region Begin/Cancel/ApplyEdit
265 void Core.IParent.ApplyEditChild(Core.IEditableBusinessObject child)
272 get {
return this.Parent; }
291 void Core.IUndoableObject.CopyState(
int parentEditLevel,
bool parentBindingEdit)
293 if (!parentBindingEdit)
294 CopyState(parentEditLevel);
297 void Core.IUndoableObject.UndoChanges(
int parentEditLevel,
bool parentBindingEdit)
299 if (!parentBindingEdit)
300 UndoChanges(parentEditLevel);
303 void Core.IUndoableObject.AcceptChanges(
int parentEditLevel,
bool parentBindingEdit)
305 if (!parentBindingEdit)
306 AcceptChanges(parentEditLevel);
309 private void CopyState(
int parentEditLevel)
311 if (this.
EditLevel + 1 > parentEditLevel)
318 foreach (C child
in this)
319 child.CopyState(_editLevel,
false);
323 child.CopyState(_editLevel,
false);
326 private bool _completelyRemoveChild;
328 private void UndoChanges(
int parentEditLevel)
332 if (this.
EditLevel - 1 != parentEditLevel)
337 if (_editLevel < 0) _editLevel = 0;
344 for (
int index = Count - 1; index >= 0; index--)
348 child.UndoChanges(_editLevel,
false);
351 if (child.EditLevelAdded > _editLevel)
353 bool oldAllowRemove = this.AllowRemove;
356 this.AllowRemove =
true;
357 _completelyRemoveChild =
true;
362 _completelyRemoveChild =
false;
363 this.AllowRemove = oldAllowRemove;
369 for (
int index =
DeletedList.Count - 1; index >= 0; index--)
372 child.UndoChanges(_editLevel,
false);
373 if (child.EditLevelAdded > _editLevel)
381 if (!child.IsDeleted) UnDeleteChild(child);
388 OnListChanged(
new ListChangedEventArgs(ListChangedType.Reset, -1));
392 private void AcceptChanges(
int parentEditLevel)
394 if (this.
EditLevel - 1 != parentEditLevel)
399 if (_editLevel < 0) _editLevel = 0;
402 foreach (C child
in this)
404 child.AcceptChanges(_editLevel,
false);
406 if (child.EditLevelAdded > _editLevel) child.EditLevelAdded = _editLevel;
410 for (
int index =
DeletedList.Count - 1; index >= 0; index--)
413 child.AcceptChanges(_editLevel,
false);
415 if (child.EditLevelAdded > _editLevel)
422#region Delete and Undelete child
430 [System.Diagnostics.CodeAnalysis.SuppressMessage(
431 "Microsoft.Design",
"CA1002:DoNotExposeGenericLists")]
432 [EditorBrowsable(EditorBrowsableState.Advanced)]
437 if (_deletedList ==
null)
443 [System.Diagnostics.CodeAnalysis.SuppressMessage(
444 "Microsoft.Design",
"CA1002:DoNotExposeGenericLists")]
445 [EditorBrowsable(EditorBrowsableState.Advanced)]
448 private void DeleteChild(C child)
451 Core.UndoableBase.ResetChildEditLevel(child, this.
EditLevel,
false);
458 private void UnDeleteChild(C child)
467 int saveLevel = child.EditLevelAdded;
469 child.EditLevelAdded = saveLevel;
477 [EditorBrowsable(EditorBrowsableState.Advanced)]
485#region Insert, Remove, Clear
532 item.SetParent(
this);
534 Core.UndoableBase.ResetChildEditLevel(item, this.
EditLevel,
false);
538 item.EditLevelAdded = _editLevel;
539 base.InsertItem(index, item);
551 C child =
this[index];
554 base.RemoveItem(index);
556 if (!_completelyRemoveChild)
562 if (RaiseListChangedEvents)
563 OnListChanged(
new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
572 while (base.Count > 0)
588 protected override void SetItem(
int index, C item)
590 C child =
default(C);
591 if (!(ReferenceEquals((C)(
this[index]), item)))
598 item.SetParent(
this);
600 Core.UndoableBase.ResetChildEditLevel(item, this.
EditLevel,
false);
605 base.SetItem(index, item);
609 if (RaiseListChangedEvents)
610 OnListChanged(
new ListChangedEventArgs(ListChangedType.ItemChanged, index));
615#region Cascade child events
622 [EditorBrowsable(EditorBrowsableState.Never)]
625 if (_deserialized && RaiseListChangedEvents && e !=
null)
627 for (
int index = 0; index < Count; index++)
629 if (ReferenceEquals(
this[index], sender))
631 PropertyDescriptor descriptor = GetPropertyDescriptor(e.PropertyName);
632 if (descriptor !=
null)
633 OnListChanged(
new ListChangedEventArgs(
634 ListChangedType.ItemChanged, index, descriptor));
636 OnListChanged(
new ListChangedEventArgs(
637 ListChangedType.ItemChanged, index));
641 base.Child_PropertyChanged(sender, e);
644 private static PropertyDescriptorCollection _propertyDescriptors;
646 private PropertyDescriptor GetPropertyDescriptor(
string propertyName)
648 if (_propertyDescriptors ==
null)
649 _propertyDescriptors = TypeDescriptor.GetProperties(typeof(C));
650 PropertyDescriptor result =
null;
651 foreach (PropertyDescriptor desc
in _propertyDescriptors)
652 if (desc.Name == propertyName)
662#region Edit level tracking
665 private int _editLevel;
670 [EditorBrowsable(EditorBrowsableState.Never)]
673 get {
return _editLevel; }
676 int Core.IUndoableObject.EditLevel
689 private bool _isChild =
false;
696 [System.ComponentModel.DataAnnotations.Display(AutoGenerateField =
false)]
697 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
700 get {
return _isChild; }
730 object ICloneable.Clone()
739 [EditorBrowsable(EditorBrowsableState.Advanced)]
756#region Serialization Notification
760 private bool _deserialized =
false;
766 [EditorBrowsable(EditorBrowsableState.Advanced)]
769 _deserialized =
true;
770 base.OnDeserialized();
772 foreach (Core.IEditableBusinessObject child in
this)
774 child.SetParent(
this);
777 foreach (Core.IEditableBusinessObject child in
DeletedList)
778 child.SetParent(
this);
783#region Child Data Access
789 [EditorBrowsable(EditorBrowsableState.Advanced)]
802 [EditorBrowsable(EditorBrowsableState.Advanced)]
812 foreach (var child
in this)
813 if (child.IsDirty) dp.UpdateChild(child, parameters);
854 catch (AggregateException ex)
856 if (ex.InnerExceptions.Count > 0)
857 throw ex.InnerExceptions[0];
886 protected virtual async Task<T>
SaveAsync(
object userState,
bool isSync)
906 result = dp.
Update((T)
this);
910 result = await dp.UpdateAsync((T)
this);
917 OnSaved(result,
null, userState);
926 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member")]
927 [EditorBrowsable(EditorBrowsableState.Advanced)]
938 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member")]
939 [EditorBrowsable(EditorBrowsableState.Advanced)]
951 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member")]
952 [EditorBrowsable(EditorBrowsableState.Advanced)]
963 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member")]
964 [EditorBrowsable(EditorBrowsableState.Advanced)]
974 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member")]
975 [EditorBrowsable(EditorBrowsableState.Advanced)]
986 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member")]
987 [EditorBrowsable(EditorBrowsableState.Advanced)]
994#region ISavable Members
1023 OnSaved((T)newObject,
null,
null);
1043 OnSaved(newObject,
null,
null);
1055 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design",
1056 "CA1062:ValidateArgumentsOfPublicMethods")]
1061 if (value.Method.IsPublic &&
1062 (value.Method.DeclaringType.IsSerializable ||
1063 value.Method.IsStatic))
1065 System.Delegate.Combine(_serializableSavedHandlers, value);
1068 System.Delegate.Combine(_nonSerializableSavedHandlers, value);
1072 if (value.Method.IsPublic &&
1073 (value.Method.DeclaringType.IsSerializable ||
1074 value.Method.IsStatic))
1075 _serializableSavedHandlers = (EventHandler<Csla.Core.SavedEventArgs>)
1076 System.Delegate.Remove(_serializableSavedHandlers, value);
1079 System.Delegate.Remove(_nonSerializableSavedHandlers, value);
1091 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1092 protected virtual void OnSaved(T newObject, Exception e,
object userState)
1095 if (_nonSerializableSavedHandlers !=
null)
1096 _nonSerializableSavedHandlers.Invoke(
this, args);
1097 if (_serializableSavedHandlers !=
null)
1098 _serializableSavedHandlers.Invoke(
this, args);
1103#region Parent/Child link
1105 [NotUndoable(), NonSerialized()]
1106 private Core.IParent _parent;
1116 [System.ComponentModel.DataAnnotations.Display(AutoGenerateField =
false)]
1117 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
1118 [EditorBrowsable(EditorBrowsableState.Advanced)]
1119 public Core.IParent Parent
1136 _identityManager =
null;
1137 InitializeIdentity();
1146 void Core.IEditableCollection.SetParent(Core.IParent parent)
1160 List<C> result =
new List<C>();
1161 foreach (C item
in this)
1163 return result.ToArray();
1169 bool Core.ITrackStatus.IsNew
1177 bool Core.ITrackStatus.IsDeleted
1189 [System.ComponentModel.DataAnnotations.Display(AutoGenerateField =
false)]
1190 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
1203 foreach (C child
in this)
1213#region IDataPortalTarget Members
1261#region Mobile object overrides
1270 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1273 _isChild = info.GetValue<
bool>(
"Csla.BusinessListBase._isChild");
1274 _editLevel = info.GetValue<
int>(
"Csla.BusinessListBase._editLevel");
1275 _identity = info.GetValue<
int>(
"Csla.Core.BusinessBase._identity");
1276 base.OnSetState(info);
1286 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1289 info.AddValue(
"Csla.BusinessListBase._isChild", _isChild);
1290 info.AddValue(
"Csla.BusinessListBase._editLevel", _editLevel);
1291 info.AddValue(
"Csla.Core.BusinessBase._identity", _identity);
1292 base.OnGetState(info);
1305 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1308 base.OnGetChildren(info, formatter);
1309 if (_deletedList !=
null)
1311 var fieldManagerInfo = formatter.SerializeObject(_deletedList);
1312 info.AddChild(
"_deletedList", fieldManagerInfo.ReferenceId);
1326 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1329 if (info.Children.ContainsKey(
"_deletedList"))
1331 var childData = info.Children[
"_deletedList"];
1332 _deletedList = (
MobileList<C>)formatter.GetObject(childData.ReferenceId);
Provides consistent context information between the client and server DataPortal objects.
object CreateInstanceDI(Type objectType, params object[] parameters)
Creates an object using 'Activator.CreateInstance' using service provider (if one is available) to po...
This is the base class from which most business collections or lists will be derived.
virtual object GetClone()
Creates a clone of the object.
virtual void Initialize()
Override this method to set up event handlers so user code in a partial class can respond to events r...
void CancelEdit()
Cancels the current edit process, restoring the object's state to its previous values.
override void RemoveItem(int index)
Marks the child object for deletion and moves it to the collection of deleted objects.
void MarkAsChild()
Marks the object as being a child object.
override void OnSetState(Csla.Serialization.Mobile.SerializationInfo info)
Override this method to retrieve your field values from the MobileFormatter serialzation stream.
virtual async Task< T > SaveAsync(object userState, bool isSync)
Saves the object to the database.
virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
Called by the server-side DataPortal if an exception occurs during data access.
bool IsDirty
Gets a value indicating whether this object's data has been changed.
override void SetItem(int index, C item)
Replaces the item at the specified index with the specified item, first moving the original item to t...
EventHandler< Csla.Core.SavedEventArgs > Saved
Event raised when an object has been saved.
override void OnDeserialized()
This method is called on a newly deserialized object after deserialization is complete.
bool ContainsDeleted(C item)
Returns true if the internal deleted list contains the specified child object.
virtual void SetParent(Core.IParent parent)
Used by BusinessListBase as a child object is created to tell the child object about its parent.
override void InsertItem(int index, C item)
Sets the edit level of the child object as it is added.
virtual void Child_OnDataPortalInvokeComplete(DataPortalEventArgs e)
Called by the server-side DataPortal after calling the requested DataPortal_XYZ method.
virtual void DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
Called by the server-side DataPortal prior to calling the requested DataPortal_xyz method.
MobileList< C > DeletedList
A collection containing all child objects marked for deletion.
async Task< T > SaveAsync()
Saves the object to the database.
int EditLevel
Returns the current edit level of the object.
T Save()
Saves the object to the database.
virtual void EditChildComplete(Core.IEditableBusinessObject child)
Override this method to be notified when a child object's Core.BusinessBase.ApplyEdit method has comp...
C[] ToArray()
Get an array containing all items in the list.
void BeginEdit()
Starts a nested edit on the object.
virtual void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
Called by the server-side DataPortal after calling the requested DataPortal_xyz method.
async Task SaveAndMergeAsync()
Saves the object to the database, merging any resulting updates into the existing object graph.
virtual bool IsSavable
Returns true if this object is both dirty and valid.
override void Child_PropertyChanged(object sender, PropertyChangedEventArgs e)
Handles any PropertyChanged event from a child object and echoes it up as a ListChanged event.
ApplicationContext ApplicationContext
Gets the current ApplicationContext
override void OnGetChildren(Csla.Serialization.Mobile.SerializationInfo info, Csla.Serialization.Mobile.MobileFormatter formatter)
Override this method to insert child objects into the MobileFormatter serialization stream.
override void ClearItems()
Clears the collection, moving all active items to the deleted list.
bool IsChild
Indicates whether this collection object is a child object.
virtual bool IsValid
Gets a value indicating whether this object is currently in a valid state (has no broken validation r...
override object AddNewCore()
Override this method to create a new object that is added to the collection.
override bool IsBusy
Gets the busy status for this object and its child objects.
BusinessBindingListBase()
Creates an instance of the type.
virtual void Child_OnDataPortalException(DataPortalEventArgs e, Exception ex)
Called by the server-side DataPortal if an exception occurs during data access.
virtual void Child_Update(params object[] parameters)
Saves all items in the list, automatically performing insert, update or delete operations as necessar...
T Clone()
Creates a clone of the object.
virtual void Child_Create()
Initializes a new instance of the object with default values.
virtual void OnSaved(T newObject, Exception e, object userState)
Raises the Saved event, indicating that the object has been saved, and providing a reference to the n...
override void OnSetChildren(Csla.Serialization.Mobile.SerializationInfo info, Csla.Serialization.Mobile.MobileFormatter formatter)
Override this method to get child objects from the MobileFormatter serialization stream.
void ApplyEdit()
Commits the current edit process.
virtual void Child_OnDataPortalInvoke(DataPortalEventArgs e)
Called by the server-side DataPortal prior to calling the requested DataPortal_XYZ method.
override void OnGetState(Csla.Serialization.Mobile.SerializationInfo info)
Override this method to insert your field values into the MobileFormatter serialzation stream.
Extends BindingList of T by adding extra behaviors.
Implements behavior to merge one object graph into a clone of itself (typically post-serialization).
Used by the root object in a graph to manage the object instance identity values for the graph.
int GetNextIdentity(int current)
Gets and consumes the next available unique identity value for an object instance in the object graph...
Implements a list that is serializable using the SerializationFormatterFactory.GetFormatter().
virtual void OnSetChildren(SerializationInfo info, MobileFormatter formatter)
Override this method to manually deserialize child objects from data in the serialization stream.
Event arguments containing a reference to the new object that was returned as a result of the Save() ...
Exception indicating a problem with the use of the n-level undo feature in CSLA .NET.
Provides information about the DataPortal call.
Client side data portal used for making asynchronous data portal calls in .NET.
T CreateChild()
Creates and initializes a new child business object.
void UpdateChild(T child)
Inserts, updates or deletes an existing child business object.
T Update(T obj)
Called by a factory method in a business class or by the UI to update an object.
A strongly-typed resource class, for looking up localized strings, etc.
static string BusyObjectsMayNotBeSaved
Looks up a localized string similar to Objects that are marked busy may not be saved.
static string EditLevelMismatchException
Looks up a localized string similar to Edit level mismatch in {0}.
static string NoSaveEditingException
Looks up a localized string similar to Object is still being edited and can not be saved.
static string NoApplyEditChildException
Looks up a localized string similar to ApplyEdit is not valid on a child object.
static string NoBeginEditChildException
Looks up a localized string similar to BeginEdit is not valid on a child object.
static string NoCancelEditChildException
Looks up a localized string similar to CancelEdit is not valid on a child object.
static string NoSaveInvalidException
Looks up a localized string similar to Object is not valid and can not be saved.
static string NoSaveChildException
Looks up a localized string similar to Can not directly save a child object.
Tracks the business rules for a business object.
static bool HasPermission(ApplicationContext applicationContext, AuthorizationActions action, Type objectType)
Checks per-type authorization rules.
Object containing the serialization data for a specific object.
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...
Defines the common methods required by all editable CSLA single objects.
Defines the common methods required by all editable CSLA collection objects.
object GetDeletedList()
Used by ObjectFactory to gain access to the list of deleted items contained in the collection.
Interface defining an object that notifies when it is busy executing an asynchronous operation.
Defines the interface that must be implemented by any business object that contains child objects.
int GetNextIdentity(int current)
Gets and consumes the next available unique identity value for an object instance in the object graph...
IParent Parent
Provide access to the parent reference for use in child object code.
Specifies that the object can save itself.
void SaveComplete(object newObject)
INTERNAL CSLA .NET USE ONLY.
Task SaveAndMergeAsync()
Saves the object to the database, merging the result into the original object graph
object Save()
Saves the object to the database.
Task< object > SaveAsync()
Saves the object to the database.
Defines the methods required to participate in n-level undo within the CSLA .NET framework.
Implement if a class requires access to the CSLA ApplicationContext type.
ApplicationContext ApplicationContext
Gets or sets the current ApplicationContext object.
Defines an object that holds a list of deleted items.
IEnumerable< IEditableBusinessObject > DeletedList
List of deleted child objects
@ Serializable
Prevents updating or inserting until the transaction is complete.