18 using erminas.SmartAPI.CMS.Project;
19 using erminas.SmartAPI.Exceptions;
20 using erminas.SmartAPI.Utils;
21 using erminas.SmartAPI.Utils.CachedCollections;
23 namespace erminas.SmartAPI.CMS.ServerManagement
28 NameAndDescription = 1,
30 ConnectedDirectoryService = 4,
32 InterfaceLanguageAndLocale = 16,
33 SmartEditNavigation = 32,
34 PreferredTextEditor = 64,
40 CtrlAndMouseButton = 0,
46 Guid AccountSystemGuid {
get; }
48 string Description {
get;
set; }
51 string FullName {
get;
set; }
53 bool IsAlwaysScrollingOpenTreeSegmentsInTheVisibleArea {
get;
set; }
54 bool IsPasswordwordChangeableByCurrentUser {
get; }
56 DateTime LastLoginDate {
get; }
59 int MaximumNumberOfSessions {
get;
set; }
61 new string Name {
get;
set; }
62 string NavigationType {
get; }
63 string Password {
set; }
64 int PreferredEditor {
get; }
71 bool IsUnknownUser {
get; }
81 internal class User : PartialRedDotObject, IUser
83 private Guid _accountSystemGuid;
84 private string _description;
85 private string _email;
86 private string _fullname;
89 private bool _isPasswordChangeableByCurrentUser;
90 private bool _isScrolling;
92 private DateTime _loginDate;
93 private int _maxLevel;
94 private int _maxSessionCount;
95 private string _navigationType;
96 private string _password;
97 private int _preferredEditor;
100 private bool _isUnknownUser;
102 public User(
ISession session, Guid userGuid) : base(session, userGuid)
113 internal User(ISession session, XmlElement xmlElement) : base(session, xmlElement)
120 public Guid AccountSystemGuid
122 get {
return LazyLoad(ref _accountSystemGuid); }
127 const string SAVE_USER =
128 @"<ADMINISTRATION><USER action=""save"" guid=""{0}"" name=""{1}"" fullname=""{2}"" description=""{3}"" email=""{4}"" userlanguage=""{5}"" maxlogin=""{6}"" invertdirectedit=""{7}"" treeautoscroll=""{8}"" preferrededitor=""{9}"" navigationtype=""{10}"" lcid=""{11}"" userlimits=""{12}"" {13}/></ADMINISTRATION>";
130 var passwordAttribute = _password != null ?
"password=\"" + _password +
'"' :
"";
131 var query = SAVE_USER.SecureRQLFormat(
this, Name, FullName, Description, EMail,
132 LanguageOfUserInterface.LanguageAbbreviation, MaximumNumberOfSessions,
133 (
int) DirectEditActivationType,
134 IsAlwaysScrollingOpenTreeSegmentsInTheVisibleArea, PreferredEditor,
137 Session.ExecuteRQL(query, RQL.IODataFormat.LogonGuidOnly);
142 const string DELETE_USER =
@"<ADMINISTRATION><USER action=""delete"" guid=""{0}"" /></ADMINISTRATION>";
143 var xmlDoc = Session.ExecuteRQL(DELETE_USER.RQLFormat(
this), RQL.IODataFormat.LogonGuidOnly);
144 if (!xmlDoc.IsContainingOk())
146 throw new SmartAPIException(Session.ServerLogin,
string.Format(
"Could not delete user {0}",
this));
148 Session.ServerManager.Users.InvalidateCache();
151 public string Description
153 get {
return LazyLoad(ref _description); }
154 set { _description = value; }
159 get {
return _invertDirectEdit; }
162 EnsureInitialization();
163 _invertDirectEdit = value;
169 get {
return LazyLoad(ref _email); }
172 EnsureInitialization();
177 public string FullName
179 get {
return LazyLoad(ref _fullname); }
182 EnsureInitialization();
189 get {
return LazyLoad(ref _id); }
192 public bool IsAlwaysScrollingOpenTreeSegmentsInTheVisibleArea
194 get {
return LazyLoad(ref _isScrolling); }
197 EnsureInitialization();
198 _isScrolling = value;
202 public bool IsPasswordwordChangeableByCurrentUser
204 get {
return LazyLoad(ref _isPasswordChangeableByCurrentUser); }
207 public IDialogLocale LanguageOfUserInterface
209 get {
return LazyLoad(ref _userInterfaceLanguage); }
212 EnsureInitialization();
213 _userInterfaceLanguage = value;
217 public DateTime LastLoginDate
219 get {
return LazyLoad(ref _loginDate); }
222 public ISystemLocale Locale
224 get {
return LazyLoad(ref _locale); }
227 EnsureInitialization();
234 get {
return LazyLoad(ref _maxLevel); }
237 public int MaximumNumberOfSessions
239 get {
return LazyLoad(ref _maxSessionCount); }
242 EnsureInitialization();
243 _maxSessionCount = value;
247 public IUserModuleAssignment ModuleAssignment {
get;
private set; }
249 public new string Name
251 get {
return base.Name; }
252 set { _name = value; }
255 public string NavigationType
257 get {
return LazyLoad(ref _navigationType); }
260 public string Password
262 set { _password = value; }
265 public int PreferredEditor
267 get {
return LazyLoad(ref _preferredEditor); }
270 public bool IsUnknownUser {
get{
271 EnsureInitialization();
272 return _isUnknownUser;
273 }
private set { _isUnknownUser = value; } }
277 public UserPofileChangeRestrictions UserPofileChangeRestrictions
279 get {
return LazyLoad(ref _userPofileChangeRestrictions); }
282 EnsureInitialization();
283 _userPofileChangeRestrictions = value;
287 protected override void LoadWholeObject()
292 protected override XmlElement RetrieveWholeObject()
294 var xmlDocument =
new XmlDocument();
297 const string LOAD_USER =
@"<ADMINISTRATION><USER action=""load"" guid=""{0}""/></ADMINISTRATION>";
298 string answer = Session.ExecuteRQLRaw(String.Format(LOAD_USER, Guid.ToRQLString()),
299 RQL.IODataFormat.LogonGuidOnly);
300 xmlDocument.LoadXml(answer);
302 return (XmlElement) xmlDocument.GetElementsByTagName(
"USER")[0];
306 IsUnknownUser =
true;
307 return xmlDocument.CreateElement(
"USER");
313 Projects =
new UserProjects(
this,
Caching.Enabled);
314 ModuleAssignment =
new UserModuleAssignment(
this);
317 private void LoadXml()
319 InitIfPresent(ref _id,
"id",
int.Parse);
320 InitIfPresent(ref _maxLevel,
"maxlevel",
int.Parse);
321 InitIfPresent(ref _maxSessionCount,
"maxlogin",
int.Parse);
322 InitIfPresent(ref _preferredEditor,
"preferrededitor",
int.Parse);
323 _fullname = _xmlElement.GetAttributeValue(
"fullname");
324 _description = _xmlElement.GetAttributeValue(
"description");
325 _email = _xmlElement.GetAttributeValue(
"email");
326 _xmlElement.TryGetGuid(
"accountsystemguid", out _accountSystemGuid);
327 InitIfPresent(ref _userInterfaceLanguage,
"userlanguage", Session.DialogLocales.Get);
328 InitIfPresent(ref _locale,
"lcid", s => Session.Locales[
int.Parse(s)]);
329 InitIfPresent(ref _isScrolling,
"treeautoscroll", BoolConvert);
330 _loginDate = _xmlElement.GetOADate(
"logindate").GetValueOrDefault();
331 InitIfPresent(ref _invertDirectEdit,
"invertdirectedit", StringConversion.ToEnum<
DirectEditActivation>);
332 InitIfPresent(ref _isPasswordChangeableByCurrentUser,
"disablepassword", x => !BoolConvert(x));
333 InitIfPresent(ref _userPofileChangeRestrictions,
"userlimits",
334 StringConversion.ToEnum<UserPofileChangeRestrictions>);