9using System.ComponentModel;
10using System.ComponentModel.DataAnnotations;
13using System.Collections.Generic;
14using System.Collections.Specialized;
19using System.Threading.Tasks;
30 [System.Diagnostics.DebuggerStepThrough]
66 private int _identity = -1;
70 get {
return _identity; }
73 private void InitializeIdentity()
75 _identity = ((
IParent)
this).GetNextIdentity(_identity);
84 if (this.Parent !=
null)
90 if (_identityManager ==
null)
100 object ICloneable.Clone()
109 [EditorBrowsable(EditorBrowsableState.Advanced)]
112 return Core.ObjectCloner.Clone(
this);
126 #region Delete and Undelete child
134 [System.Diagnostics.CodeAnalysis.SuppressMessage(
135 "Microsoft.Design",
"CA1002:DoNotExposeGenericLists")]
136 [EditorBrowsable(EditorBrowsableState.Advanced)]
141 if (_deletedList ==
null)
147 private void DeleteChild(C child)
150 Core.UndoableBase.ResetChildEditLevel(child, this.
EditLevel,
false);
158 private void UnDeleteChild(C child)
167 int saveLevel = child.EditLevelAdded;
170 child.EditLevelAdded = saveLevel;
178 [EditorBrowsable(EditorBrowsableState.Advanced)]
186 #region Begin/Cancel/ApplyEdit
258 void Core.IParent.ApplyEditChild(Core.IEditableBusinessObject child)
265 get {
return this.Parent; }
283 #region Insert, Remove, Clear
331 item.SetParent(
this);
333 Core.UndoableBase.ResetChildEditLevel(item, this.
EditLevel,
false);
337 item.EditLevelAdded = _editLevel;
338 base.InsertItem(index, item);
356 C child =
this[index];
359 base.RemoveItem(index);
361 if (!_completelyRemoveChild)
368 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, child, index));
382 protected override void SetItem(
int index, C item)
384 C child =
default(C);
385 if (!(ReferenceEquals((C)(
this[index]), item)))
396 item.SetParent(
this);
398 Core.UndoableBase.ResetChildEditLevel(item, this.
EditLevel,
false);
402 base.SetItem(index, item);
421 #region Edit level tracking
424 private int _editLevel;
429 [EditorBrowsable(EditorBrowsableState.Never)]
432 get {
return _editLevel; }
435 int Core.IUndoableObject.EditLevel
447 void Core.IUndoableObject.CopyState(
int parentEditLevel,
bool parentBindingEdit)
449 if (!parentBindingEdit)
450 CopyState(parentEditLevel);
453 void Core.IUndoableObject.UndoChanges(
int parentEditLevel,
bool parentBindingEdit)
455 if (!parentBindingEdit)
456 UndoChanges(parentEditLevel);
459 void Core.IUndoableObject.AcceptChanges(
int parentEditLevel,
bool parentBindingEdit)
461 if (!parentBindingEdit)
462 AcceptChanges(parentEditLevel);
465 private void CopyState(
int parentEditLevel)
467 if (this.
EditLevel + 1 > parentEditLevel)
474 for (
int x = 0; x < this.Count; x++)
482 child.CopyState(_editLevel,
false);
485 private bool _completelyRemoveChild;
487 private void UndoChanges(
int parentEditLevel)
491 if (this.
EditLevel - 1 != parentEditLevel)
496 if (_editLevel < 0) _editLevel = 0;
503 for (
int index = Count - 1; index >= 0; index--)
513 child.UndoChanges(_editLevel,
false);
520 if (child.EditLevelAdded > _editLevel)
526 _completelyRemoveChild =
true;
532 _completelyRemoveChild =
false;
539 for (
int index =
DeletedList.Count - 1; index >= 0; index--)
542 child.UndoChanges(_editLevel,
false);
543 if (child.EditLevelAdded > _editLevel)
551 if (!child.IsDeleted) UnDeleteChild(child);
557 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
562 private void AcceptChanges(
int parentEditLevel)
564 if (this.
EditLevel - 1 != parentEditLevel)
571 foreach (C child
in this)
573 child.AcceptChanges(_editLevel,
false);
575 if (child.EditLevelAdded > _editLevel) child.EditLevelAdded = _editLevel;
579 for (
int index =
DeletedList.Count - 1; index >= 0; index--)
582 child.AcceptChanges(_editLevel,
false);
584 if (child.EditLevelAdded > _editLevel)
588 if (_editLevel < 0) _editLevel = 0;
593 #region Mobile Object overrides
605 info.
AddValue(
"Csla.BusinessListBase._isChild", _isChild);
606 info.
AddValue(
"Csla.BusinessListBase._editLevel", _editLevel);
607 info.
AddValue(
"Csla.Core.BusinessBase._identity", _identity);
608 base.OnGetState(info);
621 _isChild = info.GetValue<
bool>(
"Csla.BusinessListBase._isChild");
622 _editLevel = info.GetValue<
int>(
"Csla.BusinessListBase._editLevel");
623 _identity = info.GetValue<
int>(
"Csla.Core.BusinessBase._identity");
624 base.OnSetState(info);
640 base.OnGetChildren(info, formatter);
641 if (_deletedList !=
null)
643 var fieldManagerInfo = formatter.SerializeObject(_deletedList);
644 info.AddChild(
"_deletedList", fieldManagerInfo.ReferenceId);
661 if (info.Children.ContainsKey(
"_deletedList"))
663 var childData = info.Children[
"_deletedList"];
664 _deletedList = (
MobileList<C>)formatter.GetObject(childData.ReferenceId);
674 private bool _isChild =
false;
682 get {
return _isChild; }
710 #region IsDirty, IsValid, IsSavable
715 bool Core.ITrackStatus.IsSelfDirty
735 foreach (C child
in this)
742 bool Core.ITrackStatus.IsSelfValid
744 get {
return IsSelfValid; }
751 protected virtual bool IsSelfValid
767 foreach (C child
in this)
801 foreach (C child
in this)
813 bool Core.ITrackStatus.IsNew
821 bool Core.ITrackStatus.IsDeleted
831 #region Serialization Notification
836 [EditorBrowsable(EditorBrowsableState.Advanced)]
839 base.OnDeserialized();
840 foreach (Core.IEditableBusinessObject child in
this)
841 child.SetParent(
this);
843 foreach (Core.IEditableBusinessObject child in
DeletedList)
844 child.SetParent(
this);
849 #region Child Data Access
855 [EditorBrowsable(EditorBrowsableState.Advanced)]
868 [EditorBrowsable(EditorBrowsableState.Advanced)]
877 foreach (var child
in this)
919 catch (AggregateException ex)
921 if (ex.InnerExceptions.Count > 0)
922 throw ex.InnerExceptions[0];
941 protected virtual async Task<T>
SaveAsync(
object userState,
bool isSync)
971 OnSaved(result,
null, userState);
1024 public async
void BeginSave(EventHandler<SavedEventArgs> handler,
object userState)
1026 Exception error =
null;
1027 T result =
default(T);
1030 result = await
SaveAsync(userState,
false);
1032 catch (AggregateException ex)
1034 if (ex.InnerExceptions.Count > 0)
1035 error = ex.InnerExceptions[0];
1039 catch (Exception ex)
1043 if (handler !=
null)
1052 [EditorBrowsable(EditorBrowsableState.Advanced)]
1061 [EditorBrowsable(EditorBrowsableState.Advanced)]
1071 [EditorBrowsable(EditorBrowsableState.Advanced)]
1080 [EditorBrowsable(EditorBrowsableState.Advanced)]
1089 [EditorBrowsable(EditorBrowsableState.Advanced)]
1099 [EditorBrowsable(EditorBrowsableState.Advanced)]
1105 #region ISavable Members
1140 OnSaved((T)newObject,
null,
null);
1160 OnSaved(newObject,
null,
null);
1170 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design",
1171 "CA1062:ValidateArgumentsOfPublicMethods")]
1177 System.Delegate.Combine(_savedEvent, value);
1182 System.Delegate.Remove(_savedEvent, value);
1194 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1195 protected virtual void OnSaved(T newObject, Exception e,
object userState)
1198 if (_savedEvent !=
null)
1199 _savedEvent.Invoke(
this, args);
1203 #region Parent/Child link
1205 [NotUndoable(), NonSerialized()]
1206 private Core.IParent _parent;
1216 [Display(AutoGenerateField=
false)]
1217 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
1218 [EditorBrowsable(EditorBrowsableState.Advanced)]
1219 public Core.IParent Parent
1236 _identityManager =
null;
1237 InitializeIdentity();
1246 void Core.IEditableCollection.SetParent(Core.IParent parent)
1253 #region IDataPortalTarget Members
1255 void IDataPortalTarget.CheckRules()
1258 void IDataPortalTarget.MarkAsChild()
1263 void IDataPortalTarget.MarkNew()
1266 void IDataPortalTarget.MarkOld()
1269 void IDataPortalTarget.DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
1274 void IDataPortalTarget.DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
1279 void IDataPortalTarget.DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
1284 void IDataPortalTarget.Child_OnDataPortalInvoke(DataPortalEventArgs e)
1289 void IDataPortalTarget.Child_OnDataPortalInvokeComplete(DataPortalEventArgs e)
1294 void IDataPortalTarget.Child_OnDataPortalException(DataPortalEventArgs e, Exception ex)
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 object.
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.
async void BeginSave(EventHandler< SavedEventArgs > handler, object userState)
Starts an async operation to save the object to the database.
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.
void BeginSave()
Starts an async operation to save the object to the database.
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...
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.
void BeginSave(object userState)
Starts an async operation to save the object to the database.
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.
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 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(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.
void BeginSave()
Saves the object to the database asynchronously.
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.
This is the base class from which most business collections or lists will be derived.
@ Serializable
Prevents updating or inserting until the transaction is complete.