9using System.ComponentModel;
10using System.Collections.Generic;
13using System.Threading.Tasks;
23 [System.Diagnostics.CodeAnalysis.SuppressMessage(
24 "Microsoft.Naming",
"CA1710:IdentifiersShouldHaveCorrectSuffix")]
60 private int _identity = -1;
64 get {
return _identity; }
67 private void InitializeIdentity()
69 _identity = ((
IParent)
this).GetNextIdentity(_identity);
78 if (this.Parent !=
null)
84 if (_identityManager ==
null)
92 #region IsDirty, IsValid, IsSavable
97 bool Core.ITrackStatus.IsSelfDirty
106 [System.ComponentModel.DataAnnotations.Display(AutoGenerateField =
false)]
107 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
120 foreach (C child
in this)
127 bool Core.ITrackStatus.IsSelfValid
129 get {
return IsSelfValid; }
136 protected virtual bool IsSelfValid
146 [System.ComponentModel.DataAnnotations.Display(AutoGenerateField =
false)]
147 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
155 foreach (C child
in this)
167 [System.ComponentModel.DataAnnotations.Display(AutoGenerateField =
false)]
179#region Begin/Cancel/ApplyEdit
251 void Core.IParent.ApplyEditChild(Core.IEditableBusinessObject child)
258 get {
return this.Parent; }
277 void Core.IUndoableObject.CopyState(
int parentEditLevel,
bool parentBindingEdit)
279 if (!parentBindingEdit)
280 CopyState(parentEditLevel);
283 void Core.IUndoableObject.UndoChanges(
int parentEditLevel,
bool parentBindingEdit)
285 if (!parentBindingEdit)
286 UndoChanges(parentEditLevel);
289 void Core.IUndoableObject.AcceptChanges(
int parentEditLevel,
bool parentBindingEdit)
291 if (!parentBindingEdit)
292 AcceptChanges(parentEditLevel);
295 private void CopyState(
int parentEditLevel)
297 if (this.
EditLevel + 1 > parentEditLevel)
304 foreach (C child
in this)
305 child.CopyState(_editLevel,
false);
309 child.CopyState(_editLevel,
false);
312 private bool _completelyRemoveChild;
314 private void UndoChanges(
int parentEditLevel)
318 if (this.
EditLevel - 1 != parentEditLevel)
323 if (_editLevel < 0) _editLevel = 0;
330 for (
int index = Count - 1; index >= 0; index--)
334 child.UndoChanges(_editLevel,
false);
337 if (child.EditLevelAdded > _editLevel)
339 bool oldAllowRemove = this.AllowRemove;
342 this.AllowRemove =
true;
343 _completelyRemoveChild =
true;
348 _completelyRemoveChild =
false;
349 this.AllowRemove = oldAllowRemove;
355 for (
int index =
DeletedList.Count - 1; index >= 0; index--)
358 child.UndoChanges(_editLevel,
false);
359 if (child.EditLevelAdded > _editLevel)
367 if (!child.IsDeleted) UnDeleteChild(child);
374 OnListChanged(
new ListChangedEventArgs(ListChangedType.Reset, -1));
378 private void AcceptChanges(
int parentEditLevel)
380 if (this.
EditLevel - 1 != parentEditLevel)
385 if (_editLevel < 0) _editLevel = 0;
388 foreach (C child
in this)
390 child.AcceptChanges(_editLevel,
false);
392 if (child.EditLevelAdded > _editLevel) child.EditLevelAdded = _editLevel;
396 for (
int index =
DeletedList.Count - 1; index >= 0; index--)
399 child.AcceptChanges(_editLevel,
false);
401 if (child.EditLevelAdded > _editLevel)
408#region Delete and Undelete child
416 [System.Diagnostics.CodeAnalysis.SuppressMessage(
417 "Microsoft.Design",
"CA1002:DoNotExposeGenericLists")]
418 [EditorBrowsable(EditorBrowsableState.Advanced)]
423 if (_deletedList ==
null)
429 private void DeleteChild(C child)
432 Core.UndoableBase.ResetChildEditLevel(child, this.
EditLevel,
false);
439 private void UnDeleteChild(C child)
448 int saveLevel = child.EditLevelAdded;
450 child.EditLevelAdded = saveLevel;
458 [EditorBrowsable(EditorBrowsableState.Advanced)]
466#region Insert, Remove, Clear
512 item.SetParent(
this);
514 Core.UndoableBase.ResetChildEditLevel(item, this.
EditLevel,
false);
518 item.EditLevelAdded = _editLevel;
519 base.InsertItem(index, item);
531 C child =
this[index];
534 base.RemoveItem(index);
536 if (!_completelyRemoveChild)
542 if (RaiseListChangedEvents)
543 OnListChanged(
new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
552 while (base.Count > 0)
568 protected override void SetItem(
int index, C item)
570 C child =
default(C);
571 if (!(ReferenceEquals((C)(
this[index]), item)))
578 item.SetParent(
this);
580 Core.UndoableBase.ResetChildEditLevel(item, this.
EditLevel,
false);
585 base.SetItem(index, item);
589 if (RaiseListChangedEvents)
590 OnListChanged(
new ListChangedEventArgs(ListChangedType.ItemChanged, index));
595#region Cascade child events
602 [EditorBrowsable(EditorBrowsableState.Never)]
605 if (_deserialized && RaiseListChangedEvents && e !=
null)
607 for (
int index = 0; index < Count; index++)
609 if (ReferenceEquals(
this[index], sender))
611 PropertyDescriptor descriptor = GetPropertyDescriptor(e.PropertyName);
612 if (descriptor !=
null)
613 OnListChanged(
new ListChangedEventArgs(
614 ListChangedType.ItemChanged, index, descriptor));
616 OnListChanged(
new ListChangedEventArgs(
617 ListChangedType.ItemChanged, index));
621 base.Child_PropertyChanged(sender, e);
624 private static PropertyDescriptorCollection _propertyDescriptors;
626 private PropertyDescriptor GetPropertyDescriptor(
string propertyName)
628 if (_propertyDescriptors ==
null)
629 _propertyDescriptors = TypeDescriptor.GetProperties(typeof(C));
630 PropertyDescriptor result =
null;
631 foreach (PropertyDescriptor desc
in _propertyDescriptors)
632 if (desc.Name == propertyName)
642#region Edit level tracking
645 private int _editLevel;
650 [EditorBrowsable(EditorBrowsableState.Never)]
653 get {
return _editLevel; }
656 int Core.IUndoableObject.EditLevel
669 private bool _isChild =
false;
676 [System.ComponentModel.DataAnnotations.Display(AutoGenerateField =
false)]
677 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
680 get {
return _isChild; }
710 object ICloneable.Clone()
719 [EditorBrowsable(EditorBrowsableState.Advanced)]
722 return Core.ObjectCloner.Clone(
this);
736#region Serialization Notification
740 private bool _deserialized =
false;
746 [EditorBrowsable(EditorBrowsableState.Advanced)]
749 _deserialized =
true;
750 base.OnDeserialized();
752 foreach (Core.IEditableBusinessObject child in
this)
754 child.SetParent(
this);
757 foreach (Core.IEditableBusinessObject child in
DeletedList)
758 child.SetParent(
this);
763#region Child Data Access
769 [EditorBrowsable(EditorBrowsableState.Advanced)]
782 [EditorBrowsable(EditorBrowsableState.Advanced)]
791 foreach (var child
in this)
833 catch (AggregateException ex)
835 if (ex.InnerExceptions.Count > 0)
836 throw ex.InnerExceptions[0];
865 protected virtual async Task<T>
SaveAsync(
object userState,
bool isSync)
895 OnSaved(result,
null, userState);
925 public void BeginSave(EventHandler<SavedEventArgs> handler)
938 public async
void BeginSave(EventHandler<SavedEventArgs> handler,
object userState)
940 T result =
default(T);
941 Exception error =
null;
944 result = await
SaveAsync(userState,
false);
946 catch (AggregateException ex)
948 if (ex.InnerExceptions.Count > 0)
949 error = ex.InnerExceptions[0];
966 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member")]
967 [EditorBrowsable(EditorBrowsableState.Advanced)]
978 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member")]
979 [EditorBrowsable(EditorBrowsableState.Advanced)]
991 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member")]
992 [EditorBrowsable(EditorBrowsableState.Advanced)]
1003 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member")]
1004 [EditorBrowsable(EditorBrowsableState.Advanced)]
1014 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member")]
1015 [EditorBrowsable(EditorBrowsableState.Advanced)]
1026 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member")]
1027 [EditorBrowsable(EditorBrowsableState.Advanced)]
1034#region ISavable Members
1063 OnSaved((T)newObject,
null,
null);
1083 OnSaved(newObject,
null,
null);
1095 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design",
1096 "CA1062:ValidateArgumentsOfPublicMethods")]
1101 if (value.Method.IsPublic &&
1102 (value.Method.DeclaringType.IsSerializable ||
1103 value.Method.IsStatic))
1105 System.Delegate.Combine(_serializableSavedHandlers, value);
1108 System.Delegate.Combine(_nonSerializableSavedHandlers, value);
1112 if (value.Method.IsPublic &&
1113 (value.Method.DeclaringType.IsSerializable ||
1114 value.Method.IsStatic))
1115 _serializableSavedHandlers = (EventHandler<Csla.Core.SavedEventArgs>)
1116 System.Delegate.Remove(_serializableSavedHandlers, value);
1119 System.Delegate.Remove(_nonSerializableSavedHandlers, value);
1131 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1132 protected virtual void OnSaved(T newObject, Exception e,
object userState)
1135 if (_nonSerializableSavedHandlers !=
null)
1136 _nonSerializableSavedHandlers.Invoke(
this, args);
1137 if (_serializableSavedHandlers !=
null)
1138 _serializableSavedHandlers.Invoke(
this, args);
1143#region Parent/Child link
1145 [NotUndoable(), NonSerialized()]
1146 private Core.IParent _parent;
1156 [System.ComponentModel.DataAnnotations.Display(AutoGenerateField =
false)]
1157 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
1158 [EditorBrowsable(EditorBrowsableState.Advanced)]
1159 public Core.IParent Parent
1176 _identityManager =
null;
1177 InitializeIdentity();
1186 void Core.IEditableCollection.SetParent(Core.IParent parent)
1200 List<C> result =
new List<C>();
1201 foreach (C item
in this)
1203 return result.ToArray();
1209 bool Core.ITrackStatus.IsNew
1217 bool Core.ITrackStatus.IsDeleted
1229 [System.ComponentModel.DataAnnotations.Display(AutoGenerateField =
false)]
1230 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
1243 foreach (C child
in this)
1253#region IDataPortalTarget Members
1301#region Mobile object overrides
1310 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1313 _isChild = info.GetValue<
bool>(
"Csla.BusinessListBase._isChild");
1314 _editLevel = info.GetValue<
int>(
"Csla.BusinessListBase._editLevel");
1315 _identity = info.GetValue<
int>(
"Csla.Core.BusinessBase._identity");
1316 base.OnSetState(info);
1326 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1329 info.AddValue(
"Csla.BusinessListBase._isChild", _isChild);
1330 info.AddValue(
"Csla.BusinessListBase._editLevel", _editLevel);
1331 info.AddValue(
"Csla.Core.BusinessBase._identity", _identity);
1332 base.OnGetState(info);
1345 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1348 base.OnGetChildren(info, formatter);
1349 if (_deletedList !=
null)
1351 var fieldManagerInfo = formatter.SerializeObject(_deletedList);
1352 info.AddChild(
"_deletedList", fieldManagerInfo.ReferenceId);
1366 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1369 if (info.Children.ContainsKey(
"_deletedList"))
1371 var childData = info.Children[
"_deletedList"];
1372 _deletedList = (
MobileList<C>)formatter.GetObject(childData.ReferenceId);
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.
void BeginSave()
Starts an async operation to save the object to the database.
Task SaveAndMergeAsync()
Saves the object to the database, merging any resulting updates into the existing object graph.
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.
void BeginSave(EventHandler< SavedEventArgs > handler)
Starts an async operation to save the object to the database.
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.
async void BeginSave(EventHandler< SavedEventArgs > handler, object userState)
Starts an async operation to save the object to the database.
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.
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.
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 object.
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.
void BeginSave(object userState)
Starts an async operation to save the object to the database.
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.
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.
This is the client-side DataPortal.
T Update(T obj)
Called by a factory method in a business class or by the UI to update an object.
static void UpdateChild(object child)
Inserts, updates or deletes an existing child business object.
async Task< T > UpdateAsync(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(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.
@ Serializable
Prevents updating or inserting until the transaction is complete.