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.
ObjectStatus.cs
Go to the documentation of this file.
1#if !NETFX_CORE && !XAMARIN
2//-----------------------------------------------------------------------
3// <copyright file="ObjectStatus.cs" company="Marimer LLC">
4// Copyright (c) Marimer LLC. All rights reserved.
5// Website: https://cslanet.com
6// </copyright>
7// <summary>Container for other UI controls that exposes</summary>
8//-----------------------------------------------------------------------
9using System;
10using System.Windows;
11using System.ComponentModel;
12using Csla.Core;
13
14namespace Csla.Xaml
15{
30 {
31#region Per-Type Dependency Properties
32
33 private static readonly DependencyProperty CanCreateProperty =
34 DependencyProperty.Register("CanCreateObject", typeof(bool), typeof(ObjectStatus), new FrameworkPropertyMetadata(false), null);
35 private static readonly DependencyProperty CanGetProperty =
36 DependencyProperty.Register("CanGetObject", typeof(bool), typeof(ObjectStatus), new FrameworkPropertyMetadata(false), null);
37 private static readonly DependencyProperty CanEditProperty =
38 DependencyProperty.Register("CanEditObject", typeof(bool), typeof(ObjectStatus), new FrameworkPropertyMetadata(false), null);
39 private static readonly DependencyProperty CanDeleteProperty =
40 DependencyProperty.Register("CanDeleteObject", typeof(bool), typeof(ObjectStatus), new FrameworkPropertyMetadata(false), null);
41
46 public bool CanCreateObject
47 {
48 get { return (bool)base.GetValue(CanCreateProperty); }
49 protected set
50 {
51 bool old = CanCreateObject;
52 base.SetValue(CanCreateProperty, value);
53 if (old != value)
54 OnPropertyChanged(
55 new DependencyPropertyChangedEventArgs(CanCreateProperty, old, value));
56 }
57 }
58
63 public bool CanGetObject
64 {
65 get { return (bool)base.GetValue(CanGetProperty); }
66 protected set
67 {
68 bool old = CanGetObject;
69 base.SetValue(CanGetProperty, value);
70 if (old != value)
71 OnPropertyChanged(
72 new DependencyPropertyChangedEventArgs(CanGetProperty, old, value));
73 }
74 }
75
80 public bool CanEditObject
81 {
82 get { return (bool)base.GetValue(CanEditProperty); }
83 protected set
84 {
85 bool old = CanEditObject;
86 base.SetValue(CanEditProperty, value);
87 if (old != value)
88 OnPropertyChanged(
89 new DependencyPropertyChangedEventArgs(CanEditProperty, old, value));
90 }
91 }
92
97 public bool CanDeleteObject
98 {
99 get { return (bool)base.GetValue(CanDeleteProperty); }
100 protected set
101 {
102 bool old = CanDeleteObject;
103 base.SetValue(CanDeleteProperty, value);
104 if (old != value)
105 OnPropertyChanged(
106 new DependencyPropertyChangedEventArgs(CanDeleteProperty, old, value));
107 }
108 }
109
110#endregion
111
112#region Per-Instance Dependency Properties
113
114 private static readonly DependencyProperty IsDeletedProperty =
115 DependencyProperty.Register("IsDeleted", typeof(bool), typeof(ObjectStatus), new FrameworkPropertyMetadata(false), null);
116 private static readonly DependencyProperty IsDirtyProperty =
117 DependencyProperty.Register("IsDirty", typeof(bool), typeof(ObjectStatus), new FrameworkPropertyMetadata(false), null);
118 private static readonly DependencyProperty IsNewProperty =
119 DependencyProperty.Register("IsNew", typeof(bool), typeof(ObjectStatus), new FrameworkPropertyMetadata(false), null);
120 private static readonly DependencyProperty IsSavableProperty =
121 DependencyProperty.Register("IsSavable", typeof(bool), typeof(ObjectStatus), new FrameworkPropertyMetadata(false), null);
122 private static readonly DependencyProperty IsValidProperty =
123 DependencyProperty.Register("IsValid", typeof(bool), typeof(ObjectStatus), new FrameworkPropertyMetadata(false), null);
124
129 public bool IsDeleted
130 {
131 get { return (bool)base.GetValue(IsDeletedProperty); }
132 protected set
133 {
134 bool old = IsDeleted;
135 base.SetValue(IsDeletedProperty, value);
136 OnPropertyChanged(
137 new DependencyPropertyChangedEventArgs(IsDeletedProperty, old, value));
138 }
139 }
140
145 public bool IsDirty
146 {
147 get { return (bool)base.GetValue(IsDirtyProperty); }
148 protected set
149 {
150 bool old = IsDirty;
151 base.SetValue(IsDirtyProperty, value);
152 if (old != value)
153 OnPropertyChanged(
154 new DependencyPropertyChangedEventArgs(IsDirtyProperty, old, value));
155 }
156 }
157
162 public bool IsNew
163 {
164 get { return (bool)base.GetValue(IsNewProperty); }
165 protected set
166 {
167 bool old = IsNew;
168 base.SetValue(IsNewProperty, value);
169 if (old != value)
170 OnPropertyChanged(
171 new DependencyPropertyChangedEventArgs(IsNewProperty, old, value));
172 }
173 }
174
179 public bool IsSavable
180 {
181 get { return (bool)base.GetValue(IsSavableProperty); }
182 protected set
183 {
184 bool old = IsSavable;
185 base.SetValue(IsSavableProperty, value);
186 if (old != value)
187 OnPropertyChanged(
188 new DependencyPropertyChangedEventArgs(IsSavableProperty, old, value));
189 }
190 }
191
196 public bool IsValid
197 {
198 get { return (bool)base.GetValue(IsValidProperty); }
199 protected set
200 {
201 bool old = IsValid;
202 base.SetValue(IsValidProperty, value);
203 if (old != value)
204 OnPropertyChanged(
205 new DependencyPropertyChangedEventArgs(IsValidProperty, old, value));
206 }
207 }
208
209#endregion
210
211#region Base Overrides
212
218 protected override void DataObjectChanged()
219 {
220 Refresh();
221 }
222
228 protected override void DataPropertyChanged(PropertyChangedEventArgs e)
229 {
230 Refresh();
231 }
232
239 protected override void DataBindingListChanged(ListChangedEventArgs e)
240 {
241 Refresh();
242 }
243
250 protected override void DataObservableCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
251 {
252 Refresh();
253 }
254
260 public void Refresh()
261 {
262 // per-type rules
263 if (DataObject != null)
264 {
265 Type sourceType = DataObject.GetType();
266 var newValue = Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.CreateObject, DataObject);
267 if (CanCreateObject != newValue)
268 CanCreateObject = newValue;
269 newValue = Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.GetObject, DataObject);
270 if (CanGetObject != newValue)
271 CanGetObject = newValue;
272 newValue = Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.EditObject, DataObject);
273 if (CanEditObject != newValue)
274 CanEditObject = newValue;
275 newValue = Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.DeleteObject, DataObject);
276 if (CanDeleteObject != newValue)
277 CanDeleteObject = newValue;
278 }
279 else
280 {
281 CanCreateObject = false;
282 CanGetObject = false;
283 CanEditObject = false;
284 CanDeleteObject = false;
285 }
286
288 if (source != null)
289 {
290 if (IsDeleted != source.IsDeleted)
291 IsDeleted = source.IsDeleted;
292 if (IsDirty != source.IsDirty)
293 IsDirty = source.IsDirty;
294 if (IsNew != source.IsNew)
295 IsNew = source.IsNew;
296 if (IsSavable != source.IsSavable)
297 IsSavable = source.IsSavable;
298 if (IsValid != source.IsValid)
299 IsValid = source.IsValid;
300 }
301 else
302 {
304 if (sourceList != null)
305 {
306 if (IsDirty != sourceList.IsDirty)
307 IsDirty = sourceList.IsDirty;
308 if (IsValid != sourceList.IsValid)
309 IsValid = sourceList.IsValid;
310 if (IsSavable != sourceList.IsSavable)
311 IsSavable = sourceList.IsSavable;
312 IsDeleted = false;
313 IsNew = false;
314 }
315 }
316 }
317
318#endregion
319 }
320}
321#endif
Tracks the business rules for a business object.
static bool HasPermission(AuthorizationActions action, Type objectType)
Checks per-type authorization rules.
Base class for creating WPF panel controls that react when the DataContext, data object and data prop...
object DataObject
Gets a reference to the current data object.
Container for other UI controls that exposes various status values from the CSLA ....
Definition: ObjectStatus.cs:30
override void DataObservableCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
This method is called if the data object is an INotifyCollectionChanged, and the CollectionChanged ev...
bool CanGetObject
Exposes the CanGetObject property of the DataContext business object.
Definition: ObjectStatus.cs:64
override void DataPropertyChanged(PropertyChangedEventArgs e)
This method is called when a property of the data object to which the control is bound has changed.
bool IsValid
Exposes the IsValid property of the DataContext business object.
void Refresh()
Refreshes the control's property values to reflect the values of the underlying business object.
override void DataObjectChanged()
This method is called when the data object to which the control is bound has changed.
bool CanCreateObject
Exposes the CanCreateObject property of the DataContext business object.
Definition: ObjectStatus.cs:47
bool CanEditObject
Exposes the CanEditObject property of the DataContext business object.
Definition: ObjectStatus.cs:81
override void DataBindingListChanged(ListChangedEventArgs e)
This method is called if the data object is an IBindingList, and the ListChanged event was raised by ...
bool IsDirty
Exposes the IsDirty property of the DataContext business object.
bool IsSavable
Exposes the IsSavable property of the DataContext business object.
bool IsDeleted
Exposes the IsDeleted property of the DataContext business object.
bool CanDeleteObject
Exposes the CanDeleteObject property of the DataContext business object.
Definition: ObjectStatus.cs:98
bool IsNew
Exposes the IsNew property of the DataContext business object.
Defines the common methods required by all editable CSLA single objects.
Defines the common methods required by all editable CSLA collection objects.
bool IsSavable
Returns true if this object is both dirty and valid.
bool IsDeleted
Returns true if this object is marked for deletion.
bool IsNew
Returns true if this is a new object, false if it is a pre-existing object.
bool IsValid
Returns true if the object and its child objects are currently valid, false if the object or any of i...
Definition: ITrackStatus.cs:37
bool IsDirty
Returns true if this object's data, or any of its fields or child objects data, has been changed.
Definition: ITrackStatus.cs:73