SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IGroup.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.Exceptions;
19 using erminas.SmartAPI.Utils;
20 
21 namespace erminas.SmartAPI.CMS.ServerManagement
22 {
24  {
25  void Commit();
26  string EMailAdress { get; set; }
27  new string Name { get; set; }
28  }
29 
30  public static class GroupFactory
31  {
32  public static IGroup CreateFromGuid(ISession session, Guid guid)
33  {
34  return new Group(session, guid);
35  }
36  }
37 
38  internal class Group : PartialRedDotObject, IGroup
39  {
40  private string _email;
41 
42  internal Group(ISession session, XmlElement xmlElement) : base(session, xmlElement)
43  {
44  LoadXml();
45  }
46 
47  internal Group(ISession session, Guid guid) : base(session, guid)
48  {
49  }
50 
51  public void Commit()
52  {
53  const string SAVE_GROUP =
54  @"<ADMINISTRATION><GROUP action=""save"" guid=""{0}"" name=""{1}"" email=""{2}""/></ADMINISTRATION>";
55 
56  var xmlDoc = Session.ExecuteRQL(SAVE_GROUP.SecureRQLFormat(this, Name, EMailAdress));
57  if (!xmlDoc.InnerText.Contains(Guid.ToRQLString()))
58  {
59  throw new SmartAPIException(Session.ServerLogin, string.Format("Could not save group {0}", this));
60  }
61  }
62 
63  public void Delete()
64  {
65  const string DELETE_GROUP = @"<ADMINISTRATION><GROUP action=""delete"" guid=""{0}""/></ADMINISTRATION>";
66  var xmlDoc = Session.ExecuteRQL(DELETE_GROUP.RQLFormat(this));
67  if (!xmlDoc.IsContainingOk())
68  {
69  throw new SmartAPIException(Session.ServerLogin, string.Format("Could not delete group {0}", this));
70  }
71  }
72 
73  public string EMailAdress
74  {
75  get { return LazyLoad(ref _email); }
76  set
77  {
78  EnsureInitialization();
79  _email = value;
80  }
81  }
82 
83  public new string Name
84  {
85  get { return base.Name; }
86  set
87  {
88  EnsureInitialization();
89  base.Name = value;
90  }
91  }
92 
93  protected override void LoadWholeObject()
94  {
95  LoadXml();
96  }
97 
98  protected override XmlElement RetrieveWholeObject()
99  {
100  const string LOAD_GROUP = @"<ADMINISTRATION><GROUP action=""load"" guid=""{0}""/></ADMINISTRATION>";
101  return Session.ExecuteRQL(LOAD_GROUP.RQLFormat(this)).GetSingleElement("GROUP");
102  }
103 
104  private void LoadXml()
105  {
106  _email = _xmlElement.GetAttributeValue("email");
107  }
108  }
109 }