9using System.ComponentModel;
10using System.ComponentModel.DataAnnotations;
13using System.Collections.Generic;
14using System.Collections.Specialized;
19using System.Threading.Tasks;
30 [System.Diagnostics.DebuggerStepThrough]
79 private int _identity = -1;
83 get {
return _identity; }
86 private void InitializeIdentity()
88 _identity = ((
IParent)
this).GetNextIdentity(_identity);
97 if (this.Parent !=
null)
103 if (_identityManager ==
null)
113 object ICloneable.Clone()
122 [EditorBrowsable(EditorBrowsableState.Advanced)]
139 #region Delete and Undelete child
147 [System.Diagnostics.CodeAnalysis.SuppressMessage(
148 "Microsoft.Design",
"CA1002:DoNotExposeGenericLists")]
149 [EditorBrowsable(EditorBrowsableState.Advanced)]
154 if (_deletedList ==
null)
160 [System.Diagnostics.CodeAnalysis.SuppressMessage(
161 "Microsoft.Design",
"CA1002:DoNotExposeGenericLists")]
162 [EditorBrowsable(EditorBrowsableState.Advanced)]
165 private void DeleteChild(C child)
168 Core.UndoableBase.ResetChildEditLevel(child, this.
EditLevel,
false);
176 private void UnDeleteChild(C child)
185 int saveLevel = child.EditLevelAdded;
188 child.EditLevelAdded = saveLevel;
196 [EditorBrowsable(EditorBrowsableState.Advanced)]
204 #region Begin/Cancel/ApplyEdit
276 void Core.IParent.ApplyEditChild(Core.IEditableBusinessObject child)
283 get {
return this.Parent; }
301 #region Insert, Remove, Clear
350 item.SetParent(
this);
352 Core.UndoableBase.ResetChildEditLevel(item, this.
EditLevel,
false);
356 item.EditLevelAdded = _editLevel;
357 base.InsertItem(index, item);
375 C child =
this[index];
378 base.RemoveItem(index);
380 if (!_completelyRemoveChild)
387 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, child, index));
401 protected override void SetItem(
int index, C item)
403 C child =
default(C);
404 if (!(ReferenceEquals((C)(
this[index]), item)))
415 item.SetParent(
this);
417 Core.UndoableBase.ResetChildEditLevel(item, this.
EditLevel,
false);
421 base.SetItem(index, item);
440 #region Edit level tracking
443 private int _editLevel;
448 [EditorBrowsable(EditorBrowsableState.Never)]
451 get {
return _editLevel; }
454 int Core.IUndoableObject.EditLevel
466 void Core.IUndoableObject.CopyState(
int parentEditLevel,
bool parentBindingEdit)
468 if (!parentBindingEdit)
469 CopyState(parentEditLevel);
472 void Core.IUndoableObject.UndoChanges(
int parentEditLevel,
bool parentBindingEdit)
474 if (!parentBindingEdit)
475 UndoChanges(parentEditLevel);
478 void Core.IUndoableObject.AcceptChanges(
int parentEditLevel,
bool parentBindingEdit)
480 if (!parentBindingEdit)
481 AcceptChanges(parentEditLevel);
484 private void CopyState(
int parentEditLevel)
486 if (this.
EditLevel + 1 > parentEditLevel)
493 for (
int x = 0; x < this.Count; x++)
501 child.CopyState(_editLevel,
false);
504 private bool _completelyRemoveChild;
506 private void UndoChanges(
int parentEditLevel)
510 if (this.
EditLevel - 1 != parentEditLevel)
515 if (_editLevel < 0) _editLevel = 0;
522 for (
int index = Count - 1; index >= 0; index--)
532 child.UndoChanges(_editLevel,
false);
539 if (child.EditLevelAdded > _editLevel)
545 _completelyRemoveChild =
true;
551 _completelyRemoveChild =
false;
558 for (
int index =
DeletedList.Count - 1; index >= 0; index--)
561 child.UndoChanges(_editLevel,
false);
562 if (child.EditLevelAdded > _editLevel)
570 if (!child.IsDeleted) UnDeleteChild(child);
576 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
581 private void AcceptChanges(
int parentEditLevel)
583 if (this.
EditLevel - 1 != parentEditLevel)
590 foreach (C child
in this)
592 child.AcceptChanges(_editLevel,
false);
594 if (child.EditLevelAdded > _editLevel) child.EditLevelAdded = _editLevel;
598 for (
int index =
DeletedList.Count - 1; index >= 0; index--)
601 child.AcceptChanges(_editLevel,
false);
603 if (child.EditLevelAdded > _editLevel)
607 if (_editLevel < 0) _editLevel = 0;
612 #region Mobile Object overrides
624 info.
AddValue(
"Csla.BusinessListBase._isChild", _isChild);
625 info.
AddValue(
"Csla.BusinessListBase._editLevel", _editLevel);
626 info.
AddValue(
"Csla.Core.BusinessBase._identity", _identity);
627 base.OnGetState(info);
640 _isChild = info.GetValue<
bool>(
"Csla.BusinessListBase._isChild");
641 _editLevel = info.GetValue<
int>(
"Csla.BusinessListBase._editLevel");
642 _identity = info.GetValue<
int>(
"Csla.Core.BusinessBase._identity");
643 base.OnSetState(info);
659 base.OnGetChildren(info, formatter);
660 if (_deletedList !=
null)
662 var fieldManagerInfo = formatter.SerializeObject(_deletedList);
663 info.AddChild(
"_deletedList", fieldManagerInfo.ReferenceId);
680 if (info.Children.ContainsKey(
"_deletedList"))
682 var childData = info.Children[
"_deletedList"];
683 _deletedList = (
MobileList<C>)formatter.GetObject(childData.ReferenceId);
693 private bool _isChild =
false;
701 get {
return _isChild; }
729 #region IsDirty, IsValid, IsSavable
734 bool Core.ITrackStatus.IsSelfDirty
754 foreach (C child
in this)
761 bool Core.ITrackStatus.IsSelfValid
763 get {
return IsSelfValid; }
770 protected virtual bool IsSelfValid
786 foreach (C child
in this)
820 foreach (C child
in this)
832 bool Core.ITrackStatus.IsNew
840 bool Core.ITrackStatus.IsDeleted
850 #region Serialization Notification
855 [EditorBrowsable(EditorBrowsableState.Advanced)]
858 base.OnDeserialized();
859 foreach (Core.IEditableBusinessObject child in
this)
860 child.SetParent(
this);
862 foreach (Core.IEditableBusinessObject child in
DeletedList)
863 child.SetParent(
this);
868 #region Child Data Access
874 [EditorBrowsable(EditorBrowsableState.Advanced)]
887 [EditorBrowsable(EditorBrowsableState.Advanced)]
897 foreach (var child
in this)
898 if (child.IsDirty) dp.UpdateChild(child, parameters);
910 [EditorBrowsable(EditorBrowsableState.Advanced)]
921 foreach (var child
in this)
922 if (child.IsDirty) await dp.UpdateChildAsync(child, parameters).ConfigureAwait(
false);
963 catch (AggregateException ex)
965 if (ex.InnerExceptions.Count > 0)
966 throw ex.InnerExceptions[0];
985 protected virtual async Task<T>
SaveAsync(
object userState,
bool isSync)
1005 result = dp.
Update((T)
this);
1009 result = await dp.UpdateAsync((T)
this);
1016 OnSaved(result,
null, userState);
1035 [EditorBrowsable(EditorBrowsableState.Advanced)]
1044 [EditorBrowsable(EditorBrowsableState.Advanced)]
1054 [EditorBrowsable(EditorBrowsableState.Advanced)]
1063 [EditorBrowsable(EditorBrowsableState.Advanced)]
1072 [EditorBrowsable(EditorBrowsableState.Advanced)]
1082 [EditorBrowsable(EditorBrowsableState.Advanced)]
1088 #region ISavable Members
1117 OnSaved((T)newObject,
null,
null);
1137 OnSaved(newObject,
null,
null);
1147 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design",
1148 "CA1062:ValidateArgumentsOfPublicMethods")]
1154 System.Delegate.Combine(_savedEvent, value);
1159 System.Delegate.Remove(_savedEvent, value);
1171 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1172 protected virtual void OnSaved(T newObject, Exception e,
object userState)
1175 if (_savedEvent !=
null)
1176 _savedEvent.Invoke(
this, args);
1180 #region Parent/Child link
1182 [NotUndoable(), NonSerialized()]
1183 private Core.IParent _parent;
1193 [Display(AutoGenerateField=
false)]
1194 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
1195 [EditorBrowsable(EditorBrowsableState.Advanced)]
1196 public Core.IParent Parent
1213 _identityManager =
null;
1214 InitializeIdentity();
1223 void Core.IEditableCollection.SetParent(Core.IParent parent)
1230 #region IDataPortalTarget Members
1232 void IDataPortalTarget.CheckRules()
1235 void IDataPortalTarget.MarkAsChild()
1240 void IDataPortalTarget.MarkNew()
1243 void IDataPortalTarget.MarkOld()
1246 void IDataPortalTarget.DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
1251 void IDataPortalTarget.DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
1256 void IDataPortalTarget.DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
1261 void IDataPortalTarget.Child_OnDataPortalInvoke(DataPortalEventArgs e)
1266 void IDataPortalTarget.Child_OnDataPortalInvokeComplete(DataPortalEventArgs e)
1271 void IDataPortalTarget.Child_OnDataPortalException(DataPortalEventArgs e, Exception ex)
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...
ApplicationContext(ApplicationContextAccessor applicationContextAccessor)
Creates a new instance of the type
This is the base class from which most business collections or lists will be derived.
override void OnSetChildren(Csla.Serialization.Mobile.SerializationInfo info, Csla.Serialization.Mobile.MobileFormatter formatter)
Method called by MobileFormatter when an object should deserialize its child references.
virtual void Initialize()
Override this method to set up event handlers so user code in a partial class can respond to events r...
virtual void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
Called by the server-side DataPortal after calling the requested DataPortal_xyz method.
BusinessListBase()
Creates an instance of the type.
override void OnGetChildren(Csla.Serialization.Mobile.SerializationInfo info, Csla.Serialization.Mobile.MobileFormatter formatter)
Method called by MobileFormatter when an object should serialize its child references.
override bool IsBusy
Gets the busy status for this object and its child objects.
override void RemoveItem(int index)
Marks the child object for deletion and moves it to the collection of deleted objects.
virtual bool IsSavable
Returns true if this object has changes, is valid, the user is authorized and the object is not busy.
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...
bool IsDirty
Gets a value indicating whether this object's data has been changed.
EventHandler< Csla.Core.SavedEventArgs > Saved
Event raised when an object has been saved.
void ApplyEdit()
Commits the current edit process.
int EditLevel
Returns the current edit level of the object.
void CancelEdit()
Cancels the current edit process, restoring the object's state to its previous values.
virtual void DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
Called by the server-side DataPortal prior to calling the requested DataPortal_xyz method.
virtual void SetParent(Core.IParent parent)
Used by BusinessListBase as a child object is created to tell the child object about its parent.
virtual void Child_Update(params object[] parameters)
Saves all items in the list, automatically performing insert, update or delete operations as necessar...
virtual void Child_OnDataPortalInvoke(DataPortalEventArgs e)
Called by the server-side DataPortal prior to calling the requested DataPortal_XYZ method.
virtual void Child_OnDataPortalException(DataPortalEventArgs e, Exception ex)
Called by the server-side DataPortal if an exception occurs during data access.
override void OnSetState(SerializationInfo info)
Method called by MobileFormatter when an object should be deserialized.
ApplicationContext ApplicationContext
Gets the current ApplicationContext
virtual async Task Child_UpdateAsync(params object[] parameters)
Asynchronously saves all items in the list, automatically performing insert, update or delete operati...
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...
virtual bool IsValid
Gets a value indicating whether this object is currently in a valid state (has no broken validation r...
override void OnDeserialized()
Reset parent references on deserialization.
override void ClearItems()
Clears the collection, moving all active items to the deleted list.
virtual void Child_Create()
Initializes a new instance of the object with default values.
virtual object GetClone()
Creates a clone of the object.
MobileList< C > DeletedList
A collection containing all child objects marked for deletion.
virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
Called by the server-side DataPortal if an exception occurs during data access.
override void OnGetState(SerializationInfo info)
Method called by MobileFormatter when an object should serialize its data.
T Save()
Saves the object to the database.
async Task< T > SaveAsync()
Saves the object to the database.
override void InsertItem(int index, C item)
Sets the edit level of the child object as it is added.
void MarkAsChild()
Marks the object as being a child object.
virtual void EditChildComplete(Core.IEditableBusinessObject child)
Override this method to be notified when a child object's Core.BusinessBase.ApplyEdit method has comp...
void BeginEdit()
Starts a nested edit on the object.
virtual async Task< T > SaveAsync(object userState, bool isSync)
Saves the object to the database.
bool IsChild
Indicates whether this collection object is a child object.
virtual void Child_OnDataPortalInvokeComplete(DataPortalEventArgs e)
Called by the server-side DataPortal after calling the requested DataPortal_XYZ method.
T Clone()
Creates a clone of the object.
bool ContainsDeleted(C item)
Returns true if the internal deleted list contains the specified child object.
override C AddNewCore()
Override this method to create a new object that is added to the collection.
async Task SaveAndMergeAsync()
Saves the object to the database, merging any resulting updates into the existing object graph.
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.
Extends ObservableCollection with behaviors required by CSLA .NET collections.
bool AllowRemove
Gets or sets a value indicating whether data binding can automatically remove items from this collect...
bool AllowNew
Gets or sets a value indicating whether data binding can automatically add new items to this collecti...
override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Raises the CollectionChanged event.
bool RaiseListChangedEvents
Gets or sets a value indicating whether the collection should raise changed events.
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.
async Task UpdateChildAsync(T child)
Inserts, updates or deletes an existing 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 ListItemNotAChildException
Looks up a localized string similar to List item must be marked as a child object.
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.
void AddValue(string name, object value)
Adds a value to the serialization stream.
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.
void RemoveChild(Core.IEditableBusinessObject child)
Removes the specified child from the parent 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.
void CopyState(int parentEditLevel, bool parentBindingEdit)
Copies the state of the object and places the copy onto the state stack.
Implement if a class requires access to the CSLA ApplicationContext type.
This is the base class from which most business collections or lists will be derived.
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.