SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IApplicationServer.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.Utils;
19 
20 namespace erminas.SmartAPI.CMS.ServerManagement
21 {
22  internal class ApplicationServer : PartialRedDotObject, IApplicationServer
23  {
24  private string _from;
25  private string _ipAddress;
26  private bool _isServerCheckDataLoaded;
27  private string _tempPath;
28 
29  public ApplicationServer(Session session, Guid guid) : base(session, guid)
30  {
31  }
32 
33  internal ApplicationServer(Session session, XmlElement element) : base(session, element)
34  {
35  LoadXml();
36  }
37 
38  public string From
39  {
40  get { return LazyLoad(ref _from); }
41  internal set { _from = value; }
42  }
43 
44  public string IpAddress
45  {
46  get { return LazyLoad(ref _ipAddress); }
47  internal set { _ipAddress = value; }
48  }
49 
50  public override void Refresh()
51  {
52  _isServerCheckDataLoaded = false;
53  base.Refresh();
54  EnsureServerCheck();
55  }
56 
57  public string TempDirectoryPath
58  {
59  get
60  {
61  EnsureServerCheck();
62  return _tempPath;
63  }
64  }
65 
66  protected override void LoadWholeObject()
67  {
68  LoadXml();
69  }
70 
71  protected override XmlElement RetrieveWholeObject()
72  {
73  const string LOAD_APPLICATION_SERVER =
74  @"<ADMINISTRATION><EDITORIALSERVER action=""load"" guid=""{0}""/></ADMINISTRATION>";
75 
76  XmlDocument xmlDoc = Session.ExecuteRQL(LOAD_APPLICATION_SERVER.RQLFormat(this));
77  return xmlDoc.GetSingleElement("EDITORIALSERVER");
78  }
79 
80  private void EnsureServerCheck()
81  {
82  if (_isServerCheckDataLoaded)
83  {
84  return;
85  }
86 
87  const string CHECK_SERVER =
88  @"<ADMINISTRATION><EDITORIALSERVER action=""check"" guid=""{0}""/></ADMINISTRATION>";
89 
90  var xmlDoc = Session.ExecuteRQL(CHECK_SERVER.RQLFormat(this));
91  var element = xmlDoc.GetSingleElement("EDITORIALSERVER");
92 
93  _tempPath = element.GetAttributeValue("temppath");
94 
95  _isServerCheckDataLoaded = true;
96  }
97 
98  private void LoadXml()
99  {
100  _from = _xmlElement.GetAttributeValue("adress");
101  _ipAddress = _xmlElement.GetAttributeValue("ip");
102  }
103  }
104 
106  {
107  string From { get; }
108  string IpAddress { get; }
109  string TempDirectoryPath { get; }
110  }
111 }