9using System.Collections.Generic;
10using System.ComponentModel;
45 Server.IDataPortalTarget,
73 private int _identity = -1;
77 get {
return _identity; }
80 private void InitializeIdentity()
82 _identity = ((
IParent)
this).GetNextIdentity(_identity);
92 if (me.Parent !=
null)
94 return me.Parent.GetNextIdentity(current);
98 if (_identityManager ==
null)
106 #region SaveItem Methods
108 private bool _activelySaving;
141 bool raisingEvents = this.RaiseListChangedEvents;
142 this.RaiseListChangedEvents =
false;
143 _activelySaving =
true;
146 T result =
default(T);
154 ICloneable clonable = savable as ICloneable;
155 if (clonable !=
null)
156 savable = (T)clonable.Clone();
159 int editLevel = savable.EditLevel;
160 for (
int tmp = 1; tmp <= editLevel; tmp++)
161 savable.AcceptChanges(editLevel - tmp,
false);
164 result = (T)savable.Save();
166 if (!ReferenceEquals(result, item))
169 for (
int tmp = 1; tmp <= editLevel; tmp++)
170 result.CopyState(tmp,
false);
173 this[index] = result;
176 if (!ReferenceEquals(savable, item))
179 Core.ISavable original = item as Core.ISavable;
180 if (original !=
null)
181 original.SaveComplete(result);
188 _activelySaving =
false;
189 this.RaiseListChangedEvents = raisingEvents;
191 this.OnListChanged(
new ListChangedEventArgs(ListChangedType.ItemChanged, index));
207 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design",
208 "CA1062:ValidateArgumentsOfPublicMethods")]
213 if (value.Method.IsPublic &&
214 (value.Method.DeclaringType.IsSerializable ||
215 value.Method.IsStatic))
217 System.Delegate.Combine(_serializableSavedHandlers, value);
220 System.Delegate.Combine(_nonSerializableSavedHandlers, value);
224 if (value.Method.IsPublic &&
225 (value.Method.DeclaringType.IsSerializable ||
226 value.Method.IsStatic))
227 _serializableSavedHandlers = (EventHandler<Csla.Core.SavedEventArgs>)
228 System.Delegate.Remove(_serializableSavedHandlers, value);
231 System.Delegate.Remove(_nonSerializableSavedHandlers, value);
245 [EditorBrowsable(EditorBrowsableState.Advanced)]
246 protected virtual void OnSaved(T newObject, Exception e)
249 if (_nonSerializableSavedHandlers !=
null)
250 _nonSerializableSavedHandlers.Invoke(
this, args);
251 if (_serializableSavedHandlers !=
null)
252 _serializableSavedHandlers.Invoke(
this, args);
257#region Insert, Remove, Clear
267 this.OnAddingNew(
new AddingNewEventArgs(item));
279 item.SetParent(
this);
280 base.InsertItem(index, item);
291 T item =
this[index];
294 bool raiseEventForNewItem =
false;
302 raiseEventForNewItem =
true;
305 base.RemoveItem(index);
306 if (raiseEventForNewItem)
316 protected override void SetItem(
int index, T item)
318 item.SetParent(
this);
319 base.SetItem(index, item);
324#region IParent Members
328 if (!_activelySaving && child.EditLevel == 0)
345#region Cascade Child events
354 [EditorBrowsable(EditorBrowsableState.Never)]
357 for (
int index = 0; index < this.Count; index++)
359 if (ReferenceEquals(
this[index], sender))
361 PropertyDescriptor descriptor = GetPropertyDescriptor(e.PropertyName);
362 if (descriptor !=
null)
363 OnListChanged(
new ListChangedEventArgs(
364 ListChangedType.ItemChanged, index, GetPropertyDescriptor(e.PropertyName)));
366 OnListChanged(
new ListChangedEventArgs(
367 ListChangedType.ItemChanged, index));
372 base.Child_PropertyChanged(sender, e);
390 [EditorBrowsable(EditorBrowsableState.Advanced)]
394 private static PropertyDescriptorCollection _propertyDescriptors;
396 private PropertyDescriptor GetPropertyDescriptor(
string propertyName)
398 if (_propertyDescriptors ==
null)
399 _propertyDescriptors = TypeDescriptor.GetProperties(this.GetType());
400 PropertyDescriptor result =
null;
401 foreach (PropertyDescriptor desc
in _propertyDescriptors)
402 if (desc.Name == propertyName)
412#region Serialization Notification
418 [EditorBrowsable(EditorBrowsableState.Advanced)]
424 INotifyPropertyChanged c = child as INotifyPropertyChanged;
428 base.OnDeserialized();
435 private void DataPortal_Update()
437 throw new NotSupportedException(Properties.Resources.UpdateNotSupportedException);
440 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Usage",
"CA1801:ReviewUnusedParameters", MessageId =
"criteria")]
442 private void DataPortal_Delete(
object criteria)
444 throw new NotSupportedException(Properties.Resources.DeleteNotSupportedException);
452 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member"), EditorBrowsable(EditorBrowsableState.Advanced)]
463 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member"), EditorBrowsable(EditorBrowsableState.Advanced)]
475 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member"), EditorBrowsable(EditorBrowsableState.Advanced)]
490 List<T> result =
new List<T>();
491 foreach (T item
in this)
493 return result.ToArray();
498#region IDataPortalTarget Members
551 foreach (T child
in this)
561 #region Mobile object overrides
572 info.
AddValue(
"Csla.Core.BusinessBase._identity", _identity);
573 base.OnGetState(info);
585 _identity = info.GetValue<
int>(
"Csla.Core.BusinessBase._identity");
586 base.OnSetState(info);
Event arguments for the BusyChanged event.
Extends BindingList of T by adding extra behaviors.
virtual void OnBusyChanged(BusyChangedEventArgs args)
Override this method to be notified when the IsBusy property has changed.
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...
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.
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.
EventHandler< Csla.Core.SavedEventArgs > Saved
Event raised when an object has been saved.
override void Child_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
Handles any PropertyChanged event from a child object and echoes it up as a ChildChanged event.
virtual void OnChildPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
Override this method to be notified when a child object has been changed.
override bool IsBusy
Gets a value indicating whether this object is currently running an async operation.
virtual void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
Called by the server-side DataPortal after calling the requested DataPortal_xyz method.
virtual void OnSaved(T newObject, Exception e)
Raises the Saved event.
virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
Called by the server-side DataPortal if an exception occurs during data access.
T[] ToArray()
Get an array containing all items in the list.
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 OnGetState(SerializationInfo info)
Override this method to insert your field values into the MobileFormatter serialzation stream.
DynamicBindingListBase()
Creates an instance of the object.
override void SetItem(int index, T item)
Replaces item in the list.
override void InsertItem(int index, T item)
Gives the new object a parent reference to this list.
override void OnDeserialized()
This method is called on a newly deserialized object after deserialization is complete.
T SaveItem(T item)
Saves the specified item in the list.
override object AddNewCore()
Adds a new item to the list.
override void RemoveItem(int index)
Removes an item from the list.
virtual T SaveItem(int index)
Saves the specified item in the list.
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...
@ Serializable
Prevents updating or inserting until the transaction is complete.