9using System.Collections.Generic;
10using System.Collections.Specialized;
11using System.ComponentModel;
12using System.Threading.Tasks;
46#if (ANDROID || IOS) || NETFX_CORE
78 private int _identity = -1;
82 get {
return _identity; }
85 private void InitializeIdentity()
87 _identity = ((
IParent)
this).GetNextIdentity(_identity);
97 if (me.Parent !=
null)
99 return me.Parent.GetNextIdentity(current);
103 if (_identityManager ==
null)
111 #region SaveItem Methods
125 [EditorBrowsable(EditorBrowsableState.Advanced)]
126 protected virtual void OnSaved(T newObject, Exception error)
157 T item =
this[index];
158 var handleBusy =
false;
159 if ((item.IsDeleted ||
delete) || (item.IsValid && item.IsDirty))
164 ICloneable cloneable = savable as ICloneable;
165 if (cloneable !=
null)
167 savable = (T)cloneable.Clone();
168 MethodCaller.CallMethodIfImplemented(item,
"MarkBusy");
173 int editLevel = savable.EditLevel;
174 for (
int tmp = 1; tmp <= editLevel; tmp++)
175 savable.AcceptChanges(editLevel - tmp,
false);
180 Exception error =
null;
181 T result =
default(T);
186 catch (AggregateException ex)
188 if (ex.InnerExceptions.Count > 0)
189 error = ex.InnerExceptions[0];
200 MethodCaller.CallMethodIfImplemented(item,
"MarkIdle");
203 index = IndexOf(item);
204 if (error ==
null && result !=
null)
206 if (savable.IsDeleted)
209 SafeRemoveItem(index);
213 for (
int tmp = 1; tmp <= editLevel; tmp++)
214 result.CopyState(tmp,
false);
216 SafeSetItem(index, result);
217 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
218 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add,
this[index], index));
220 item.SaveComplete(result);
225 item.SaveComplete(item);
266 catch (AggregateException ex)
268 if (ex.InnerExceptions.Count > 0)
269 throw ex.InnerExceptions[0];
275 private void SafeSetItem(
int index, T newObject)
278 this[index].SetParent(
null);
279 base.OnRemoveEventHooks(
this[index]);
280 newObject.SetParent(
this);
281 base.SetItem(index, newObject);
282 base.OnAddEventHooks(newObject);
285 private void SafeRemoveItem(
int index)
287 this[index].SetParent(
null);
288 base.OnRemoveEventHooks(
this[index]);
289 base.RemoveItem(index);
294 #region Insert, Remove, Clear
296#if NETFX_CORE || (ANDROID || IOS)
326 portal.BeginCreate();
349 item.SetParent(
this);
350 base.InsertItem(index, item);
360 T item =
this[index];
361 if (item.IsDeleted ==
false)
370 catch (AggregateException ex)
372 if (ex.InnerExceptions.Count > 0)
373 throw ex.InnerExceptions[0];
380 SafeRemoveItem(index);
392 protected override void SetItem(
int index, T item)
394 item.SetParent(
this);
395 base.SetItem(index, item);
400 #region IParent Members
424 base.OnCollectionChanged(e);
441 if (child.EditLevel == 0)
473 foreach (T child
in this)
482 #region Serialization Notification
487 [EditorBrowsable(EditorBrowsableState.Advanced)]
493 base.OnDeserialized();
500 private void DataPortal_Update()
502 throw new NotSupportedException(Properties.Resources.UpdateNotSupportedException);
505 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Usage",
"CA1801:ReviewUnusedParameters", MessageId =
"criteria")]
507 private void DataPortal_Delete(
object criteria)
509 throw new NotSupportedException(Properties.Resources.DeleteNotSupportedException);
517 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member"), EditorBrowsable(EditorBrowsableState.Advanced)]
528 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member"), EditorBrowsable(EditorBrowsableState.Advanced)]
540 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member"), EditorBrowsable(EditorBrowsableState.Advanced)]
555 List<T> result =
new List<T>();
556 foreach (T item
in this)
558 return result.ToArray();
563 #region IDataPortalTarget Members
603 #region Mobile object overrides
614 info.
AddValue(
"Csla.Core.BusinessBase._identity", _identity);
615 base.OnGetState(info);
627 _identity = info.GetValue<
int>(
"Csla.Core.BusinessBase._identity");
628 base.OnSetState(info);
Event arguments for an unhandled async exception.
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...
Extends ObservableCollection with behaviors required by CSLA .NET collections.
bool AllowNew
Gets or sets a value indicating whether data binding can automatically add new items to this collecti...
virtual void OnAddedNew(T item)
Raises the AddedNew event.
virtual void OnUnhandledAsyncException(ErrorEventArgs error)
Method invoked when an unhandled async exception has occurred.
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() ...
Provides information about the DataPortal call.
This is the client-side DataPortal.
async Task< T > UpdateAsync(T obj)
Called by a factory method in a business class or by the UI to update an object.
EventHandler< DataPortalResult< T > > CreateCompleted
Event raised when the operation has completed.
static object Create(Type objectType, object criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...
This is the base class from which collections of editable root business objects should be derived.
override void SetItem(int index, T item)
Replaces item in the list.
override void OnGetState(SerializationInfo info)
Override this method to insert your field values into the MobileFormatter serialzation stream.
DynamicListBase()
Creates an instance of the object.
async Task SaveItemAsync(int index)
Saves the specified item in the list.
override bool SupportsChangeNotificationCore
Gets a value indicating whether this collection supports change notification (always returns true).
override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Raises the CollectionChanged event.
async void SaveItem(int index)
Saves the specified item in the list.
EventHandler< Csla.Core.SavedEventArgs > Saved
Event raised when an object in the list has been saved.
void SaveItem(T item)
Saves the specified item in the list.
T[] ToArray()
Get an array containing all items in the list.
override void OnDeserialized()
Set parent reference.
virtual async Task SaveItemAsync(int index, bool delete)
Saves the specified item in the list.
virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
Called by the server-side DataPortal if an exception occurs during data access.
async Task SaveItemAsync(T item)
Saves the specified item in the list.
override T AddNewCore()
Adds a new item to the list.
override async void RemoveItem(int index)
Removes an item from the list.
virtual void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
Called by the server-side DataPortal after calling the requested DataPortal_xyz method.
bool RaiseReplaceEvents
Gets or sets a value indicating whether the Replace event should be raised when OnCollectionChanged()...
override bool IsBusy
Gets a value indicating whether this object or any child object is currently executing an async opera...
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_OnDataPortalInvoke(DataPortalEventArgs e)
Called by the server-side DataPortal prior to calling the requested DataPortal_xyz method.
override void OnSetState(SerializationInfo info)
Override this method to retrieve your field values from the MobileFormatter serialzation stream.
override void InsertItem(int index, T item)
Gives the new object a parent reference to this list.
virtual void OnSaved(T newObject, Exception error)
Raises the Saved event.
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.
void SetParent(IParent parent)
Used by BusinessListBase as a child object is created to tell the child object about its parent.
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...
void ApplyEditChild(Core.IEditableBusinessObject child)
Override this method to be notified when a child object's Core.BusinessBase.ApplyEdit method has comp...
void RemoveChild(Core.IEditableBusinessObject child)
This method is called by a child object when it wants to be removed from the collection.
IParent Parent
Provide access to the parent reference for use in child object code.
Specifies that the object can save itself.
Defines the methods required to participate in n-level undo within the CSLA .NET framework.
Interface to be implemented by any object that supports serialization by the SerializationFormatterFa...
Interface defining callback methods used by the SerializationFormatterFactory.GetFormatter().
@ Serializable
Prevents updating or inserting until the transaction is complete.