17 using System.Collections.Generic;
20 using erminas.SmartAPI.Utils;
21 using erminas.SmartAPI.Utils.CachedCollections;
23 namespace erminas.SmartAPI.CMS.ServerManagement
25 public interface IUsers : IIndexedRDList<String, IUser>
27 IUser Create(
string name,
string password);
35 internal class Users : NameIndexedRDList<IUser>, IUsers
37 private readonly Session _session;
38 private Lazy<IUser> _user;
40 internal Users(Session session,
Caching caching) : base(caching)
43 RetrieveFunc = GetUsers;
44 _user =
new Lazy<IUser>(GetCurrentUser);
47 public IUser Create(
string name,
string password)
49 const string CREATE_USER =
50 @"<ADMINISTRATION><USER action=""addnew"" name=""{0}"" pw=""{1}"" lcid=""{2}"" userlanguage=""{3}""></USER></ADMINISTRATION>";
51 _session.ExecuteRQL(CREATE_USER.SecureRQLFormat(name, password, _session.StandardLocale,
52 _session.StandardLocale.LanguageAbbreviation));
59 get {
return _user.Value; }
60 internal set { _user =
new Lazy<IUser>(() => value); }
63 private IUser GetCurrentUser()
65 var userElement = _session.GetUserSessionInfoElement();
67 return new User(_session, userElement.GetGuid()) {Name = userElement.GetName()};
70 private List<IUser> GetUsers()
72 const string LIST_USERS =
@"<ADMINISTRATION><USERS action=""list""/></ADMINISTRATION>";
73 var userListDoc = _session.ExecuteRQL(LIST_USERS);
75 return (from XmlElement curUserElement in userListDoc.GetElementsByTagName(
"USER")
76 select (IUser) new User(_session, curUserElement)).ToList();