CSLA.NET 6.0.0
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,
40 where T : BusinessListBase<T, C>
41 where C : Core.IEditableBusinessObject
42 {
46 protected BusinessListBase()
47 { }
48
52 protected ApplicationContext ApplicationContext { get; private set; }
53 ApplicationContext Core.IUseApplicationContext.ApplicationContext
54 {
55 get => ApplicationContext;
56 set
57 {
58 ApplicationContext = value;
59 InitializeIdentity();
60 Initialize();
61 AllowNew = true;
62 }
63 }
64
65 #region Initialize
66
72 protected virtual void Initialize()
73 { /* allows subclass to initialize events before any other activity occurs */ }
74
75 #endregion
76
77 #region Identity
78
79 private int _identity = -1;
80
82 {
83 get { return _identity; }
84 }
85
86 private void InitializeIdentity()
87 {
88 _identity = ((IParent)this).GetNextIdentity(_identity);
89 }
90
91 [NonSerialized]
92 [NotUndoable]
93 private IdentityManager _identityManager;
94
95 int IParent.GetNextIdentity(int current)
96 {
97 if (this.Parent != null)
98 {
99 return this.Parent.GetNextIdentity(current);
100 }
101 else
102 {
103 if (_identityManager == null)
104 _identityManager = new IdentityManager();
105 return _identityManager.GetNextIdentity(current);
106 }
107 }
108
109 #endregion
110
111 #region ICloneable
112
113 object ICloneable.Clone()
114 {
115 return GetClone();
116 }
117
122 [EditorBrowsable(EditorBrowsableState.Advanced)]
123 protected virtual object GetClone()
124 {
125 return Core.ObjectCloner.GetInstance(ApplicationContext).Clone(this);
126 }
127
132 public T Clone()
133 {
134 return (T)GetClone();
135 }
136
137 #endregion
138
139 #region Delete and Undelete child
140
141 private MobileList<C> _deletedList;
142
147 [System.Diagnostics.CodeAnalysis.SuppressMessage(
148 "Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
149 [EditorBrowsable(EditorBrowsableState.Advanced)]
151 {
152 get
153 {
154 if (_deletedList == null)
155 _deletedList = new MobileList<C>();
156 return _deletedList;
157 }
158 }
159
160 [System.Diagnostics.CodeAnalysis.SuppressMessage(
161 "Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
162 [EditorBrowsable(EditorBrowsableState.Advanced)]
163 IEnumerable<IEditableBusinessObject> IContainsDeletedList.DeletedList => (IEnumerable<IEditableBusinessObject>)DeletedList;
164
165 private void DeleteChild(C child)
166 {
167 // set child edit level
168 Core.UndoableBase.ResetChildEditLevel(child, this.EditLevel, false);
169
170 // mark the object as deleted
171 child.DeleteChild();
172 // and add it to the deleted collection for storage
173 DeletedList.Add(child);
174 }
175
176 private void UnDeleteChild(C child)
177 {
178 // since the object is no longer deleted, remove it from
179 // the deleted collection
180 DeletedList.Remove(child);
181
182 // we are inserting an _existing_ object so
183 // we need to preserve the object's editleveladded value
184 // because it will be changed by the normal add process
185 int saveLevel = child.EditLevelAdded;
186
187 Add(child);
188 child.EditLevelAdded = saveLevel;
189 }
190
196 [EditorBrowsable(EditorBrowsableState.Advanced)]
197 public bool ContainsDeleted(C item)
198 {
199 return DeletedList.Contains(item);
200 }
201
202 #endregion
203
204 #region Begin/Cancel/ApplyEdit
205
226 public void BeginEdit()
227 {
228 if (this.IsChild)
229 throw new NotSupportedException(Resources.NoBeginEditChildException);
230
231 CopyState(this.EditLevel + 1);
232 }
233
247 public void CancelEdit()
248 {
249 if (this.IsChild)
250 throw new NotSupportedException(Resources.NoCancelEditChildException);
251
252 UndoChanges(this.EditLevel - 1);
253 }
254
268 public void ApplyEdit()
269 {
270 if (this.IsChild)
271 throw new NotSupportedException(Resources.NoApplyEditChildException);
272
273 AcceptChanges(this.EditLevel - 1);
274 }
275
276 void Core.IParent.ApplyEditChild(Core.IEditableBusinessObject child)
277 {
278 EditChildComplete(child);
279 }
280
281 IParent Core.IParent.Parent
282 {
283 get { return this.Parent; }
284 }
285
292 protected virtual void EditChildComplete(Core.IEditableBusinessObject child)
293 {
294
295 // do nothing, we don't really care
296 // when a child has its edits applied
297 }
298
299 #endregion
300
301 #region Insert, Remove, Clear
302
307 protected override C AddNewCore()
308 {
310 var item = dp.CreateChild();
311 Add(item);
312 return item;
313 }
314
321 {
322 Remove((C)child);
323 }
324
326 {
327 return DeletedList;
328 }
329
335 void Core.IParent.RemoveChild(Csla.Core.IEditableBusinessObject child)
336 {
337 Remove((C)child);
338 }
339
345 protected override void InsertItem(int index, C item)
346 {
347 if (item.IsChild)
348 {
349 // set parent reference
350 item.SetParent(this);
351 // set child edit level
352 Core.UndoableBase.ResetChildEditLevel(item, this.EditLevel, false);
353 // when an object is inserted we assume it is
354 // a new object and so the edit level when it was
355 // added must be set
356 item.EditLevelAdded = _editLevel;
357 base.InsertItem(index, item);
358 }
359 else
360 {
361 // item must be marked as a child object
362 throw new InvalidOperationException(Resources.ListItemNotAChildException);
363 }
364 }
365
371 protected override void RemoveItem(int index)
372 {
373 // when an object is 'removed' it is really
374 // being deleted, so do the deletion work
375 C child = this[index];
376 using (LoadListMode)
377 {
378 base.RemoveItem(index);
379 }
380 if (!_completelyRemoveChild)
381 {
382 // the child shouldn't be completely removed,
383 // so copy it to the deleted list
384 DeleteChild(child);
385 }
387 OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, child, index));
388 }
389
401 protected override void SetItem(int index, C item)
402 {
403 C child = default(C);
404 if (!(ReferenceEquals((C)(this[index]), item)))
405 child = this[index];
406 // replace the original object with this new
407 // object
408 using (LoadListMode)
409 {
410 if (child != null)
411 DeleteChild(child);
412 }
413
414 // set parent reference
415 item.SetParent(this);
416 // set child edit level
417 Core.UndoableBase.ResetChildEditLevel(item, this.EditLevel, false);
418 // reset EditLevelAdded
419 item.EditLevelAdded = this.EditLevel;
420 // add to list and raise list changed as appropriate
421 base.SetItem(index, item);
422 }
423
428 protected override void ClearItems()
429 {
430 while (base.Count > 0) RemoveItem(0);
431 //DeferredLoadIndexIfNotLoaded();
432 //_indexSet.ClearIndexes();
433 //DeferredLoadPositionMapIfNotLoaded();
434 //_positionMap.ClearMap();
435 base.ClearItems();
436 }
437
438 #endregion
439
440 #region Edit level tracking
441
442 // keep track of how many edit levels we have
443 private int _editLevel;
444
448 [EditorBrowsable(EditorBrowsableState.Never)]
449 protected int EditLevel
450 {
451 get { return _editLevel; }
452 }
453
454 int Core.IUndoableObject.EditLevel
455 {
456 get
457 {
458 return this.EditLevel;
459 }
460 }
461
462 #endregion
463
464 #region N-level undo
465
466 void Core.IUndoableObject.CopyState(int parentEditLevel, bool parentBindingEdit)
467 {
468 if (!parentBindingEdit)
469 CopyState(parentEditLevel);
470 }
471
472 void Core.IUndoableObject.UndoChanges(int parentEditLevel, bool parentBindingEdit)
473 {
474 if (!parentBindingEdit)
475 UndoChanges(parentEditLevel);
476 }
477
478 void Core.IUndoableObject.AcceptChanges(int parentEditLevel, bool parentBindingEdit)
479 {
480 if (!parentBindingEdit)
481 AcceptChanges(parentEditLevel);
482 }
483
484 private void CopyState(int parentEditLevel)
485 {
486 if (this.EditLevel + 1 > parentEditLevel)
487 throw new UndoException(string.Format(Resources.EditLevelMismatchException, "CopyState"), this.GetType().Name, _parent != null ? _parent.GetType().Name : null, this.EditLevel, parentEditLevel - 1);
488
489 // we are going a level deeper in editing
490 _editLevel += 1;
491
492 // cascade the call to all child objects
493 for (int x = 0; x < this.Count; x++)
494 {
495 C child = this[x];
496 child.CopyState(_editLevel, false);
497 }
498
499 // cascade the call to all deleted child objects
500 foreach (C child in DeletedList)
501 child.CopyState(_editLevel, false);
502 }
503
504 private bool _completelyRemoveChild;
505
506 private void UndoChanges(int parentEditLevel)
507 {
508 C child;
509
510 if (this.EditLevel - 1 != parentEditLevel)
511 throw new UndoException(string.Format(Resources.EditLevelMismatchException, "UndoChanges"), this.GetType().Name, _parent != null ? _parent.GetType().Name : null, this.EditLevel, parentEditLevel + 1);
512
513 // we are coming up one edit level
514 _editLevel -= 1;
515 if (_editLevel < 0) _editLevel = 0;
516
517 using (LoadListMode)
518 {
519 try
520 {
521 // Cancel edit on all current items
522 for (int index = Count - 1; index >= 0; index--)
523 {
524 child = this[index];
525
526 //ACE: Important, make sure to remove the item prior to
527 // it going through undo, otherwise, it will
528 // incur a more expensive RemoveByReference operation
529 //DeferredLoadIndexIfNotLoaded();
530 //_indexSet.RemoveItem(child);
531
532 child.UndoChanges(_editLevel, false);
533
534 //ACE: Now that we have undone the changes, we can add the item
535 // back in the index.
536 //_indexSet.InsertItem(child);
537
538 // if item is below its point of addition, remove
539 if (child.EditLevelAdded > _editLevel)
540 {
541 bool oldAllowRemove = this.AllowRemove;
542 try
543 {
544 this.AllowRemove = true;
545 _completelyRemoveChild = true;
546 //RemoveIndexItem(child);
547 RemoveAt(index);
548 }
549 finally
550 {
551 _completelyRemoveChild = false;
552 this.AllowRemove = oldAllowRemove;
553 }
554 }
555 }
556
557 // cancel edit on all deleted items
558 for (int index = DeletedList.Count - 1; index >= 0; index--)
559 {
560 child = DeletedList[index];
561 child.UndoChanges(_editLevel, false);
562 if (child.EditLevelAdded > _editLevel)
563 {
564 // if item is below its point of addition, remove
565 DeletedList.RemoveAt(index);
566 }
567 else
568 {
569 // if item is no longer deleted move back to main list
570 if (!child.IsDeleted) UnDeleteChild(child);
571 }
572 }
573 }
574 finally
575 {
576 OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
577 }
578 }
579 }
580
581 private void AcceptChanges(int parentEditLevel)
582 {
583 if (this.EditLevel - 1 != parentEditLevel)
584 throw new UndoException(string.Format(Resources.EditLevelMismatchException, "AcceptChanges"), this.GetType().Name, _parent != null ? _parent.GetType().Name : null, this.EditLevel, parentEditLevel + 1);
585
586 // we are coming up one edit level
587 _editLevel -= 1;
588
589 // cascade the call to all child objects
590 foreach (C child in this)
591 {
592 child.AcceptChanges(_editLevel, false);
593 // if item is below its point of addition, lower point of addition
594 if (child.EditLevelAdded > _editLevel) child.EditLevelAdded = _editLevel;
595 }
596
597 // cascade the call to all deleted child objects
598 for (int index = DeletedList.Count - 1; index >= 0; index--)
599 {
600 C child = DeletedList[index];
601 child.AcceptChanges(_editLevel, false);
602 // if item is below its point of addition, remove
603 if (child.EditLevelAdded > _editLevel)
604 DeletedList.RemoveAt(index);
605 }
606
607 if (_editLevel < 0) _editLevel = 0;
608 }
609
610 #endregion
611
612 #region Mobile Object overrides
613
622 protected override void OnGetState(SerializationInfo info)
623 {
624 info.AddValue("Csla.BusinessListBase._isChild", _isChild);
625 info.AddValue("Csla.BusinessListBase._editLevel", _editLevel);
626 info.AddValue("Csla.Core.BusinessBase._identity", _identity);
627 base.OnGetState(info);
628 }
629
638 protected override void OnSetState(SerializationInfo info)
639 {
640 _isChild = info.GetValue<bool>("Csla.BusinessListBase._isChild");
641 _editLevel = info.GetValue<int>("Csla.BusinessListBase._editLevel");
642 _identity = info.GetValue<int>("Csla.Core.BusinessBase._identity");
643 base.OnSetState(info);
644 }
645
658 {
659 base.OnGetChildren(info, formatter);
660 if (_deletedList != null)
661 {
662 var fieldManagerInfo = formatter.SerializeObject(_deletedList);
663 info.AddChild("_deletedList", fieldManagerInfo.ReferenceId);
664 }
665 }
666
679 {
680 if (info.Children.ContainsKey("_deletedList"))
681 {
682 var childData = info.Children["_deletedList"];
683 _deletedList = (MobileList<C>)formatter.GetObject(childData.ReferenceId);
684 }
685 base.OnSetChildren(info, formatter);
686 }
687
688 #endregion
689
690 #region IsChild
691
692 [NotUndoable()]
693 private bool _isChild = false;
694
699 public bool IsChild
700 {
701 get { return _isChild; }
702 }
703
721 protected void MarkAsChild()
722 {
723 _identity = -1;
724 _isChild = true;
725 }
726
727 #endregion
728
729 #region IsDirty, IsValid, IsSavable
730
734 bool Core.ITrackStatus.IsSelfDirty
735 {
736 get { return IsDirty; }
737 }
738
742 public bool IsDirty
743 {
744 get
745 {
746 // any non-new deletions make us dirty
747 foreach (C item in DeletedList)
748 if (!item.IsNew)
749 return true;
750
751 // run through all the child objects
752 // and if any are dirty then then
753 // collection is dirty
754 foreach (C child in this)
755 if (child.IsDirty)
756 return true;
757 return false;
758 }
759 }
760
761 bool Core.ITrackStatus.IsSelfValid
762 {
763 get { return IsSelfValid; }
764 }
765
770 protected virtual bool IsSelfValid
771 {
772 get { return IsValid; }
773 }
774
779 public virtual bool IsValid
780 {
781 get
782 {
783 // run through all the child objects
784 // and if any are invalid then the
785 // collection is invalid
786 foreach (C child in this)
787 if (!child.IsValid)
788 return false;
789 return true;
790 }
791 }
792
797 public virtual bool IsSavable
798 {
799 get
800 {
801 bool auth = Csla.Rules.BusinessRules.HasPermission(ApplicationContext, Rules.AuthorizationActions.EditObject, this);
802 return (IsDirty && IsValid && auth && !IsBusy);
803 }
804 }
805
809 public override bool IsBusy
810 {
811 get
812 {
813 // run through all the child objects
814 // and if any are busy then then
815 // collection is busy
816 foreach (C item in DeletedList)
817 if (item.IsBusy)
818 return true;
819
820 foreach (C child in this)
821 if (child.IsBusy)
822 return true;
823
824 return false;
825 }
826 }
827
828 #endregion
829
830 #region ITrackStatus
831
832 bool Core.ITrackStatus.IsNew
833 {
834 get
835 {
836 return false;
837 }
838 }
839
840 bool Core.ITrackStatus.IsDeleted
841 {
842 get
843 {
844 return false;
845 }
846 }
847
848 #endregion
849
850 #region Serialization Notification
851
855 [EditorBrowsable(EditorBrowsableState.Advanced)]
856 protected override void OnDeserialized()
857 {
858 base.OnDeserialized();
859 foreach (Core.IEditableBusinessObject child in this)
860 child.SetParent(this);
861
862 foreach (Core.IEditableBusinessObject child in DeletedList)
863 child.SetParent(this);
864 }
865
866 #endregion
867
868 #region Child Data Access
869
874 [EditorBrowsable(EditorBrowsableState.Advanced)]
875 protected virtual void Child_Create()
876 { /* do nothing - list self-initializes */ }
877
887 [EditorBrowsable(EditorBrowsableState.Advanced)]
888 protected virtual void Child_Update(params object[] parameters)
889 {
890 using (LoadListMode)
891 {
893 foreach (var child in DeletedList)
894 dp.UpdateChild(child, parameters);
895 DeletedList.Clear();
896
897 foreach (var child in this)
898 if (child.IsDirty) dp.UpdateChild(child, parameters);
899 }
900 }
901
910 [EditorBrowsable(EditorBrowsableState.Advanced)]
911 [UpdateChild]
912 protected virtual async Task Child_UpdateAsync(params object[] parameters)
913 {
914 using (LoadListMode)
915 {
917 foreach (var child in DeletedList)
918 await dp.UpdateChildAsync(child, parameters).ConfigureAwait(false);
919 DeletedList.Clear();
920
921 foreach (var child in this)
922 if (child.IsDirty) await dp.UpdateChildAsync(child, parameters).ConfigureAwait(false);
923 }
924 }
925
926 #endregion
927
928 #region Data Access
929
957 public T Save()
958 {
959 try
960 {
961 return SaveAsync(null, true).Result;
962 }
963 catch (AggregateException ex)
964 {
965 if (ex.InnerExceptions.Count > 0)
966 throw ex.InnerExceptions[0];
967 else
968 throw;
969 }
970 }
971
975 public async Task<T> SaveAsync()
976 {
977 return await SaveAsync(null, false);
978 }
979
985 protected virtual async Task<T> SaveAsync(object userState, bool isSync)
986 {
987 T result;
988 if (this.IsChild)
989 throw new InvalidOperationException(Resources.NoSaveChildException);
990
991 if (_editLevel > 0)
992 throw new InvalidOperationException(Resources.NoSaveEditingException);
993
994 if (!IsValid)
995 throw new Rules.ValidationException(Resources.NoSaveInvalidException);
996
997 if (IsBusy)
998 throw new InvalidOperationException(Resources.BusyObjectsMayNotBeSaved);
999
1000 if (IsDirty)
1001 {
1003 if (isSync)
1004 {
1005 result = dp.Update((T)this);
1006 }
1007 else
1008 {
1009 result = await dp.UpdateAsync((T)this);
1010 }
1011 }
1012 else
1013 {
1014 result = (T)this;
1015 }
1016 OnSaved(result, null, userState);
1017 return result;
1018 }
1019
1025 public async Task SaveAndMergeAsync()
1026 {
1027 new GraphMerger(ApplicationContext).MergeBusinessListGraph<T, C>((T)this, await SaveAsync());
1028 }
1029
1035 [EditorBrowsable(EditorBrowsableState.Advanced)]
1037 { }
1038
1044 [EditorBrowsable(EditorBrowsableState.Advanced)]
1046 { }
1047
1054 [EditorBrowsable(EditorBrowsableState.Advanced)]
1055 protected virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
1056 { }
1057
1063 [EditorBrowsable(EditorBrowsableState.Advanced)]
1065 { }
1066
1072 [EditorBrowsable(EditorBrowsableState.Advanced)]
1074 { }
1075
1082 [EditorBrowsable(EditorBrowsableState.Advanced)]
1083 protected virtual void Child_OnDataPortalException(DataPortalEventArgs e, Exception ex)
1084 { }
1085
1086 #endregion
1087
1088 #region ISavable Members
1089
1090 object Csla.Core.ISavable.Save()
1091 {
1092 return Save();
1093 }
1094
1095 object Csla.Core.ISavable.Save(bool forceUpdate)
1096 {
1097 return Save();
1098 }
1099
1100 async Task<object> ISavable.SaveAsync()
1101 {
1102 return await SaveAsync();
1103 }
1104
1105 async Task<object> ISavable.SaveAsync(bool forceUpdate)
1106 {
1107 return await SaveAsync();
1108 }
1109
1110 async Task ISavable.SaveAndMergeAsync(bool forceUpdate)
1111 {
1112 await SaveAndMergeAsync();
1113 }
1114
1115 void Csla.Core.ISavable.SaveComplete(object newObject)
1116 {
1117 OnSaved((T)newObject, null, null);
1118 }
1119
1120 T Csla.Core.ISavable<T>.Save(bool forceUpdate)
1121 {
1122 return Save();
1123 }
1124
1125 async Task<T> ISavable<T>.SaveAsync(bool forceUpdate)
1126 {
1127 return await SaveAsync();
1128 }
1129
1130 async Task ISavable<T>.SaveAndMergeAsync(bool forceUpdate)
1131 {
1132 await SaveAndMergeAsync();
1133 }
1134
1135 void Csla.Core.ISavable<T>.SaveComplete(T newObject)
1136 {
1137 OnSaved(newObject, null, null);
1138 }
1139
1140 [NonSerialized()]
1141 [NotUndoable]
1142 private EventHandler<Csla.Core.SavedEventArgs> _savedEvent;
1143
1147 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design",
1148 "CA1062:ValidateArgumentsOfPublicMethods")]
1149 public event EventHandler<Csla.Core.SavedEventArgs> Saved
1150 {
1151 add
1152 {
1153 _savedEvent = (EventHandler<Csla.Core.SavedEventArgs>)
1154 System.Delegate.Combine(_savedEvent, value);
1155 }
1156 remove
1157 {
1158 _savedEvent = (EventHandler<Csla.Core.SavedEventArgs>)
1159 System.Delegate.Remove(_savedEvent, value);
1160 }
1161 }
1162
1171 [System.ComponentModel.EditorBrowsable(EditorBrowsableState.Advanced)]
1172 protected virtual void OnSaved(T newObject, Exception e, object userState)
1173 {
1174 Csla.Core.SavedEventArgs args = new Csla.Core.SavedEventArgs(newObject, e, userState);
1175 if (_savedEvent != null)
1176 _savedEvent.Invoke(this, args);
1177 }
1178 #endregion
1179
1180 #region Parent/Child link
1181
1182 [NotUndoable(), NonSerialized()]
1183 private Core.IParent _parent;
1184
1192 [Browsable(false)]
1193 [Display(AutoGenerateField=false)]
1194 [System.ComponentModel.DataAnnotations.ScaffoldColumn(false)]
1195 [EditorBrowsable(EditorBrowsableState.Advanced)]
1196 public Core.IParent Parent
1197 {
1198 get
1199 {
1200 return _parent;
1201 }
1202 }
1203
1210 protected virtual void SetParent(Core.IParent parent)
1211 {
1212 _parent = parent;
1213 _identityManager = null;
1214 InitializeIdentity();
1215 }
1216
1223 void Core.IEditableCollection.SetParent(Core.IParent parent)
1224 {
1225 this.SetParent(parent);
1226 }
1227
1228 #endregion
1229
1230 #region IDataPortalTarget Members
1231
1232 void IDataPortalTarget.CheckRules()
1233 { }
1234
1235 void IDataPortalTarget.MarkAsChild()
1236 {
1237 this.MarkAsChild();
1238 }
1239
1240 void IDataPortalTarget.MarkNew()
1241 { }
1242
1243 void IDataPortalTarget.MarkOld()
1244 { }
1245
1246 void IDataPortalTarget.DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
1247 {
1249 }
1250
1251 void IDataPortalTarget.DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
1252 {
1254 }
1255
1256 void IDataPortalTarget.DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
1257 {
1259 }
1260
1261 void IDataPortalTarget.Child_OnDataPortalInvoke(DataPortalEventArgs e)
1262 {
1264 }
1265
1266 void IDataPortalTarget.Child_OnDataPortalInvokeComplete(DataPortalEventArgs e)
1267 {
1269 }
1270
1271 void IDataPortalTarget.Child_OnDataPortalException(DataPortalEventArgs e, Exception ex)
1272 {
1273 this.Child_OnDataPortalException(e, ex);
1274 }
1275
1276 #endregion
1277
1278 }
1279}
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
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 type.
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.
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.
ApplicationContext ApplicationContext
Gets the current ApplicationContext
virtual async Task Child_UpdateAsync(params object[] parameters)
Asynchronously saves all items in the list, automatically performing insert, update or delete operati...
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.
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.
Client side data portal used for making asynchronous data portal calls in .NET.
Definition: DataPortalT.cs:24
T CreateChild()
Creates and initializes a new child business object.
Definition: DataPortalT.cs:639
async Task UpdateChildAsync(T child)
Inserts, updates or deletes an existing child business object.
Definition: DataPortalT.cs:779
void UpdateChild(T child)
Inserts, updates or deletes an existing child business object.
Definition: DataPortalT.cs:734
T Update(T obj)
Called by a factory method in a business class or by the UI to update an object.
Definition: DataPortalT.cs:467
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(ApplicationContext applicationContext, 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.
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.
Implement if a class requires access to the CSLA ApplicationContext type.
This is the base class from which most business collections or lists will be derived.
Defines an object that holds a list of deleted items.
IEnumerable< IEditableBusinessObject > DeletedList
List of deleted child objects
@ Serializable
Prevents updating or inserting until the transaction is complete.