SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IUser.cs
Go to the documentation of this file.
1 ï»¿// SmartAPI - .Net programmatic access to RedDot servers
2 //
3 // Copyright (C) 2013 erminas GbR
4 //
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free Software Foundation,
7 // either version 3 of the License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 // See the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program.
14 // If not, see <http://www.gnu.org/licenses/>.
15 
16 using System;
17 using System.Xml;
18 using erminas.SmartAPI.CMS.Project;
19 using erminas.SmartAPI.Exceptions;
20 using erminas.SmartAPI.Utils;
21 using erminas.SmartAPI.Utils.CachedCollections;
22 
23 namespace erminas.SmartAPI.CMS.ServerManagement
24 {
25  [Flags]
27  {
28  NameAndDescription = 1,
29  EMailAdress = 2,
30  ConnectedDirectoryService = 4,
31  Password = 8,
32  InterfaceLanguageAndLocale = 16,
33  SmartEditNavigation = 32,
34  PreferredTextEditor = 64,
35  DirectEdit = 128
36  }
37 
39  {
40  CtrlAndMouseButton = 0,
41  MouseButtonOnly = 1
42  }
43 
45  {
46  Guid AccountSystemGuid { get; }
47  void Commit();
48  string Description { get; set; }
49  DirectEditActivation DirectEditActivationType { get; set; }
50  string EMail { get; set; }
51  string FullName { get; set; }
52  int Id { get; }
53  bool IsAlwaysScrollingOpenTreeSegmentsInTheVisibleArea { get; set; }
54  bool IsPasswordwordChangeableByCurrentUser { get; }
55  IDialogLocale LanguageOfUserInterface { get; set; }
56  DateTime LastLoginDate { get; }
57  ISystemLocale Locale { get; set; }
58  int MaxLevel { get; }
59  int MaximumNumberOfSessions { get; set; }
60  IUserModuleAssignment ModuleAssignment { get; }
61  new string Name { get; set; }
62  string NavigationType { get; }
63  string Password { set; }
64  int PreferredEditor { get; }
65 
71  bool IsUnknownUser { get; }
72 
73  IUserProjects Projects { get; }
74 
76  }
77 
81  internal class User : PartialRedDotObject, IUser
82  {
83  private Guid _accountSystemGuid;
84  private string _description;
85  private string _email;
86  private string _fullname;
87  private int _id;
88  private DirectEditActivation _invertDirectEdit;
89  private bool _isPasswordChangeableByCurrentUser;
90  private bool _isScrolling;
91  private ISystemLocale _locale;
92  private DateTime _loginDate;
93  private int _maxLevel;
94  private int _maxSessionCount;
95  private string _navigationType;
96  private string _password;
97  private int _preferredEditor;
98  private IDialogLocale _userInterfaceLanguage;
99  private UserPofileChangeRestrictions _userPofileChangeRestrictions;
100  private bool _isUnknownUser;
101 
102  public User(ISession session, Guid userGuid) : base(session, userGuid)
103  {
104  Init();
105  }
106 
113  internal User(ISession session, XmlElement xmlElement) : base(session, xmlElement)
114  {
115  Init();
116 
117  LoadXml();
118  }
119 
120  public Guid AccountSystemGuid
121  {
122  get { return LazyLoad(ref _accountSystemGuid); }
123  }
124 
125  public void Commit()
126  {
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>";
129 
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,
135  NavigationType, Locale, (int) UserPofileChangeRestrictions,
136  passwordAttribute);
137  Session.ExecuteRQL(query, RQL.IODataFormat.LogonGuidOnly);
138  }
139 
140  public void Delete()
141  {
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())
145  {
146  throw new SmartAPIException(Session.ServerLogin, string.Format("Could not delete user {0}", this));
147  }
148  Session.ServerManager.Users.InvalidateCache();
149  }
150 
151  public string Description
152  {
153  get { return LazyLoad(ref _description); }
154  set { _description = value; }
155  }
156 
157  public DirectEditActivation DirectEditActivationType
158  {
159  get { return _invertDirectEdit; }
160  set
161  {
162  EnsureInitialization();
163  _invertDirectEdit = value;
164  }
165  }
166 
167  public string EMail
168  {
169  get { return LazyLoad(ref _email); }
170  set
171  {
172  EnsureInitialization();
173  _email = value;
174  }
175  }
176 
177  public string FullName
178  {
179  get { return LazyLoad(ref _fullname); }
180  set
181  {
182  EnsureInitialization();
183  _fullname = value;
184  }
185  }
186 
187  public int Id
188  {
189  get { return LazyLoad(ref _id); }
190  }
191 
192  public bool IsAlwaysScrollingOpenTreeSegmentsInTheVisibleArea
193  {
194  get { return LazyLoad(ref _isScrolling); }
195  set
196  {
197  EnsureInitialization();
198  _isScrolling = value;
199  }
200  }
201 
202  public bool IsPasswordwordChangeableByCurrentUser
203  {
204  get { return LazyLoad(ref _isPasswordChangeableByCurrentUser); }
205  }
206 
207  public IDialogLocale LanguageOfUserInterface
208  {
209  get { return LazyLoad(ref _userInterfaceLanguage); }
210  set
211  {
212  EnsureInitialization();
213  _userInterfaceLanguage = value;
214  }
215  }
216 
217  public DateTime LastLoginDate
218  {
219  get { return LazyLoad(ref _loginDate); }
220  }
221 
222  public ISystemLocale Locale
223  {
224  get { return LazyLoad(ref _locale); }
225  set
226  {
227  EnsureInitialization();
228  _locale = value;
229  }
230  }
231 
232  public int MaxLevel
233  {
234  get { return LazyLoad(ref _maxLevel); }
235  }
236 
237  public int MaximumNumberOfSessions
238  {
239  get { return LazyLoad(ref _maxSessionCount); }
240  set
241  {
242  EnsureInitialization();
243  _maxSessionCount = value;
244  }
245  }
246 
247  public IUserModuleAssignment ModuleAssignment { get; private set; }
248 
249  public new string Name
250  {
251  get { return base.Name; }
252  set { _name = value; }
253  }
254 
255  public string NavigationType
256  {
257  get { return LazyLoad(ref _navigationType); }
258  }
259 
260  public string Password
261  {
262  set { _password = value; }
263  }
264 
265  public int PreferredEditor
266  {
267  get { return LazyLoad(ref _preferredEditor); }
268  }
269 
270  public bool IsUnknownUser { get{
271  EnsureInitialization();
272  return _isUnknownUser;
273  } private set { _isUnknownUser = value; } }
274 
275  public IUserProjects Projects { get; private set; }
276 
277  public UserPofileChangeRestrictions UserPofileChangeRestrictions
278  {
279  get { return LazyLoad(ref _userPofileChangeRestrictions); }
280  set
281  {
282  EnsureInitialization();
283  _userPofileChangeRestrictions = value;
284  }
285  }
286 
287  protected override void LoadWholeObject()
288  {
289  LoadXml();
290  }
291 
292  protected override XmlElement RetrieveWholeObject()
293  {
294  var xmlDocument = new XmlDocument();
295  try
296  {
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);
301 
302  return (XmlElement) xmlDocument.GetElementsByTagName("USER")[0];
303  }
304  catch ( RQLException e )
305  {
306  IsUnknownUser = true;
307  return xmlDocument.CreateElement("USER");
308  }
309  }
310 
311  private void Init()
312  {
313  Projects = new UserProjects(this, Caching.Enabled);
314  ModuleAssignment = new UserModuleAssignment(this);
315  }
316 
317  private void LoadXml()
318  {
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>);
335  }
336  }
337 }