17 using System.Collections.Generic;
20 using erminas.SmartAPI.CMS.ServerManagement;
21 using erminas.SmartAPI.Exceptions;
22 using erminas.SmartAPI.Utils.CachedCollections;
24 namespace erminas.SmartAPI.CMS.Project
29 bool ContainsUser(
IUser user);
30 bool ContainsUserGuid(Guid userGuid);
31 bool ContainsUserName(
string userName);
35 void Remove(
IUser user);
41 internal class ProjectUsers : IndexedCachedList<string, IUserProjectAssignment>, IProjectUsers
43 private readonly IProject _project;
45 internal ProjectUsers(IProject project,
Caching caching) : base(assignment => assignment.User.Name, caching)
48 RetrieveFunc = GetUsersOfProject;
53 return UserProjectAssignment.Create(user, _project, role, extendedUserRoles);
56 public bool ContainsUser(
IUser user)
58 return ContainsUserGuid(user.
Guid);
61 public bool ContainsUserGuid(Guid userGuid)
63 return this.Any(assignment => assignment.User.Guid == userGuid);
66 public bool ContainsUserName(
string userName)
68 return this.Any(assignment => assignment.User.Name == userName);
73 return this.First(x => x.User.Guid == userGuid);
78 return this[userName];
83 get {
return this[user.
Name]; }
86 public IProject Project
88 get {
return _project; }
91 public void Remove(
IUser user)
93 UserProjectAssignment.
Delete(Project, user);
96 public ISession Session
98 get {
return _project.Session; }
103 return TryGetByUserGuid(user.
Guid, out assignment);
108 assignment = this.FirstOrDefault(projectAssignment => projectAssignment.User.Guid == userGuid);
109 return assignment != null;
114 return TryGet(userName, out assignment);
117 private List<IUserProjectAssignment> GetUsersOfProject()
121 const string GET_USERS =
@"<PROJECT><USERS action=""list""/></PROJECT>";
122 var xmlDoc = Session.ExecuteRQLInProjectContext(GET_USERS, _project.Guid);
123 var xmlNodes = xmlDoc.GetElementsByTagName(
"USER");
125 return (from XmlElement node in xmlNodes
128 }
catch (Exception e)
131 string.Format(
"Could not load users of project {0} ",
this), e);