CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
BusinessListBase.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="BusinessListBase.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>This is the base class from which most business collections</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.ComponentModel;
10using System.ComponentModel.DataAnnotations;
11using Csla.Core;
12using Csla.Properties;
13using System.Collections.Generic;
14using System.Collections.Specialized;
17using Csla.Server;
18using System.Linq;
19using System.Threading.Tasks;
20
21namespace Csla
22{
29#if TESTING
30 [System.Diagnostics.DebuggerStepThrough]
31#endif
33 public abstract class BusinessListBase<T, C> :
35 IEditableCollection, Core.IUndoableObject, ICloneable,
36 ISavable, Core.ISavable<T>, Core.IParent, Server.IDataPortalTarget,
39 where T : BusinessListBase<T, C>
40 where C : Core.IEditableBusinessObject
41 {
45 protected BusinessListBase()
46 {
47 InitializeIdentity();
48 Initialize();
49 AllowNew = true;
50 }
51
52 #region Initialize
53
59 protected virtual void Initialize()
60 { /* allows subclass to initialize events before any other activity occurs */ }
61
62 #endregion
63
64 #region Identity
65
66 private int _identity = -1;
67
69 {
70 get { return _identity; }
71 }
72
73 private void InitializeIdentity()
74 {
75 _identity = ((IParent)this).GetNextIdentity(_identity);
76 }
77
78 [NonSerialized]
79 [NotUndoable]
80 private IdentityManager _identityManager;
81
82 int IParent.GetNextIdentity(int current)
83 {
84 if (this.Parent != null)
85 {
86 return this.Parent.GetNextIdentity(current);
87 }
88 else
89 {
90 if (_identityManager == null)
91 _identityManager = new IdentityManager();
92 return _identityManager.GetNextIdentity(current);
93 }
94 }
95
96 #endregion
97
98 #region ICloneable
99
100 object ICloneable.Clone()
101 {
102 return GetClone();
103 }
104
109 [EditorBrowsable(EditorBrowsableState.Advanced)]
110 protected virtual object GetClone()
111 {
112 return Core.ObjectCloner.Clone(this);
113 }
114
119 public T Clone()
120 {
121 return (T)GetClone();
122 }
123
124 #endregion
125
126 #region Delete and Undelete child
127
128 private MobileList<C> _deletedList;
129
134 [System.Diagnostics.CodeAnalysis.SuppressMessage(
135 "Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
136 [EditorBrowsable(EditorBrowsableState.Advanced)]
138 {
139 get
140 {
141 if (_deletedList == null)
142 _deletedList = new MobileList<C>();
143 return _deletedList;
144 }
145 }
146
147 private void DeleteChild(C child)
148 {
149 // set child edit level
150 Core.UndoableBase.ResetChildEditLevel(child, this.EditLevel, false);
151
152 // mark the object as deleted
153 child.DeleteChild();
154 // and add it to the deleted collection for storage
155 DeletedList.Add(child);
156 }
157
158 private void UnDeleteChild(C child)
159 {
160 // since the object is no longer deleted, remove it from
161 // the deleted collection
162 DeletedList.Remove(child);
163
164 // we are inserting an _existing_ object so
165 // we need to preserve the object's editleveladded value
166 // because it will be changed by the normal add process
167 int saveLevel = child.EditLevelAdded;
168
169 Add(child);
170 child.EditLevelAdded = saveLevel;
171 }
172
178 [EditorBrowsable(EditorBrowsableState.Advanced)]
179 public bool ContainsDeleted(C item)
180 {
181 return DeletedList.Contains(item);
182 }
183
184 #endregion
185
186 #region Begin/Cancel/ApplyEdit
187
208 public void BeginEdit()
209 {
210 if (this.IsChild)
211 throw new NotSupportedException(Resources.NoBeginEditChildException);
212
213 CopyState(this.EditLevel + 1);
214 }
215
229 public void CancelEdit()
230 {
231 if (this.IsChild)
232 throw new NotSupportedException(Resources.NoCancelEditChildException);
233
234 UndoChanges(this.EditLevel - 1);
235 }
236
250 public void ApplyEdit()
251 {
252 if (this.IsChild)
253 throw new NotSupportedException(Resources.NoApplyEditChildException);
254
255 AcceptChanges(this.EditLevel - 1);
256 }
257
258 void Core.IParent.ApplyEditChild(Core.IEditableBusinessObject child)
259 {
260 EditChildComplete(child);
261 }
262
263 IParent Core.IParent.Parent
264 {
265 get { return this.Parent; }
266 }
267
274 protected virtual void EditChildComplete(Core.IEditableBusinessObject child)
275 {
276
277 // do nothing, we don't really care
278 // when a child has its edits applied
279 }
280
281 #endregion
282
283 #region Insert, Remove, Clear
284
289 protected override C AddNewCore()
290 {
291 var item = DataPortal.CreateChild<C>();
292 Add(item);
293 return item;
294 }
295
302 {
303 Remove((C)child);
304 }
305
307 {
308 return DeletedList;
309 }
310
316 void Core.IParent.RemoveChild(Csla.Core.IEditableBusinessObject child)
317 {
318 Remove((C)child);
319 }
320
326 protected override void InsertItem(int index, C item)
327 {
328 if (item.IsChild)
329 {
330 // set parent reference
331 item.SetParent(this);
332 // set child edit level
333 Core.UndoableBase.ResetChildEditLevel(item, this.EditLevel, false);
334 // when an object is inserted we assume it is
335 // a new object and so the edit level when it was
336 // added must be set
337 item.EditLevelAdded = _editLevel;
338 base.InsertItem(index, item);
339 }
340 else
341 {
342 // item must be marked as a child object
343 throw new InvalidOperationException(Resources.ListItemNotAChildException);
344 }
345 }
346
352 protected override void RemoveItem(int index)
353 {
354 // when an object is 'removed' it is really
355 // being deleted, so do the deletion work
356 C child = this[index];
357 using (LoadListMode)
358 {
359 base.RemoveItem(index);
360 }
361 if (!_completelyRemoveChild)
362 {
363 // the child shouldn't be completely removed,
364 // so copy it to the deleted list
365 DeleteChild(child);
366 }
368 OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, child, index));
369 }
370
382 protected override void SetItem(int index, C item)
383 {
384 C child = default(C);
385 if (!(ReferenceEquals((C)(this[index]), item)))
386 child = this[index];
387 // replace the original object with this new
388 // object
389 using (LoadListMode)
390 {
391 if (child != null)
392 DeleteChild(child);
393 }
394
395 // set parent reference
396 item.SetParent(this);
397 // set child edit level
398 Core.UndoableBase.ResetChildEditLevel(item, this.EditLevel, false);
399 // reset EditLevelAdded
400 item.EditLevelAdded = this.EditLevel;
401 // add to list and raise list changed as appropriate
402 base.SetItem(index, item);
403 }
404
409 protected override void ClearItems()
410 {
411 while (base.Count > 0) RemoveItem(0);
412 //DeferredLoadIndexIfNotLoaded();
413 //_indexSet.ClearIndexes();
414 //DeferredLoadPositionMapIfNotLoaded();
415 //_positionMap.ClearMap();
416 base.ClearItems();
417 }
418
419 #endregion
420
421 #region Edit level tracking
422
423 // keep track of how many edit levels we have
424 private int _editLevel;
425
429 [EditorBrowsable(EditorBrowsableState.Never)]
430 protected int EditLevel
431 {
432 get { return _editLevel; }
433 }
434
435 int Core.IUndoableObject.EditLevel
436 {
437 get
438 {
439 return this.EditLevel;
440 }
441 }
442
443 #endregion
444
445 #region N-level undo
446
447 void Core.IUndoableObject.CopyState(int parentEditLevel, bool parentBindingEdit)
448 {
449 if (!parentBindingEdit)
450 CopyState(parentEditLevel);
451 }
452
453 void Core.IUndoableObject.UndoChanges(int parentEditLevel, bool parentBindingEdit)
454 {
455 if (!parentBindingEdit)
456 UndoChanges(parentEditLevel);
457 }
458
459 void Core.IUndoableObject.AcceptChanges(int parentEditLevel, bool parentBindingEdit)
460 {
461 if (!parentBindingEdit)
462 AcceptChanges(parentEditLevel);
463 }
464
465 private void CopyState(int parentEditLevel)
466 {
467 if (this.EditLevel + 1 > parentEditLevel)
468 throw new UndoException(string.Format(Resources.EditLevelMismatchException, "CopyState"), this.GetType().Name, _parent != null ? _parent.GetType().Name : null, this.EditLevel, parentEditLevel - 1);
469
470 // we are going a level deeper in editing
471 _editLevel += 1;
472
473 // cascade the call to all child objects
474 for (int x = 0; x < this.Count; x++)
475 {
476 C child = this[x];
477 child.CopyState(_editLevel, false);
478 }
479
480 // cascade the call to all deleted child objects
481 foreach (C child in DeletedList)
482 child.CopyState(_editLevel, false);
483 }
484
485 private bool _completelyRemoveChild;
486
487 private void UndoChanges(int parentEditLevel)
488 {
489 C child;
490
491 if (this.EditLevel - 1 != parentEditLevel)
492 throw new UndoException(string.Format(Resources.EditLevelMismatchException, "UndoChanges"), this.GetType().Name, _parent != null ? _parent.GetType().Name : null, this.EditLevel, parentEditLevel + 1);
493
494 // we are coming up one edit level
495 _editLevel -= 1;
496 if (_editLevel < 0) _editLevel = 0;
497
498 using (LoadListMode)
499 {
500 try
501 {
502 // Cancel edit on all current items
503 for (int index = Count - 1; index >= 0; index--)
504 {
505 child = this[index];
506
507 //ACE: Important, make sure to remove the item prior to
508 // it going through undo, otherwise, it will
509 // incur a more expensive RemoveByReference operation
510 //DeferredLoadIndexIfNotLoaded();
511 //_indexSet.RemoveItem(child);
512
513 child.UndoChanges(_editLevel, false);
514
515 //ACE: Now that we have undone the changes, we can add the item
516 // back in the index.
517 //_indexSet.InsertItem(child);
518
519 // if item is below its point of addition, remove
520 if (child.EditLevelAdded > _editLevel)
521 {
522 bool oldAllowRemove = this.AllowRemove;
523 try
524 {
525 this.AllowRemove = true;
526 _completelyRemoveChild = true;
527 //RemoveIndexItem(child);
528 RemoveAt(index);
529 }
530 finally
531 {
532 _completelyRemoveChild = false;
533 this.AllowRemove = oldAllowRemove;
534 }
535 }
536 }
537
538 // cancel edit on all deleted items
539 for (int index = DeletedList.Count - 1; index >= 0; index--)
540 {
541 child = DeletedList[index];
542 child.UndoChanges(_editLevel, false);
543 if (child.EditLevelAdded > _editLevel)
544 {
545 // if item is below its point of addition, remove
546 DeletedList.RemoveAt(index);
547 }
548 else
549 {
550 // if item is no longer deleted move back to main list
551 if (!child.IsDeleted) UnDeleteChild(child);
552 }
553 }
554 }
555 finally
556 {
557 OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
558 }
559 }
560 }
561
562 private void AcceptChanges(int parentEditLevel)
563 {
564 if (this.EditLevel - 1 != parentEditLevel)
565 throw new UndoException(string.Format(Resources.EditLevelMismatchException, "AcceptChanges"), this.GetType().Name, _parent != null ? _parent.GetType().Name : null, this.EditLevel, parentEditLevel + 1);
566
567 // we are coming up one edit level
568 _editLevel -= 1;
569
570 // cascade the call to all child objects
571 foreach (C child in this)
572 {
573 child.AcceptChanges(_editLevel, false);
574 // if item is below its point of addition, lower point of addition
575 if (child.EditLevelAdded > _editLevel) child.EditLevelAdded = _editLevel;
576 }
577
578 // cascade the call to all deleted child objects
579 for (int index = DeletedList.Count - 1; index >= 0; index--)
580 {
581 C child = DeletedList[index];
582 child.AcceptChanges(_editLevel, false);
583 // if item is below its point of addition, remove
584 if (child.EditLevelAdded > _editLevel)
585 DeletedList.RemoveAt(index);
586 }
587
588 if (_editLevel < 0) _editLevel = 0;
589 }
590
591 #endregion
592
593 #region Mobile Object overrides
594
603 protected override void OnGetState(SerializationInfo info)
604 {
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);
609 }
610
619 protected override void OnSetState(SerializationInfo info)
620 {
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);
625 }
626
639 {
640 base.OnGetChildren(info, formatter);
641 if (_deletedList != null)
642 {
643 var fieldManagerInfo = formatter.SerializeObject(_deletedList);
644 info.AddChild("_deletedList", fieldManagerInfo.ReferenceId);
645 }
646 }
647
660 {
661 if (info.Children.ContainsKey("_deletedList"))
662 {
663 var childData = info.Children["_deletedList"];
664 _deletedList = (MobileList<C>)formatter.GetObject(childData.ReferenceId);
665 }
666 base.OnSetChildren(info, formatter);
667 }
668
669 #endregion
670
671 #region IsChild
672
673 [NotUndoable()]
674 private bool _isChild = false;
675
680 public bool IsChild
681 {
682 get { return _isChild; }
683 }
684
702 protected void MarkAsChild()
703 {
704 _identity = -1;
705 _isChild = true;
706 }
707
708 #endregion
709
710 #region IsDirty, IsValid, IsSavable
711
715 bool Core.ITrackStatus.IsSelfDirty
716 {
717 get { return IsDirty; }
718 }
719
723 public bool IsDirty
724 {
725 get
726 {
727 // any non-new deletions make us dirty
728 foreach (C item in DeletedList)
729 if (!item.IsNew)
730 return true;
731
732 // run through all the child objects
733 // and if any are dirty then then
734 // collection is dirty
735 foreach (C child in this)
736 if (child.IsDirty)
737 return true;
738 return false;
739 }
740 }
741
742 bool Core.ITrackStatus.IsSelfValid
743 {
744 get { return IsSelfValid; }
745 }
746
751 protected virtual bool IsSelfValid
752 {
753 get { return IsValid; }
754 }
755
760 public virtual bool IsValid
761 {
762 get
763 {
764 // run through all the child objects
765 // and if any are invalid then the
766 // collection is invalid
767 foreach (C child in this)
768 if (!child.IsValid)
769 return false;
770 return true;
771 }
772 }
773
778 public virtual bool IsSavable
779 {
780 get
781 {
782 bool auth = Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.EditObject, this);
783 return (IsDirty && IsValid && auth && !IsBusy);
784 }
785 }
786
790 public override bool IsBusy
791 {
792 get
793 {
794 // run through all the child objects
795 // and if any are busy then then
796 // collection is busy
797 foreach (C item in DeletedList)
798 if (item.IsBusy)
799 return true;
800
801 foreach (C child in this)
802 if (child.IsBusy)
803 return true;
804
805 return false;
806 }
807 }
808
809 #endregion
810
811 #region ITrackStatus
812
813 bool Core.ITrackStatus.IsNew
814 {
815 get
816 {
817 return false;
818 }
819 }
820
821 bool Core.ITrackStatus.IsDeleted
822 {
823 get
824 {
825 return false;
826 }
827 }
828
829 #endregion
830
831 #region Serialization Notification
832
836 [EditorBrowsable(EditorBrowsableState.Advanced)]
837 protected override void OnDeserialized()
838 {
839 base.OnDeserialized();
840 foreach (Core.IEditableBusinessObject child in this)
841 child.SetParent(this);
842
843 foreach (Core.IEditableBusinessObject child in DeletedList)
844 child.SetParent(this);
845 }
846
847 #endregion
848
849 #region Child Data Access
850
855 [EditorBrowsable(EditorBrowsableState.Advanced)]
856 protected virtual void Child_Create()
857 { /* do nothing - list self-initializes */ }
858
868 [EditorBrowsable(EditorBrowsableState.Advanced)]
869 protected virtual void Child_Update(params object[] parameters)
870 {
871 using (LoadListMode)
872 {
873 foreach (var child in DeletedList)
874 DataPortal.UpdateChild(child, parameters);
875 DeletedList.Clear();
876
877 foreach (var child in this)
878 if (child.IsDirty) DataPortal.UpdateChild(child, parameters);
879 }
880 }
881
882 #endregion
883
884 #region Data Access
885
913 public T Save()
914 {
915 try
916 {
917 return SaveAsync(null, true).Result;
918 }
919 catch (AggregateException ex)
920 {
921 if (ex.InnerExceptions.Count > 0)
922 throw ex.InnerExceptions[0];
923 else
924 throw;
925 }
926 }
927
931 public async Task<T> SaveAsync()
932 {
933 return await SaveAsync(null, false);
934 }
935
941 protected virtual async Task<T> SaveAsync(object userState, bool isSync)
942 {
943 T result;
944 if (this.IsChild)
945 throw new InvalidOperationException(Resources.NoSaveChildException);
946
947 if (_editLevel > 0)
948 throw new InvalidOperationException(Resources.NoSaveEditingException);
949
950 if (!IsValid)
951 throw new Rules.ValidationException(Resources.NoSaveInvalidException);
952
953 if (IsBusy)
954 throw new InvalidOperationException(Resources.BusyObjectsMayNotBeSaved);
955
956 if (IsDirty)
957 {
958 if (isSync)
959 {
960 result = DataPortal.Update<T>((T)this);
961 }
962 else
963 {
964 result = await DataPortal.UpdateAsync<T>((T)this);
965 }
966 }
967 else
968 {
969 result = (T)this;
970 }
971 OnSaved(result, null, userState);
972 return result;
973 }
974
980 public async Task SaveAndMergeAsync()
981 {
982 new GraphMerger().MergeBusinessListGraph<T, C>((T)this, await SaveAsync());
983 }
984
988 [Obsolete]
989 public void BeginSave()
990 {
991 BeginSave(null, null);
992 }
993
998 [Obsolete]
999 public void BeginSave(object userState)
1000 {
1001 BeginSave(null, userState);
1002 }
1003
1010 [Obsolete]
1011 public void BeginSave(EventHandler<SavedEventArgs> handler)
1012 {
1013 BeginSave(handler, null);
1014 }
1015
1023 [Obsolete]
1024 public async void BeginSave(EventHandler<SavedEventArgs> handler, object userState)
1025 {
1026 Exception error = null;
1027 T result = default(T);
1028 try
1029 {
1030 result = await SaveAsync(userState, false);
1031 }
1032 catch (AggregateException ex)
1033 {
1034 if (ex.InnerExceptions.Count > 0)
1035 error = ex.InnerExceptions[0];
1036 else
1037 error = ex;
1038 }
1039 catch (Exception ex)
1040 {
1041 error = ex;
1042 }
1043 if (handler != null)
1044 handler(result, new SavedEventArgs(result, error, userState));
1045 }
1046
1052 [EditorBrowsable(EditorBrowsableState.Advanced)]
1054 { }
1055
1061 [EditorBrowsable(EditorBrowsableState.Advanced)]
1063 { }
1064
1071 [EditorBrowsable(EditorBrowsableState.Advanced)]
1072 protected virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
1073 { }
1074
1080 [EditorBrowsable(EditorBrowsableState.Advanced)]
1082 { }
1083
1089 [EditorBrowsable(EditorBrowsableState.Advanced)]
1091 { }
1092
1099 [EditorBrowsable(EditorBrowsableState.Advanced)]
1100 protected virtual void Child_OnDataPortalException(DataPortalEventArgs e, Exception ex)
1101 { }
1102
1103 #endregion
1104
1105 #region ISavable Members
1106
1107 object Csla.Core.ISavable.Save()
1108 {
1109 return Save();
1110 }
1111
1112 object Csla.Core.ISavable.Save(bool forceUpdate)
1113 {
1114 return Save();
1115 }
1116
1117 async Task<object> ISavable.SaveAsync()
1118 {
1119 return await SaveAsync();
1120 }
1121
1122 async Task<object> ISavable.SaveAsync(bool forceUpdate)
1123 {
1124 return await SaveAsync();
1125 }
1126
1127 async Task ISavable.SaveAndMergeAsync(bool forceUpdate)
1128 {
1129 await SaveAndMergeAsync();
1130 }
1131
1132 [Obsolete]
1133 void ISavable.BeginSave()
1134 {
1135 BeginSave();
1136 }
1137
1138 void Csla.Core.ISavable.SaveComplete(object newObject)
1139 {
1140 OnSaved((T)newObject, null, null);
1141 }
1142
1143 T Csla.Core.ISavable<T>.Save(bool forceUpdate)
1144 {
1145 return Save();
1146 }
1147
1148 async Task<T> ISavable<T>.SaveAsync(bool forceUpdate)
1149 {
1150 return await SaveAsync();
1151 }
1152
1153 async Task ISavable<T>.SaveAndMergeAsync(bool forceUpdate)
1154 {
1155 await SaveAndMergeAsync();
1156 }
1157
1158 void Csla.Core.ISavable<T>.SaveComplete(T newObject)
1159 {
1160 OnSaved(newObject, null, null);
1161 }
1162
1163 [NonSerialized()]
1164 [NotUndoable]
1165 private EventHandler<Csla.Core.SavedEventArgs> _savedEvent;
1166
1170 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design",
1171 "CA1062:ValidateArgumentsOfPublicMethods")]
1172 public event EventHandler<Csla.Core.SavedEventArgs> Saved
1173 {
1174 add
1175 {
1176 _savedEvent = (EventHandler<Csla.Core.SavedEventArgs>)
1177 System.Delegate.Combine(_savedEvent, value);
1178 }
1179 remove
1180 {
1181 _savedEvent = (EventHandler<Csla.Core.SavedEventArgs>)
1182 System.Delegate.Remove(_savedEvent, value);
1183 }
1184 }
1185
1194 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1195 protected virtual void OnSaved(T newObject, Exception e, object userState)
1196 {
1197 Csla.Core.SavedEventArgs args = new Csla.Core.SavedEventArgs(newObject, e, userState);
1198 if (_savedEvent != null)
1199 _savedEvent.Invoke(this, args);
1200 }
1201 #endregion
1202
1203 #region Parent/Child link
1204
1205 [NotUndoable(), NonSerialized()]
1206 private Core.IParent _parent;
1207
1215 [Browsable(false)]
1216 [Display(AutoGenerateField=false)]
1217 [System.ComponentModel.DataAnnotations.ScaffoldColumn(false)]
1218 [EditorBrowsable(EditorBrowsableState.Advanced)]
1219 public Core.IParent Parent
1220 {
1221 get
1222 {
1223 return _parent;
1224 }
1225 }
1226
1233 protected virtual void SetParent(Core.IParent parent)
1234 {
1235 _parent = parent;
1236 _identityManager = null;
1237 InitializeIdentity();
1238 }
1239
1246 void Core.IEditableCollection.SetParent(Core.IParent parent)
1247 {
1248 this.SetParent(parent);
1249 }
1250
1251 #endregion
1252
1253 #region IDataPortalTarget Members
1254
1255 void IDataPortalTarget.CheckRules()
1256 { }
1257
1258 void IDataPortalTarget.MarkAsChild()
1259 {
1260 this.MarkAsChild();
1261 }
1262
1263 void IDataPortalTarget.MarkNew()
1264 { }
1265
1266 void IDataPortalTarget.MarkOld()
1267 { }
1268
1269 void IDataPortalTarget.DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
1270 {
1272 }
1273
1274 void IDataPortalTarget.DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
1275 {
1277 }
1278
1279 void IDataPortalTarget.DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
1280 {
1282 }
1283
1284 void IDataPortalTarget.Child_OnDataPortalInvoke(DataPortalEventArgs e)
1285 {
1287 }
1288
1289 void IDataPortalTarget.Child_OnDataPortalInvokeComplete(DataPortalEventArgs e)
1290 {
1292 }
1293
1294 void IDataPortalTarget.Child_OnDataPortalException(DataPortalEventArgs e, Exception ex)
1295 {
1296 this.Child_OnDataPortalException(e, ex);
1297 }
1298
1299 #endregion
1300
1301 }
1302}
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).
Definition: GraphMerger.cs:20
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().
Definition: MobileList.cs:29
virtual void OnSetChildren(SerializationInfo info, MobileFormatter formatter)
Override this method to manually deserialize child objects from data in the serialization stream.
Definition: MobileList.cs:117
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.
Definition: DataPortalT.cs:24
T Update(T obj)
Called by a factory method in a business class or by the UI to update an object.
Definition: DataPortalT.cs:715
static void UpdateChild(object child)
Inserts, updates or deletes an existing child business object.
Definition: DataPortal.cs:733
async Task< T > UpdateAsync(T obj)
Called by a factory method in a business class or by the UI to update an object.
Definition: DataPortalT.cs:773
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.
Serializes and deserializes objects at the field level.
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.
Definition: INotifyBusy.cs:17
Defines the interface that must be implemented by any business object that contains child objects.
Definition: IParent.cs:18
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.
Definition: IParent.cs:39
Specifies that the object can save itself.
Definition: ISavableT.cs:19
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.