9using System.Collections.Generic;
10using System.ComponentModel;
45 Server.IDataPortalTarget,
86 private int _identity = -1;
90 get {
return _identity; }
93 private void InitializeIdentity()
95 _identity = ((
IParent)
this).GetNextIdentity(_identity);
105 if (me.Parent !=
null)
107 return me.Parent.GetNextIdentity(current);
111 if (_identityManager ==
null)
119 #region SaveItem Methods
121 private bool _activelySaving;
154 bool raisingEvents = this.RaiseListChangedEvents;
155 this.RaiseListChangedEvents =
false;
156 _activelySaving =
true;
159 T result =
default(T);
167 ICloneable clonable = savable as ICloneable;
168 if (clonable !=
null)
169 savable = (T)clonable.Clone();
172 int editLevel = savable.EditLevel;
173 for (
int tmp = 1; tmp <= editLevel; tmp++)
174 savable.AcceptChanges(editLevel - tmp,
false);
177 result = (T)savable.Save();
179 if (!ReferenceEquals(result, item))
182 for (
int tmp = 1; tmp <= editLevel; tmp++)
183 result.CopyState(tmp,
false);
186 this[index] = result;
189 if (!ReferenceEquals(savable, item))
192 Core.ISavable original = item as Core.ISavable;
193 if (original !=
null)
194 original.SaveComplete(result);
201 _activelySaving =
false;
202 this.RaiseListChangedEvents = raisingEvents;
204 this.OnListChanged(
new ListChangedEventArgs(ListChangedType.ItemChanged, index));
220 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design",
221 "CA1062:ValidateArgumentsOfPublicMethods")]
226 if (value.Method.IsPublic &&
227 (value.Method.DeclaringType.IsSerializable ||
228 value.Method.IsStatic))
230 System.Delegate.Combine(_serializableSavedHandlers, value);
233 System.Delegate.Combine(_nonSerializableSavedHandlers, value);
237 if (value.Method.IsPublic &&
238 (value.Method.DeclaringType.IsSerializable ||
239 value.Method.IsStatic))
240 _serializableSavedHandlers = (EventHandler<Csla.Core.SavedEventArgs>)
241 System.Delegate.Remove(_serializableSavedHandlers, value);
244 System.Delegate.Remove(_nonSerializableSavedHandlers, value);
258 [EditorBrowsable(EditorBrowsableState.Advanced)]
259 protected virtual void OnSaved(T newObject, Exception e)
262 if (_nonSerializableSavedHandlers !=
null)
263 _nonSerializableSavedHandlers.Invoke(
this, args);
264 if (_serializableSavedHandlers !=
null)
265 _serializableSavedHandlers.Invoke(
this, args);
270#region Insert, Remove, Clear
281 this.OnAddingNew(
new AddingNewEventArgs(item));
293 item.SetParent(
this);
294 base.InsertItem(index, item);
305 T item =
this[index];
308 bool raiseEventForNewItem =
false;
316 raiseEventForNewItem =
true;
319 base.RemoveItem(index);
320 if (raiseEventForNewItem)
330 protected override void SetItem(
int index, T item)
332 item.SetParent(
this);
333 base.SetItem(index, item);
338#region IParent Members
342 if (!_activelySaving && child.EditLevel == 0)
359#region Cascade Child events
368 [EditorBrowsable(EditorBrowsableState.Never)]
371 for (
int index = 0; index < this.Count; index++)
373 if (ReferenceEquals(
this[index], sender))
375 PropertyDescriptor descriptor = GetPropertyDescriptor(e.PropertyName);
376 if (descriptor !=
null)
377 OnListChanged(
new ListChangedEventArgs(
378 ListChangedType.ItemChanged, index, GetPropertyDescriptor(e.PropertyName)));
380 OnListChanged(
new ListChangedEventArgs(
381 ListChangedType.ItemChanged, index));
386 base.Child_PropertyChanged(sender, e);
404 [EditorBrowsable(EditorBrowsableState.Advanced)]
408 private static PropertyDescriptorCollection _propertyDescriptors;
410 private PropertyDescriptor GetPropertyDescriptor(
string propertyName)
412 if (_propertyDescriptors ==
null)
413 _propertyDescriptors = TypeDescriptor.GetProperties(this.GetType());
414 PropertyDescriptor result =
null;
415 foreach (PropertyDescriptor desc
in _propertyDescriptors)
416 if (desc.Name == propertyName)
426#region Serialization Notification
432 [EditorBrowsable(EditorBrowsableState.Advanced)]
438 INotifyPropertyChanged c = child as INotifyPropertyChanged;
442 base.OnDeserialized();
449 private void DataPortal_Update()
451 throw new NotSupportedException(Properties.Resources.UpdateNotSupportedException);
454 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Usage",
"CA1801:ReviewUnusedParameters", MessageId =
"criteria")]
456 private void DataPortal_Delete(
object criteria)
458 throw new NotSupportedException(Properties.Resources.DeleteNotSupportedException);
466 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member"), EditorBrowsable(EditorBrowsableState.Advanced)]
477 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member"), EditorBrowsable(EditorBrowsableState.Advanced)]
489 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores", MessageId =
"Member"), EditorBrowsable(EditorBrowsableState.Advanced)]
504 List<T> result =
new List<T>();
505 foreach (T item
in this)
507 return result.ToArray();
512#region IDataPortalTarget Members
565 foreach (T child
in this)
575 #region Mobile object overrides
586 info.
AddValue(
"Csla.Core.BusinessBase._identity", _identity);
587 base.OnGetState(info);
599 _identity = info.GetValue<
int>(
"Csla.Core.BusinessBase._identity");
600 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...
ApplicationContext(ApplicationContextAccessor applicationContextAccessor)
Creates a new instance of the type
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.
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...
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 type.
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.
ApplicationContext ApplicationContext
Gets the current ApplicationContext
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.
Implement if a class requires access to the CSLA ApplicationContext type.
Interface to be implemented by any object that supports serialization by the SerializationFormatterFa...
@ Serializable
Prevents updating or inserting until the transaction is complete.