SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IApplicationServers.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.Collections.Generic;
18 using System.Linq;
19 using System.Xml;
20 using erminas.SmartAPI.Utils;
21 using erminas.SmartAPI.Utils.CachedCollections;
22 
23 namespace erminas.SmartAPI.CMS.ServerManagement
24 {
25  internal class ApplicationServers : RDList<IApplicationServer>, IApplicationServers
26  {
27  private readonly Lazy<IApplicationServer> _currentApplicationServer;
28  private readonly Session _session;
29 
30  public ApplicationServers(Session session, Caching caching) : base(caching)
31  {
32  _session = session;
33  RetrieveFunc = GetApplicationServers;
34  _currentApplicationServer = new Lazy<IApplicationServer>(GetCurrentApplicationServer);
35  }
36 
37  public IApplicationServer Current
38  {
39  get { return _currentApplicationServer.Value; }
40  }
41 
42  public ISession Session
43  {
44  get { return _session; }
45  }
46 
47  private List<IApplicationServer> GetApplicationServers()
48  {
49  const string LIST_APPLICATION_SERVERS =
50  @"<ADMINISTRATION><EDITORIALSERVERS action=""list""/></ADMINISTRATION>";
51  XmlDocument xmlDoc = _session.ExecuteRQL(LIST_APPLICATION_SERVERS);
52 
53  XmlNodeList editorialServers = xmlDoc.GetElementsByTagName("EDITORIALSERVER");
54  return (from XmlElement curServer in editorialServers
55  select
56  (IApplicationServer)
57  new ApplicationServer(_session, curServer.GetGuid())
58  {
59  Name = curServer.GetName(),
60  IpAddress = curServer.GetAttributeValue("ip")
61  }).ToList();
62  }
63 
64  private IApplicationServer GetCurrentApplicationServer()
65  {
66  const string LOAD_APPLICATIONSERVER =
67  @"<ADMINISTRATION><EDITORIALSERVER action=""check""/></ADMINISTRATION>";
68  XmlDocument reply = _session.ExecuteRQL(LOAD_APPLICATIONSERVER, RQL.IODataFormat.Plain);
69  return new ApplicationServer(_session, reply.GetSingleElement("EDITORIALSERVER").GetGuid("serverguid"));
70  }
71  }
72 
73  public interface IApplicationServers : IRDList<IApplicationServer>, ISessionObject
74  {
75  IApplicationServer Current { get; }
76  }
77 }