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.
Csla.Xaml.Shared/ViewModelBase.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ViewModelBase.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Base class used to create ViewModel objects that</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections;
10using System.Collections.Generic;
11using System.Collections.Specialized;
12using System.ComponentModel;
13using System.ComponentModel.DataAnnotations;
14using System.Linq.Expressions;
15using System.Threading.Tasks;
16using System.Windows;
17using Csla.Core;
18using Csla.Reflection;
19using Csla.Rules;
20#if WINDOWS_UWP
21using Windows.UI.Xaml;
22#endif
23
24#if ANDROID
25namespace Csla.Axml
26#elif IOS
27namespace Csla.Iosui
28#else
29namespace Csla.Xaml
30#endif
31{
37#if ANDROID || IOS || XAMARIN
38 public abstract class ViewModelBase<T> : INotifyPropertyChanged, IViewModel
39#else
40 public abstract class ViewModelBase<T> : DependencyObject,
41 INotifyPropertyChanged, IViewModel
42#endif
43 {
48 protected ViewModelBase()
49 {
50 SetPropertiesAtObjectLevel();
51 }
52
53#region Obsolete Code
54
61 [Obsolete("Use RefreshAsync", false)]
62 public async Task<ViewModelBase<T>> InitAsync()
63 {
64 try
65 {
66 IsBusy = true;
67 Model = await DoInitAsync();
68 IsBusy = false;
69 }
70#pragma warning disable CA1031 // Do not catch general exception types
71 catch (Exception ex)
72 {
73 IsBusy = false;
74 this.Error = ex;
75 }
76#pragma warning restore CA1031 // Do not catch general exception types
77 return this;
78 }
79
80#pragma warning disable 1998
87 [Obsolete("Use RefreshAsync", false)]
88 protected async virtual Task<T> DoInitAsync()
89 {
90 throw new NotImplementedException("DoInitAsync");
91 }
92#pragma warning restore 1998
93
94 private Exception _error;
95
100 [Browsable(false)]
101 [Display(AutoGenerateField = false)]
102 [ScaffoldColumn(false)]
103 [Obsolete("Use RefreshAsync/SaveAsync", false)]
104 public Exception Error
105 {
106 get { return _error; }
107 protected set
108 {
109 if (!ReferenceEquals(_error, value))
110 {
111 _error = value;
112 OnPropertyChanged(nameof(Error));
113 if (_error != null)
114 OnError(_error);
115 }
116 }
117 }
118
122 [Obsolete("Use RefreshAsync/SaveAsync", false)]
123 public event EventHandler<ErrorEventArgs> ErrorOccurred;
124
130 [Obsolete("Use RefreshAsync/SaveAsync", false)]
131 protected virtual void OnError(Exception error)
132 {
133#if ANDROID || IOS
134 ErrorOccurred?.Invoke(this, new ErrorEventArgs(this, error));
135#else
136 ErrorOccurred?.Invoke(this, new ErrorEventArgs { Error = error });
137#endif
138 }
139
140#if !(ANDROID || IOS)
149 [Obsolete("Use RefreshAsync", false)]
150 protected virtual void DoRefresh(Func<T> factoryMethod)
151 {
152 if (typeof(T) != null)
153 {
154 OnRefreshing(Model);
155 Error = null;
156 try
157 {
158 Model = factoryMethod.Invoke();
159 }
160#pragma warning disable CA1031 // Do not catch general exception types
161 catch (Exception ex)
162 {
163 Error = ex;
164 }
165#pragma warning restore CA1031 // Do not catch general exception types
166 OnRefreshed();
167 }
168 }
169
176 [Obsolete("Use RefreshAsync", false)]
177 protected virtual void DoRefresh(string factoryMethod, params object[] factoryParameters)
178 {
179 if (typeof(T) != null)
180 {
181 OnRefreshing(Model);
182 Error = null;
183 try
184 {
185 Model = (T)MethodCaller.CallFactoryMethod(typeof(T), factoryMethod, factoryParameters);
186 }
187#pragma warning disable CA1031 // Do not catch general exception types
188 catch (Exception ex)
189 {
190 Error = ex;
191 }
192#pragma warning restore CA1031 // Do not catch general exception types
193 OnRefreshed();
194 }
195 }
196
202 [Obsolete("Use RefreshAsync", false)]
203 protected virtual void DoRefresh(string factoryMethod)
204 {
205 DoRefresh(factoryMethod, Array.Empty<object>());
206 }
207#endif
208
217 [Obsolete("Use RefreshAsync", false)]
218 protected virtual void BeginRefresh(Action<EventHandler<DataPortalResult<T>>> factoryMethod)
219 {
220 if (typeof(T) != null)
221 try
222 {
223 Error = null;
224 IsBusy = true;
225
226 var handler = (EventHandler<DataPortalResult<T>>)CreateHandler(typeof(T));
227 factoryMethod(handler);
228 }
229#pragma warning disable CA1031 // Do not catch general exception types
230 catch (Exception ex)
231 {
232 Error = ex;
233 IsBusy = false;
234 }
235#pragma warning restore CA1031 // Do not catch general exception types
236 }
237
244 [Obsolete("Use RefreshAsync", false)]
245 protected virtual void BeginRefresh(string factoryMethod, params object[] factoryParameters)
246 {
247 if (typeof(T) != null)
248 try
249 {
250 Error = null;
251 IsBusy = true;
252 var parameters = new List<object>(factoryParameters)
253 {
254 CreateHandler(typeof(T))
255 };
256
257 MethodCaller.CallFactoryMethod(typeof(T), factoryMethod, parameters.ToArray());
258 }
259#pragma warning disable CA1031 // Do not catch general exception types
260 catch (Exception ex)
261 {
262 Error = ex;
263 IsBusy = false;
264 }
265#pragma warning restore CA1031 // Do not catch general exception types
266 }
267
273 [Obsolete("Use RefreshAsync", false)]
274 protected virtual void BeginRefresh(string factoryMethod)
275 {
276 BeginRefresh(factoryMethod, Array.Empty<object>());
277 }
278
279 private Delegate CreateHandler(Type objectType)
280 {
281 System.Reflection.MethodInfo method = MethodCaller.GetMethod(GetType(), "QueryCompleted");
282 var innerType = typeof(DataPortalResult<>).MakeGenericType(objectType);
283 var args = typeof(EventHandler<>).MakeGenericType(innerType);
284
285 Delegate handler = Delegate.CreateDelegate(args, this, method);
286 return handler;
287 }
288
289 [Obsolete("Use RefreshAsync", false)]
290 private void QueryCompleted(object sender, EventArgs e)
291 {
292 try
293 {
294 var eventArgs = (IDataPortalResult)e;
295 if (eventArgs.Error == null)
296 {
297 var model = (T)eventArgs.Object;
298 OnRefreshing(model);
299 Model = model;
300 }
301 else
302 Error = eventArgs.Error;
303 OnRefreshed();
304 }
305 finally
306 {
307 IsBusy = false;
308 }
309 }
310
316 [Obsolete("Use RefreshAsync", false)]
317 protected virtual void OnRefreshing(T model)
318 { }
319
324 [Obsolete("Use RefreshAsync", false)]
325 protected virtual void OnRefreshed()
326 { }
327
332 [Obsolete("Use SaveAsync", false)]
333 protected virtual T DoSave()
334 {
335 T result = (T)Model;
336 Error = null;
337 try
338 {
339 UnhookChangedEvents(Model);
340 var savable = Model as Csla.Core.ISavable;
341 if (ManageObjectLifetime)
342 {
343 // clone the object if possible
344 if (Model is ICloneable clonable)
345 savable = (Csla.Core.ISavable)clonable.Clone();
346
347 //apply changes
348 if (savable is Csla.Core.ISupportUndo undoable)
349 undoable.ApplyEdit();
350 }
351
352 result = (T)savable.Save();
353
354 Model = result;
355 OnSaved();
356 }
357 catch (Exception ex)
358 {
359 HookChangedEvents(Model);
360 Error = ex;
361 OnSaved();
362 }
363 return result;
364 }
365
370 [Obsolete("Use SaveAsync", false)]
371 protected virtual void BeginSave()
372 {
373 try
374 {
375 var savable = Model as Csla.Core.ISavable;
376 if (ManageObjectLifetime)
377 {
378 // clone the object if possible
379 if (Model is ICloneable clonable)
380 savable = (Csla.Core.ISavable)clonable.Clone();
381
382 //apply changes
383 if (savable is Csla.Core.ISupportUndo undoable)
384 undoable.ApplyEdit();
385 }
386
387 savable.Saved += (o, e) =>
388 {
389 IsBusy = false;
390 if (e.Error == null)
391 {
392 var result = e.NewObject;
393 var model = (T)result;
394 OnSaving(model);
395 Model = model;
396 }
397 else
398 {
399 Error = e.Error;
400 }
401 OnSaved();
402 };
403 Error = null;
404 IsBusy = true;
405 savable.BeginSave();
406 }
407#pragma warning disable CA1031 // Do not catch general exception types
408 catch (Exception ex)
409 {
410 IsBusy = false;
411 Error = ex;
412 OnSaved();
413 }
414#pragma warning restore CA1031 // Do not catch general exception types
415 }
416
422 [Obsolete("Use SaveAsync", false)]
423 protected virtual void OnSaving(T model)
424 { }
425
431 [Obsolete("Use SaveAsync", false)]
432 protected virtual void OnSaved()
433 { }
434
435 #endregion
436
437#if ANDROID || IOS || XAMARIN || WINDOWS_UWP
438 private T _model;
442 public T Model
443 {
444 get { return _model; }
445 set
446 {
447 if (!ReferenceEquals(value, _model))
448 {
449 var oldValue = _model;
450 _model = value;
451 this.OnModelChanged((T)oldValue, _model);
452 OnPropertyChanged(nameof(Model));
453 }
454 }
455 }
456#else
460 public static readonly DependencyProperty ModelProperty =
461 DependencyProperty.Register("Model", typeof(T), typeof(ViewModelBase<T>),
462 new PropertyMetadata((o, e) =>
463 {
464 var viewmodel = (ViewModelBase<T>)o;
465 viewmodel.OnModelChanged((T)e.OldValue, (T)e.NewValue);
466 }));
467
471 public T Model
472 {
473 get { return (T)GetValue(ModelProperty); }
474 set { SetValue(ModelProperty, value); }
475 }
476#endif
477
483#if ANDROID || IOS || XAMARIN
484 public bool ManageObjectLifetimeProperty;
485#else
486 public static readonly DependencyProperty ManageObjectLifetimeProperty =
487 DependencyProperty.Register("ManageObjectLifetime", typeof(bool),
488 typeof(ViewModelBase<T>), new PropertyMetadata(true));
489#endif
495 [Browsable(false)]
496 [Display(AutoGenerateField = false)]
497 [ScaffoldColumn(false)]
498 public bool ManageObjectLifetime
499 {
500#if ANDROID || IOS || XAMARIN
501 get { return (bool)ManageObjectLifetimeProperty; }
502 set { ManageObjectLifetimeProperty = value; }
503#else
504 get { return (bool)GetValue(ManageObjectLifetimeProperty); }
505 set { SetValue(ManageObjectLifetimeProperty, value); }
506#endif
507 }
508
509 private bool _isBusy;
510
515 public bool IsBusy
516 {
517 get { return _isBusy; }
518 protected set
519 {
520 if (value != _isBusy)
521 {
522 _isBusy = value;
523 OnPropertyChanged(nameof(IsBusy));
524 OnSetProperties();
525 }
526 }
527 }
528
529 private bool _isDirty;
530
535 public virtual bool IsDirty
536 {
537 get
538 {
539 return _isDirty;
540 }
541 protected set
542 {
543 if (_isDirty != value)
544 {
545 _isDirty = value;
546 OnPropertyChanged(nameof(IsDirty));
547 }
548 }
549 }
550
551 private bool _isValid;
552
557 public virtual bool IsValid
558 {
559 get
560 {
561 return _isValid;
562 }
563 protected set
564 {
565 if (_isValid != value)
566 {
567 _isValid = value;
568 OnPropertyChanged(nameof(IsValid));
569 }
570 }
571 }
572
573 private bool _canSave = false;
574
579 public virtual bool CanSave
580 {
581 get
582 {
583 return _canSave;
584 }
585 protected set
586 {
587 if (_canSave != value)
588 {
589 _canSave = value;
590 OnPropertyChanged(nameof(CanSave));
591 }
592 }
593 }
594
595 private bool _canCancel = false;
596
601 public virtual bool CanCancel
602 {
603 get
604 {
605 return _canCancel;
606 }
607 protected set
608 {
609 if (_canCancel != value)
610 {
611 _canCancel = value;
612 OnPropertyChanged(nameof(CanCancel));
613 }
614 }
615 }
616
617 private bool _canCreate = false;
618
624 public virtual bool CanCreate
625 {
626 get
627 {
628 return _canCreate;
629 }
630 protected set
631 {
632 if (_canCreate != value)
633 {
634 _canCreate = value;
635 OnPropertyChanged(nameof(CanCreate));
636 }
637 }
638 }
639
640 private bool _canDelete = false;
641
646 public virtual bool CanDelete
647 {
648 get
649 {
650 return _canDelete;
651 }
652 protected set
653 {
654 if (_canDelete != value)
655 {
656 _canDelete = value;
657 OnPropertyChanged(nameof(CanDelete));
658 }
659 }
660 }
661
662 private bool _canFetch = false;
663
669 public virtual bool CanFetch
670 {
671 get
672 {
673 return _canFetch;
674 }
675 protected set
676 {
677 if (_canFetch != value)
678 {
679 _canFetch = value;
680 OnPropertyChanged(nameof(CanFetch));
681 }
682 }
683 }
684
685 private bool _canRemove = false;
686
691 public virtual bool CanRemove
692 {
693 get
694 {
695 return _canRemove;
696 }
697 protected set
698 {
699 if (_canRemove != value)
700 {
701 _canRemove = value;
702 OnPropertyChanged(nameof(CanRemove));
703 }
704 }
705 }
706
707 private bool _canAddNew = false;
708
713 public virtual bool CanAddNew
714 {
715 get
716 {
717 return _canAddNew;
718 }
719 protected set
720 {
721 if (_canAddNew != value)
722 {
723 _canAddNew = value;
724 OnPropertyChanged(nameof(CanAddNew));
725 }
726 }
727 }
728
729 private void SetProperties()
730 {
731 bool isObjectBusy = false;
732 if (Model is INotifyBusy busyObject && busyObject.IsBusy)
733 isObjectBusy = true;
734
735 // Does Model instance implement ITrackStatus
736 if (Model is ITrackStatus targetObject)
737 {
738 var canDeleteInstance = BusinessRules.HasPermission(AuthorizationActions.DeleteObject, targetObject);
739
740 IsDirty = targetObject.IsDirty;
741 IsValid = targetObject.IsValid;
742 CanSave = CanEditObject && targetObject.IsSavable && !isObjectBusy;
743 CanCancel = CanEditObject && targetObject.IsDirty && !isObjectBusy;
744 CanCreate = CanCreateObject && !targetObject.IsDirty && !isObjectBusy;
745 CanDelete = CanDeleteObject && !isObjectBusy && canDeleteInstance;
746 CanFetch = CanGetObject && !targetObject.IsDirty && !isObjectBusy;
747
748 // Set properties for List
749 if (Model is ICollection list)
750 {
751 Type itemType = Utilities.GetChildItemType(Model.GetType());
752 if (itemType == null)
753 {
754 CanAddNew = false;
755 CanRemove = false;
756 }
757 else
758 {
759 CanRemove = BusinessRules.HasPermission(AuthorizationActions.DeleteObject, itemType) &&
760 list.Count > 0 && !isObjectBusy;
761 CanAddNew = BusinessRules.HasPermission(AuthorizationActions.CreateObject, itemType) &&
762 !isObjectBusy;
763 }
764 }
765 else
766 {
767 CanRemove = false;
768 CanAddNew = false;
769 }
770 }
771
772 // Else if Model instance implement ICollection
773 else if (Model is ICollection list)
774 {
775 Type itemType = Utilities.GetChildItemType(Model.GetType());
776 if (itemType == null)
777 {
778 CanAddNew = false;
779 CanRemove = false;
780 }
781 else
782 {
783 CanRemove = BusinessRules.HasPermission(AuthorizationActions.DeleteObject, itemType) &&
784 list.Count > 0 && !isObjectBusy;
785 CanAddNew = BusinessRules.HasPermission(AuthorizationActions.CreateObject, itemType) &&
786 !isObjectBusy;
787 }
788 }
789 else
790 {
791 IsDirty = false;
792 IsValid = false;
793 CanCancel = false;
794 CanCreate = CanCreateObject;
795 CanDelete = false;
796 CanFetch = CanGetObject && !IsBusy;
797 CanSave = false;
798 CanRemove = false;
799 CanAddNew = false;
800 }
801 }
802
803 private bool _canCreateObject;
804
809 public virtual bool CanCreateObject
810 {
811 get { return _canCreateObject; }
812 protected set
813 {
814 if (_canCreateObject != value)
815 {
816 _canCreateObject = value;
817 OnPropertyChanged(nameof(CanCreateObject));
818 }
819 }
820 }
821
822 private bool _canGetObject;
823
828 public virtual bool CanGetObject
829 {
830 get { return _canGetObject; }
831 protected set
832 {
833 if (_canGetObject != value)
834 {
835 _canGetObject = value;
836 OnPropertyChanged(nameof(CanGetObject));
837 }
838 }
839 }
840
841 private bool _canEditObject;
842
848 public virtual bool CanEditObject
849 {
850 get { return _canEditObject; }
851 protected set
852 {
853 if (_canEditObject != value)
854 {
855 _canEditObject = value;
856 OnPropertyChanged(nameof(CanEditObject));
857 }
858 }
859 }
860
861 private bool _canDeleteObject;
862
868 public virtual bool CanDeleteObject
869 {
870 get { return _canDeleteObject; }
871 protected set
872 {
873 if (_canDeleteObject != value)
874 {
875 _canDeleteObject = value;
876 OnPropertyChanged(nameof(CanDeleteObject));
877 }
878 }
879 }
880
885 private void SetPropertiesAtObjectLevel()
886 {
887 Type sourceType = typeof(T);
888
889 CanCreateObject = BusinessRules.HasPermission(Rules.AuthorizationActions.CreateObject, sourceType);
890 CanGetObject = BusinessRules.HasPermission(Rules.AuthorizationActions.GetObject, sourceType);
891 CanEditObject = BusinessRules.HasPermission(Rules.AuthorizationActions.EditObject, sourceType);
892 CanDeleteObject = BusinessRules.HasPermission(Rules.AuthorizationActions.DeleteObject, sourceType);
893
894 // call SetProperties to set "instance" values
895 OnSetProperties();
896 }
897
903 protected virtual async Task<T> RefreshAsync<F>(Func<Task<T>> factory)
904 {
905 T result = default;
906 try
907 {
908 IsBusy = true;
909 result = await factory.Invoke();
910 Model = result;
911 }
912 finally
913 {
914 IsBusy = false;
915 }
916 return result;
917 }
918
923 protected virtual async Task<T> SaveAsync()
924 {
925 try
926 {
927 UnhookChangedEvents(Model);
928 var savable = Model as ISavable;
929 if (ManageObjectLifetime)
930 {
931 // clone the object if possible
932 if (Model is ICloneable clonable)
933 savable = (ISavable)clonable.Clone();
934
935 //apply changes
936 if (savable is ISupportUndo undoable)
937 undoable.ApplyEdit();
938 }
939
940 IsBusy = true;
941 Model = (T) await savable.SaveAsync();
942 }
943 finally
944 {
945 HookChangedEvents(Model);
946 IsBusy = false;
947 }
948 return Model;
949 }
950
955 protected virtual void DoCancel()
956 {
957 if (ManageObjectLifetime)
958 {
959 if (Model is ISupportUndo undo)
960 {
961 UnhookChangedEvents(Model);
962 try
963 {
964 undo.CancelEdit();
965 undo.BeginEdit();
966 }
967 finally
968 {
969 HookChangedEvents(Model);
970 OnSetProperties();
971 }
972 }
973 }
974 }
975
976#if (ANDROID || IOS) || XAMARIN
981 protected virtual void BeginAddNew()
982 {
983#if ANDROID || IOS
984 var ibl = (Model as System.ComponentModel.IBindingList);
985#else
986 var ibl = (Model as IBindingList);
987#endif
988 if (ibl != null)
989 {
990 ibl.AddNew();
991 }
992 else
993 {
994 // else try to use as IObservableBindingList
995 var iobl = ((IObservableBindingList)Model);
996 iobl.AddNew();
997 }
998 OnSetProperties();
999 }
1000#else
1005 protected virtual object DoAddNew()
1006 {
1007 object result;
1008 // typically use ObserableCollection
1009 if (Model is IObservableBindingList iobl)
1010 {
1011 result = iobl.AddNew();
1012 }
1013 else
1014 {
1015 // else try to use as BindingList
1016 var ibl = ((IBindingList)Model);
1017 result = ibl.AddNew();
1018 }
1019 OnSetProperties();
1020 return result;
1021 }
1022#endif
1023
1028 protected virtual void DoRemove(object item)
1029 {
1030 ((IList)Model).Remove(item);
1031 OnSetProperties();
1032 }
1033
1038 protected virtual void DoDelete()
1039 {
1040 ((IEditableBusinessObject)Model).Delete();
1041 }
1042
1050 protected virtual void OnModelChanged(T oldValue, T newValue)
1051 {
1052 if (ReferenceEquals(oldValue, newValue)) return;
1053
1054 if (ManageObjectLifetime && newValue is ISupportUndo undo)
1055 undo.BeginEdit();
1056
1057 // unhook events from old value
1058 if (oldValue != null)
1059 {
1060 UnhookChangedEvents(oldValue);
1061
1062 if (oldValue is INotifyBusy nb)
1063 nb.BusyChanged -= Model_BusyChanged;
1064 }
1065
1066 // hook events on new value
1067 if (newValue != null)
1068 {
1069 HookChangedEvents(newValue);
1070
1071 if (newValue is INotifyBusy nb)
1072 nb.BusyChanged += Model_BusyChanged;
1073 }
1074
1075 OnSetProperties();
1076 }
1077
1082 protected void UnhookChangedEvents(T model)
1083 {
1084 if (model is INotifyPropertyChanged npc)
1085 npc.PropertyChanged -= Model_PropertyChanged;
1086
1087 if (model is INotifyChildChanged ncc)
1088 ncc.ChildChanged -= Model_ChildChanged;
1089
1090 if (model is INotifyCollectionChanged cc)
1091 cc.CollectionChanged -= Model_CollectionChanged;
1092 }
1093
1098 private void HookChangedEvents(T model)
1099 {
1100 if (model is INotifyPropertyChanged npc)
1101 npc.PropertyChanged += Model_PropertyChanged;
1102
1103 if (model is INotifyChildChanged ncc)
1104 ncc.ChildChanged += Model_ChildChanged;
1105
1106 if (model is INotifyCollectionChanged cc)
1107 cc.CollectionChanged += Model_CollectionChanged;
1108 }
1109
1114 protected virtual void OnSetProperties()
1115 {
1116 SetProperties();
1117 }
1118
1119 private void Model_BusyChanged(object sender, BusyChangedEventArgs e)
1120 {
1121 // only set busy state for entire object. Ignore busy state based
1122 // on asynch rules being active
1123 if (string.IsNullOrEmpty(e.PropertyName))
1124 IsBusy = e.Busy;
1125 else
1126 OnSetProperties();
1127 }
1128
1129 private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
1130 {
1131 OnSetProperties();
1132 }
1133
1134 private void Model_ChildChanged(object sender, ChildChangedEventArgs e)
1135 {
1136 OnSetProperties();
1137 }
1138
1139 private void Model_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
1140 {
1141 OnSetProperties();
1142 }
1143
1144 object IViewModel.Model
1145 {
1146 get { return Model; }
1147 set { Model = (T)value; }
1148 }
1149
1153 public event PropertyChangedEventHandler PropertyChanged;
1154
1159 protected virtual void OnPropertyChanged(string propertyName)
1160 {
1161 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
1162 }
1163 }
1164}
Event arguments for the BusyChanged event.
string PropertyName
Property for which the Busy value has changed.
Contains event data about the changed child object.
DataPortalResult defines the results of DataPortal operation.
Tracks the business rules for a business object.
static bool HasPermission(AuthorizationActions action, Type objectType)
Checks per-type authorization rules.
Contains information about the error that has occurred.
Base class used to create ViewModel objects that implement their own commands/verbs/actions.
virtual void DoRemove(object item)
Removes an item from the Model (if it is a collection).
PropertyChangedEventHandler PropertyChanged
Event raised when a property changes.
virtual void OnModelChanged(T oldValue, T newValue)
Invoked when the Model changes, allowing event handlers to be unhooked from the old object and hooked...
virtual void BeginSave()
Saves the Model, first committing changes if ManagedObjectLifetime is true.
virtual void OnSetProperties()
Override this method to hook into to logic of setting properties when model is changed or edited.
virtual void DoCancel()
Cancels changes made to the model if ManagedObjectLifetime is true.
virtual void DoDelete()
Marks the Model for deletion (if it is an editable root object).
virtual void OnRefreshed()
Method called after a refresh operation has completed.
virtual void OnSaving(T model)
Method called after a save operation has completed and before Model is updated (when successful).
virtual T DoSave()
Saves the Model, first committing changes if ManagedObjectLifetime is true.
virtual void DoRefresh(Func< T > factoryMethod)
Creates or retrieves a new instance of the Model by invoking a static factory method.
virtual void OnError(Exception error)
Raises ErrorOccurred event when an error occurs during processing.
void UnhookChangedEvents(T model)
Unhooks changed event handlers from the model.
virtual void OnSaved()
Method called after a save operation has completed (whether successful or not).
async Task< ViewModelBase< T > > InitAsync()
Method used to perform async initialization of the viewmodel.
virtual void DoRefresh(string factoryMethod, params object[] factoryParameters)
Creates or retrieves a new instance of the Model by invoking a static factory method.
ViewModelBase()
Create new instance of base class used to create ViewModel objects that implement their own commands/...
virtual void BeginRefresh(Action< EventHandler< DataPortalResult< T > > > factoryMethod)
Creates or retrieves a new instance of the Model by invoking a static factory method.
EventHandler< ErrorEventArgs > ErrorOccurred
Event raised when an error occurs during processing.
virtual async Task< T > SaveAsync()
Saves the Model, first committing changes if ManagedObjectLifetime is true.
virtual void OnRefreshing(T model)
Method called after a refresh operation has completed and before the model is updated.
virtual void DoRefresh(string factoryMethod)
Creates or retrieves a new instance of the Model by invoking a static factory method.
virtual void BeginRefresh(string factoryMethod)
Creates or retrieves a new instance of the Model by invoking a static factory method.
virtual void BeginRefresh(string factoryMethod, params object[] factoryParameters)
Creates or retrieves a new instance of the Model by invoking a static factory method.
virtual object DoAddNew()
Adds a new item to the Model (if it is a collection).
virtual void OnPropertyChanged(string propertyName)
Raise the PropertyChanged event.
virtual async Task< T > DoInitAsync()
Override this method to implement async initialization of the model object.
Defines the common methods required by all editable CSLA single objects.
Interface defining an object that notifies when it is busy executing an asynchronous operation.
Definition: INotifyBusy.cs:17
bool IsBusy
Gets a value indicating whether the object, or any of the object's child objects, are busy running an...
Definition: INotifyBusy.cs:29
Implemented by classes that notify when a child object has changed.
Defines additional elements for an ObservableCollection as required by CSLA .NET.
Specifies that the object can save itself.
Definition: ISavableT.cs:19
EventHandler< SavedEventArgs > Saved
Event raised when an object has been saved.
Definition: ISavable.cs:81
object Save()
Saves the object to the database.
Task< object > SaveAsync()
Saves the object to the database.
Define the common methods used by the UI to interact with n-level undo.
Definition: ISupportUndo.cs:25
Defines the common properties required objects that track their own status.
Definition: ITrackStatus.cs:17
IDataPortalResult defines the results of DataPortal operation
Defines a CSLA .NET viewmodel object.
AuthorizationActions
Authorization actions.
@ Error
Represents a serious business rule violation that should cause an object to be considered invalid.
@ PropertyChanged
Called from PropertyHasChanged event on BO but not including cascade calls by AffectedProperties