9using System.Collections.Generic;
10using System.Collections.Specialized;
11using System.ComponentModel;
12using System.Threading.Tasks;
46#if (ANDROID || IOS) || NETFX_CORE
84 private int _identity = -1;
88 get {
return _identity; }
91 private void InitializeIdentity()
93 _identity = ((
IParent)
this).GetNextIdentity(_identity);
103 if (me.Parent !=
null)
105 return me.Parent.GetNextIdentity(current);
109 if (_identityManager ==
null)
117 #region SaveItem Methods
131 [EditorBrowsable(EditorBrowsableState.Advanced)]
132 protected virtual void OnSaved(T newObject, Exception error)
163 T item =
this[index];
164 var handleBusy =
false;
165 if ((item.IsDeleted ||
delete) || (item.IsValid && item.IsDirty))
170 ICloneable cloneable = savable as ICloneable;
171 if (cloneable !=
null)
173 savable = (T)cloneable.Clone();
174 MethodCaller.CallMethodIfImplemented(item,
"MarkBusy");
179 int editLevel = savable.EditLevel;
180 for (
int tmp = 1; tmp <= editLevel; tmp++)
181 savable.AcceptChanges(editLevel - tmp,
false);
186 Exception error =
null;
187 T result =
default(T);
193 catch (AggregateException ex)
195 if (ex.InnerExceptions.Count > 0)
196 error = ex.InnerExceptions[0];
207 MethodCaller.CallMethodIfImplemented(item,
"MarkIdle");
210 index = IndexOf(item);
211 if (error ==
null && result !=
null)
213 if (savable.IsDeleted)
216 SafeRemoveItem(index);
220 for (
int tmp = 1; tmp <= editLevel; tmp++)
221 result.CopyState(tmp,
false);
223 SafeSetItem(index, result);
224 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
225 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add,
this[index], index));
227 item.SaveComplete(result);
232 item.SaveComplete(item);
273 catch (AggregateException ex)
275 if (ex.InnerExceptions.Count > 0)
276 throw ex.InnerExceptions[0];
282 private void SafeSetItem(
int index, T newObject)
285 this[index].SetParent(
null);
286 base.OnRemoveEventHooks(
this[index]);
287 newObject.SetParent(
this);
288 base.SetItem(index, newObject);
289 base.OnAddEventHooks(newObject);
292 private void SafeRemoveItem(
int index)
294 this[index].SetParent(
null);
295 base.OnRemoveEventHooks(
this[index]);
296 base.RemoveItem(index);
301 #region Insert, Remove, Clear
323 item.SetParent(
this);
324 base.InsertItem(index, item);
334 T item =
this[index];
335 if (item.IsDeleted ==
false)
344 catch (AggregateException ex)
346 if (ex.InnerExceptions.Count > 0)
347 throw ex.InnerExceptions[0];
354 SafeRemoveItem(index);
366 protected override void SetItem(
int index, T item)
368 item.SetParent(
this);
369 base.SetItem(index, item);
374 #region IParent Members
398 base.OnCollectionChanged(e);
415 if (child.EditLevel == 0)
447 foreach (T child
in this)
456 #region Serialization Notification
461 [EditorBrowsable(EditorBrowsableState.Advanced)]
467 base.OnDeserialized();
474 private void DataPortal_Update()
476 throw new NotSupportedException(Properties.Resources.UpdateNotSupportedException);
479 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Usage",
"CA1801:ReviewUnusedParameters", MessageId =
"criteria")]
481 private void DataPortal_Delete(
object criteria)
483 throw new NotSupportedException(Properties.Resources.DeleteNotSupportedException);
491 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member"), EditorBrowsable(EditorBrowsableState.Advanced)]
502 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member"), EditorBrowsable(EditorBrowsableState.Advanced)]
514 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member"), EditorBrowsable(EditorBrowsableState.Advanced)]
529 List<T> result =
new List<T>();
530 foreach (T item
in this)
532 return result.ToArray();
537 #region IDataPortalTarget Members
577 #region Mobile object overrides
588 info.
AddValue(
"Csla.Core.BusinessBase._identity", _identity);
589 base.OnGetState(info);
601 _identity = info.GetValue<
int>(
"Csla.Core.BusinessBase._identity");
602 base.OnSetState(info);
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...
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...
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.
Client side data portal used for making asynchronous data portal calls in .NET.
T Create(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...
async Task< T > UpdateAsync(T obj)
Called by a factory method in a business class or by the UI to update an object.
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 type.
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.
ApplicationContext ApplicationContext
Gets the current ApplicationContext
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.
Implement if a class requires access to the CSLA ApplicationContext type.
ApplicationContext ApplicationContext
Gets or sets the current ApplicationContext object.
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.