-
Notifications
You must be signed in to change notification settings - Fork 0
/
Application.cs
312 lines (265 loc) · 7.71 KB
/
Application.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AzAlternative
{
/// <summary>
/// An application in the store
/// </summary>
public class Application : ContainerBase, Interfaces.IApplication
{
private readonly Interfaces.IApplication Instance;
public override Application Parent
{
get { return null; }
internal set
{
BaseApplication = value;
Groups.Application = value;
Operations.Application = value;
Tasks.Application = value;
}
}
/// <summary>
/// Gets the application identifier
/// </summary>
public override string Key
{
get { return Instance.Key; }
}
/// <summary>
/// Gets or sets the application name
/// </summary>
public override string Name
{
get { return Instance.Name; }
set
{
if (string.IsNullOrEmpty(value))
throw new ArgumentNullException("Name");
Instance.Name = value;
}
}
/// <summary>
/// Gets or sets the description
/// </summary>
public string Description
{
get { return Instance.Description; }
set { Instance.Description = value; }
}
/// <summary>
/// Gets or sets the application version
/// </summary>
public string ApplicationVersion
{
get { return Instance.ApplicationVersion; }
set { Instance.ApplicationVersion = value; }
}
/// <summary>
/// Gets the collection of roles defined in the application
/// </summary>
public Collections.RoleDefinitionCollection Roles
{
get { return Instance.Roles; }
}
public Collections.RoleAssignmentsCollection RoleAssignments
{
get { return Instance.RoleAssignments; }
}
/// <summary>
/// Gets the collection of groups defined in the application
/// </summary>
public Collections.ApplicationGroupCollection Groups
{
get { return Instance.Groups; }
}
/// <summary>
/// Gets the collection of operations defined in the application
/// </summary>
public Collections.OperationCollection Operations
{
get { return Instance.Operations; }
}
/// <summary>
/// Gets the collection of tasks defined in the application
/// </summary>
public Collections.TaskCollection Tasks
{
get { return Instance.Tasks; }
}
public AdminManager Store
{
get;
internal set;
}
internal Application(Interfaces.IApplication application)
{
Instance = application;
Instance.Groups.Application = this;
Instance.Operations.Application = this;
Instance.RoleAssignments.Application = this;
Instance.Roles.Application = this;
Instance.Tasks.Application = this;
}
internal Application(Interfaces.IApplication application, AdminManager parent)
: this(application)
{
Store = parent;
}
public void Save()
{
Store.Applications.CheckName(this);
Locator.Factory.UpdateApplication(Instance);
Store.Applications.UpdateValue(this);
}
public void Delete()
{
Locator.Factory.DeleteApplication(Instance);
Store.Applications.RemoveValue(Key);
IsDeleted = true;
}
/// <summary>
/// Create a new group in the application
/// </summary>
/// <param name="name">name of the group</param>
/// <param name="description">description of the group</param>
/// <param name="groupType">type of group</param>
/// <returns>group in the current application</returns>
public ApplicationGroup CreateGroup(string name, string description, GroupType groupType)
{
Groups.CheckName(name);
ApplicationGroup g = Locator.Factory.CreateGroup(Key, name, description, groupType, false);
g.Parent = this;
Groups.AddValue(g);
return g;
}
public void DeleteGroup(string name)
{
ApplicationGroup g = Groups[name];
if (g == null)
return;
g.Delete();
}
//public void UpdateGroup(ApplicationGroup group)
//{
// if (group == null)
// throw new ArgumentNullException("group");
// if (!CheckObjectIsValid(group))
// throw new AzException("The group is not part of this application. Only application groups can be updated here.");
// Groups.CheckName(group);
// Locator.Factory.UpdateGroup(group);
// Groups.UpdateValue(group);
//}
/// <summary>
/// Create a new role in the application
/// </summary>
/// <param name="name">Required name of the role</param>
/// <param name="description">Description of the role</param>
/// <returns>new role</returns>
public RoleDefinition CreateRole(string name, string description)
{
Roles.CheckName(name);
RoleDefinition r = Locator.Factory.CreateRole(Key, name, description);
r.Parent = this;
Roles.AddValue(r);
return r;
}
/// <summary>
/// Deletes a role from the application
/// </summary>
/// <param name="role"></param>
public void DeleteRole(string name)
{
RoleDefinition r = Roles[name];
if (r == null)
return;
r.Delete();
}
public RoleAssignments CreateRoleAssignments(string name, string description, RoleDefinition role, bool renameOnMatch)
{
if (role == null)
throw new ArgumentNullException("role");
if (renameOnMatch)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException("name");
name = RoleAssignments.MakeNameUnique(name);
}
else
RoleAssignments.CheckName(name);
if (!CheckObjectIsValid(role))
throw new AzException("The role is not defined in this application");
AzAlternative.RoleAssignments r = Locator.Factory.CreateRoleAssignments(Key, name, description, role);
r.Parent = this;
RoleAssignments.AddValue(r);
return r;
}
public RoleAssignments CreateRoleAssignments(string name, string description, RoleDefinition role)
{
return CreateRoleAssignments(name, description, role, false);
}
public void DeleteRoleAssignments(string name)
{
RoleAssignments r = RoleAssignments[name];
if (r == null)
return;
r.Delete();
}
/// <summary>
/// Create a new operation in the application
/// </summary>
/// <param name="name">Required operation name</param>
/// <param name="description">Operaton description</param>
/// <param name="operationId">Required operaton ID</param>
/// <returns>new operation</returns>
public Operation CreateOperation(string name, string description, int operationId)
{
if (operationId < 1)
throw new ArgumentOutOfRangeException("operationId", "Operation ID must be greater than zero.");
Operations.CheckName(name);
Operations.CheckId(operationId);
Operation o = Locator.Factory.CreateOperation(Key, name, description, operationId);
o.Parent = this;
Operations.AddValue(o);
return o;
}
/// <summary>
/// Deletes the operation from the application
/// </summary>
/// <param name="operation">Operaton to delete</param>
public void DeleteOperation(string name)
{
Operation o = Operations[name];
if (o == null)
return;
o.Delete();
}
/// <summary>
/// Creates a new task in the application
/// </summary>
/// <param name="name">Required name of the task</param>
/// <param name="description">Description of the task</param>
/// <returns>new task</returns>
public Task CreateTask(string name, string description)
{
Tasks.CheckName(name);
Task t = Locator.Factory.CreateTask(Key, name, description);
t.Parent = this;
Tasks.AddValue(t);
return t;
}
/// <summary>
/// Deletes a task from the application
/// </summary>
/// <param name="task">task to delete</param>
public void DeleteTask(string name)
{
Task t = Tasks[name];
if (t == null)
return;
t.Delete();
}
}
}