This repository was archived by the owner on Apr 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCoreRpc.cs
More file actions
346 lines (295 loc) · 12.4 KB
/
CoreRpc.cs
File metadata and controls
346 lines (295 loc) · 12.4 KB
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
using System;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Arena.Portal;
using Arena.Core;
using Arena.Security;
using Arena.Enums;
using Arena.Peer;
using Arena.Organization;
using Arena.SmallGroup;
namespace Arena.Custom.HDC.WebService
{
/// <summary>
/// Provides the core functionality of the web service. Other
/// classes exist which provide the actual front-end to different
/// RPC providers. Class methods provide anonymous functionality,
/// such as checking the API version. Instance methods provide
/// authenticated functionality, such as searching for people.
/// In communicating with the RPC service, a few rules are followed.
/// The standard retrieval and update rules for structures here
/// infers that on retrieval, only fields that are valid and the
/// person has access to are filled in, the others are not included
/// to save bandwidth. During updates or record creation, only
/// those fields that are supplied (not null) are updated. Any
/// Enum, as of this version, are treated as integers so client
/// libraries should provide local enums or other provisions to
/// ensure the user knows what the value stands for.
/// </summary>
public class CoreRpc
{
#region Methods for working with people records.
/// <summary>
/// Retrieve an RpcPeerList object to identify all the peers the
/// given personID has. If no peers are found then the peers member
/// of the returned object will be empty. If the person is not found
/// then an empty peers member will be returned.
/// </summary>
/// <param name="personID">The ID of the person who we are interested in.</param>
/// <param name="peerCount">The number of peers to return, if more peers are available only this many will be returned.</param>
/// <returns>A new RpcPeerList object which contains the information requested.</returns>
public RpcPeerList GetPersonPeers(int personID, int start, int count)
{
ScoreCollection scores = new ScoreCollection();
RpcPeerList list = new RpcPeerList();
ArrayList peers = new ArrayList();
Score s;
int i;
//
// Load the peers for this person.
//
scores.LoadBySourcePersonId(personID, 1);
//
// Make sure we have valid values to work with.
//
if (start < 0)
start = 0;
if ((start + count) > scores.Count)
count = (scores.Count - start);
//
// Walk each peer and add them to our array.
//
for (i = 0; i < count; i++)
{
RpcPeer peer = new RpcPeer();
s = scores[i + start];
peer.PersonID = s.TargetPersonId;
peer.FullName = new Person(s.TargetPersonId).FullName;
peer.Score = s.TotalScore;
peer.Trend = s.UpwardTrend;
}
list.PersonID = personID;
list.Peers = (RpcPeer[])peers.ToArray(typeof(RpcPeer));
return list;
}
#endregion
#region Methods for working with profile records.
/// <summary>
/// Get a list of all occurence IDs for a profile.
/// </summary>
/// <param name="profileID">The profile to list occurences of.</param>
/// <returns>Integer array of occurrence IDs.</returns>
public int[] GetProfileOccurrences(int profileID)
{
Profile profile;
ArrayList list;
int i;
//
// Load up the profile and check to see if it was found or not.
//
profile = new Profile(profileID);
if (profile.ProfileID == -1)
return new int[0];
list = new ArrayList(profile.Occurrences.Count);
//
// Check if the user has access to view information about the
// profile.
//
if (ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, profileID, OperationType.View) == true)
{
for (i = 0; i < profile.Occurrences.Count; i++)
{
list.Add(profile.Occurrences[i].OccurrenceID);
}
}
return (int[])list.ToArray(typeof(int));
}
#endregion
#region Methods for working with small group records.
/// <summary>
/// Find all occurrences of the given small group. If the small group
/// currently has no occurrences then an empty array is returned.
/// </summary>
/// <param name="groupID">The small group whose occurrences we are interested in.</param>
/// <returns>Integer array of occurenceIDs.</returns>
public int[] GetSmallGroupOccurrences(int groupID)
{
ArrayList list = new ArrayList();
Group group = new Group(groupID);
if (GroupClusterOperationAllowed(ArenaContext.Current.Person.PersonID, group.GroupClusterID, OperationType.View) == true)
{
foreach (GroupOccurrence occurrence in group.Occurrences)
{
list.Add(occurrence.OccurrenceID);
}
}
return (int[])list.ToArray(typeof(int));
}
#endregion
#region Private methods for validating security.
/// <summary>
/// Determines if the personID has access to perform the
/// indicated operation on the person field in question.
/// </summary>
/// <param name="personID">The ID number of the person whose security access we are checking.</param>
/// <param name="field">The ID number of the PersonField that the user wants access to.</param>
/// <param name="operation">The type of access the user needs to proceed.</param>
/// <returns>true/false indicating if the operation is allowed.</returns>
static private bool PersonFieldOperationAllowed(int personID, int field, OperationType operation)
{
PermissionCollection permissions;
//
// Load the permissions.
//
permissions = new PermissionCollection(ObjectType.PersonField, field);
return PermissionsOperationAllowed(permissions, personID, operation);
}
/// <summary>
/// Determines if the personID has access to perform the
/// indicated operation on the profile in question.
/// </summary>
/// <param name="personID">The ID number of the person whose security access we are checking.</param>
/// <param name="profileID">The ID number of the profile the user wants access to.</param>
/// <param name="operation">The type of access the user needs to proceed.</param>
/// <returns>true/false indicating if the operation is allowed.</returns>
static private bool ProfileOperationAllowed(int personID, int profileID, OperationType operation)
{
PermissionCollection permissions;
//
// Load the permissions.
//
permissions = new PermissionCollection(ObjectType.Tag, profileID);
return PermissionsOperationAllowed(permissions, personID, operation);
}
/// <summary>
/// Determines if the personID has access to perform the indicated operation
/// on the small group cluster in question.
/// </summary>
/// <param name="personID">The ID number of the person whose security access we are checkin.</param>
/// <param name="clusterID">The ID number of the profile the user wants access to.</param>
/// <param name="operation">The type of access the user needs to proceed.</param>
/// <returns>true/false indicating if the operation is allowed.</returns>
static private bool GroupClusterOperationAllowed(int personID, int clusterID, OperationType operation)
{
PermissionCollection permissions;
//
// Load the permissions.
//
permissions = new PermissionCollection(ObjectType.Group_Cluster, clusterID);
return PermissionsOperationAllowed(permissions, personID, operation);
}
/// <summary>
/// Checks the PermissionCollection class to determine if the
/// indicated operation is allowed for the person identified by
/// their ID number.
/// </summary>
/// <param name="permissions">The collection of permissions to check. These should be object permissions.</param>
/// <param name="personID">The ID number of the user whose security access we are checking.</param>
/// <param name="operation">The type of access the user needs to proceed.</param>
/// <returns>true/false indicating if the operation is allowed.</returns>
static private bool PermissionsOperationAllowed(PermissionCollection permissions, int personID, OperationType operation)
{
RoleCollection roles;
int i;
//
// Check if the person has direct permission.
//
if (permissions.ContainsSubjectOperation(SubjectType.Person, personID, operation) == true)
return true;
//
// Now check all roles for the given person.
//
roles = new RoleCollection(DefaultOrganizationID(), personID);
for (i = 0; i < roles.Count; i++)
{
if (permissions.ContainsSubjectOperation(SubjectType.Role, roles[i].RoleID, operation) == true)
return true;
}
return false;
}
#endregion
#region Generic convenience methods.
/// <summary>
/// Retrieve the default organization ID for this web
/// service. This is retrieved via the "Organization"
/// application setting in the web.config file.
/// </summary>
/// <returns>An integer indicating the organization ID.</returns>
static public int DefaultOrganizationID()
{
return Convert.ToInt32(ConfigurationSettings.AppSettings["Organization"]);
}
/// <summary>
/// Retrieve the base url (the portion of the URL without the last path
/// component, that is the filename and query string) of the current
/// web request.
/// </summary>
/// <returns>Base url as a string.</returns>
static public string BaseUrl()
{
StringBuilder url = new StringBuilder();
string[] segments;
int i;
url.Append(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority));
segments = HttpContext.Current.Request.Url.Segments;
for (i = 0; i < segments.Length - 1; i++)
{
url.Append(segments[i]);
}
return url.ToString();
}
#endregion
}
#region Data structures used in RPC communication
/// <summary>
/// Identifies a single peer by its person ID, formal name and
/// the peer level. In general, the formal name should be used
/// for displaying and the Level should be used for sorting with
/// higher numbers displayed first.
/// </summary>
public struct RpcPeer
{
/// <summary>
/// The personID of the peer identified by this structure.
/// </summary>
public int PersonID;
/// <summary>
/// A string which identifies the formal name of this person, this
/// name can and should be used when displaying the name of the
/// person in a list to be chosen from for navigating to this person.
/// </summary>
public string FullName;
/// <summary>
/// The peer score value of this person.
/// </summary>
public int Score;
/// <summary>
/// True if this peer has an upward trend, false otherwise.
/// </summary>
public bool Trend;
}
/// <summary>
/// This structure identifies a list of peers and the person
/// to whom the list belongs.
/// </summary>
public struct RpcPeerList
{
/// <summary>
/// The person to identify who this peer list belongs to.
/// </summary>
public int PersonID;
/// <summary>
/// The list of peers associated with this person.
/// </summary>
public RpcPeer[] Peers;
}
#endregion
}