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.
DpRoot.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="DpRoot.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>no summary</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Text;
13
15{
16 [Serializable()]
17 public class DpRoot : BusinessBase<DpRoot>
18 {
19 private string _auth = "No value";
20
21 #region "Get/Set Private Variables"
22
23 public static PropertyInfo<string> DataProperty = RegisterProperty<string>(c => c.Data);
24 public string Data
25 {
26 get { return GetProperty(DataProperty); }
27 set { SetProperty(DataProperty, value); }
28 }
29
30 public string Auth
31 {
32 get
33 {
34 return _auth;
35 }
36
37 set
38 {
39 //Not allowed
40 }
41 }
42
43 #endregion
44
45 #region "Criteria class"
46
47 [Serializable()]
48 internal class Criteria : CriteriaBase<Criteria>
49 {
50 public static PropertyInfo<string> DataProperty = RegisterProperty<string>(c => c.Data);
51 public string Data
52 {
53 get { return ReadProperty(DataProperty); }
54 set { LoadProperty(DataProperty, value); }
55 }
56
57 public Criteria()
58 {
59 Data = "<new>";
60 }
61
62 public Criteria(string data)
63 {
64 Data = data;
65 }
66 }
67
68 #endregion
69
71 {
72 return this.Clone();
73 }
74
75
76 #region "DataPortal"
77
78 private void DataPortal_Create(object criteria)
79 {
80 Criteria crit = (Criteria)(criteria);
81 using (BypassPropertyChecks)
82 Data = crit.Data;
83 }
84
85 protected void DataPortal_Fetch(object criteria)
86 {
87 Criteria crit = (Criteria)(criteria);
88 using (BypassPropertyChecks)
89 Data = crit.Data;
90 MarkOld();
91 }
92
93 [Insert]
94 protected void DataPortal_Insert()
95 {
96 //we would insert here
97 }
98
99 [Update]
100 protected void DataPortal_Update()
101 {
102 //we would update here
103 }
104
105 [DeleteSelf]
106 protected void DataPortal_DeleteSelf()
107 {
108 //we would delete here
109 }
110
111 [Delete]
112 protected void DataPortal_Delete(object criteria)
113 {
114 //we would delete here
115 }
116
118 {
119 TestResults.Add("serverinvoke", "true");
120 }
121
123 {
124 TestResults.Add("serverinvokecomplete", "true");
125 }
126
127 #endregion
128
129 #region "Authorization Rules"
130
131 protected override void AddBusinessRules()
132 {
133 string role = "Admin";
134
135 BusinessRules.AddRule(new Csla.Rules.CommonRules.IsNotInRole(Rules.AuthorizationActions.ReadProperty, DenyReadOnPropertyProperty, new List<string> { role }));
136 BusinessRules.AddRule(new Csla.Rules.CommonRules.IsNotInRole(Rules.AuthorizationActions.WriteProperty, DenyWriteOnPropertyProperty, new List<string> { role }));
137
138 BusinessRules.AddRule(new Csla.Rules.CommonRules.IsNotInRole(Rules.AuthorizationActions.ReadProperty, DenyReadWriteOnPropertyProperty, new List<string> { role }));
139 BusinessRules.AddRule(new Csla.Rules.CommonRules.IsNotInRole(Rules.AuthorizationActions.WriteProperty, DenyReadWriteOnPropertyProperty, new List<string> { role }));
140
141 BusinessRules.AddRule(new Csla.Rules.CommonRules.IsInRole(Rules.AuthorizationActions.ReadProperty, AllowReadWriteOnPropertyProperty, new List<string> { role }));
142 BusinessRules.AddRule(new Csla.Rules.CommonRules.IsInRole(Rules.AuthorizationActions.WriteProperty, AllowReadWriteOnPropertyProperty, new List<string> { role }));
143 }
144
145 public static PropertyInfo<string> DenyReadOnPropertyProperty = RegisterProperty<string>(c => c.DenyReadOnProperty);
146 public string DenyReadOnProperty
147 {
148 get
149 {
150 if (CanReadProperty("DenyReadOnProperty"))
151 //return "Not allowed 1";
152 return ((TestHelpers.ApplicationContextManagerUnitTests)ApplicationContext.ContextManager).InstanceId.ToString();
153
154 else
155 return "[DenyReadOnProperty] Can't read property";
156 }
157
158 set
159 {
160 //Not allowed
161 }
162 }
163
164 public static PropertyInfo<string> DenyWriteOnPropertyProperty = RegisterProperty<string>(c => c.DenyWriteOnProperty);
166 {
167 get
168 {
169 return "<No Value>";
170 }
171
172 set
173 {
174 if (CanWriteProperty("DenyWriteOnProperty"))
175 throw new Csla.Security.SecurityException("Not allowed 2");
176
177 else
178 _auth = "[DenyWriteOnProperty] Can't write variable";
179
180 }
181 }
182
183 public static PropertyInfo<string> DenyReadWriteOnPropertyProperty = RegisterProperty<string>(c => c.DenyReadWriteOnProperty);
185 {
186 get
187 {
188 if (CanReadProperty("DenyReadWriteOnProperty"))
189 return "Not allowed 3";
190
191 else
192 return "[DenyReadWriteOnProperty] Can't read property";
193 }
194 set
195 {
196 if (CanWriteProperty("DenyReadWriteOnProperty"))
197 throw new Csla.Security.SecurityException("Not allowed 4");
198
199 else
200 _auth = "[DenyReadWriteOnProperty] Can't write variable";
201 }
202 }
203
204 public static PropertyInfo<string> AllowReadWriteOnPropertyProperty = RegisterProperty<string>(c => c.AllowReadWriteOnProperty);
206 {
207 get
208 {
209 if (CanReadProperty("AllowReadWriteOnProperty"))
210 return _auth;
211
212 else
213 return "Should be allowed 5";
214 }
215 set
216 {
217 if (CanWriteProperty("AllowReadWriteOnProperty"))
218 _auth = value;
219
220 else
221 throw new Csla.Security.SecurityException("Should be allowed 5");
222 }
223 }
224
225 #endregion
226 }
227}
Provides consistent context information between the client and server DataPortal objects.
IContextManager ContextManager
Gets the context manager responsible for storing user and context information for the application.
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
T Clone()
Creates a clone of the object.
Definition: BusinessBase.cs:79
Base type from which Criteria classes can be derived in a business class.
Definition: CriteriaBase.cs:25
Provides information about the DataPortal call.
Maintains metadata about a property.
IsInRole authorization rule.
IsNotInRole authorization rule.
static PropertyInfo< string > DataProperty
Definition: DpRoot.cs:23
void DataPortal_Fetch(object criteria)
Definition: DpRoot.cs:85
static PropertyInfo< string > AllowReadWriteOnPropertyProperty
Definition: DpRoot.cs:204
static PropertyInfo< string > DenyReadOnPropertyProperty
Definition: DpRoot.cs:145
override void AddBusinessRules()
Definition: DpRoot.cs:131
void DataPortal_Delete(object criteria)
Definition: DpRoot.cs:112
static PropertyInfo< string > DenyWriteOnPropertyProperty
Definition: DpRoot.cs:164
override void DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
Definition: DpRoot.cs:117
static PropertyInfo< string > DenyReadWriteOnPropertyProperty
Definition: DpRoot.cs:183
override void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
Definition: DpRoot.cs:122
Static dictionary-like class that offers similar functionality to GlobalContext This is used in tests...
Definition: TestResults.cs:21
static void Add(string key, string value)
Add an item to the test results, to indicate an outcome of a particular operation
Definition: TestResults.cs:29
@ Serializable
Prevents updating or inserting until the transaction is complete.
@ Update
Update operation (includes insert, update and delete self).
@ Delete
Delete operation.