SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IServerManager.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.Collections.Generic;
17 using System.Linq;
18 using System.Xml;
19 using erminas.SmartAPI.Utils.CachedCollections;
20 
21 namespace erminas.SmartAPI.CMS.ServerManagement
22 {
23  internal class ServerManager : IServerManager
24  {
25  private readonly Session _session;
26 
27  internal ServerManager(Session session)
28  {
29  _session = session;
30 
31  Groups = new Groups(_session, Caching.Enabled);
32  Projects = new Projects(_session, Caching.Enabled);
33  DatabaseServers = new DatabaseServers(_session, Caching.Enabled);
34  Users = new Users(_session, Caching.Enabled);
35  Modules = new IndexedRDList<ModuleType, IModule>(GetModules, x => x.Type, Caching.Enabled);
36  AsynchronousProcesses = new RDList<IAsynchronousProcess>(GetAsynchronousProcesses, Caching.Disabled);
37  ApplicationServers = new ApplicationServers(_session, Caching.Enabled);
38  }
39 
40  public IApplicationServers ApplicationServers { get; private set; }
41 
42  public IRDList<IAsynchronousProcess> AsynchronousProcesses { get; private set; }
43  public IDatabaseServers DatabaseServers { get; private set; }
44  public IGroups Groups { get; private set; }
45  public IIndexedRDList<ModuleType, IModule> Modules { get; private set; }
46 
47  public IProjects Projects { get; private set; }
48  public IUsers Users { get; private set; }
49 
50  private List<IAsynchronousProcess> GetAsynchronousProcesses()
51  {
52  const string LIST_PROCESSES = @"<ADMINISTRATION><ASYNCQUEUE action=""list"" project=""""/></ADMINISTRATION>";
53  XmlDocument xmlDoc = _session.ExecuteRQL(LIST_PROCESSES);
54  return (from XmlElement curProcess in xmlDoc.GetElementsByTagName("ASYNCQUEUE")
55  select (IAsynchronousProcess) new AsynchronousProcess(_session, curProcess)).ToList();
56  }
57 
58  private List<IModule> GetModules()
59  {
60  const string LIST_MODULES = @"<ADMINISTRATION><MODULES action=""list"" /></ADMINISTRATION>";
61  XmlDocument xmlDoc = _session.ExecuteRQL(LIST_MODULES);
62 
63  //we need to create an intermediate list, because the XmlNodeList returned by GetElementsByTagName gets changed in the linq/ToList() expression.
64  //the change to the list occurs due to the cloning on the XmlElements in Module->AbstractAttributeContainer c'tor.
65  //i have no idea why that changes the list as the same approach works without a problem everywhere else without the need for the intermediate list.
66  List<XmlElement> moduleElements = xmlDoc.GetElementsByTagName("MODULE").OfType<XmlElement>().ToList();
67  return
68  (from XmlElement curModule in moduleElements select (IModule) new Module(_session, curModule)).ToList();
69  }
70  }
71 
72  public interface IServerManager
73  {
74  IApplicationServers ApplicationServers { get; }
75 
82  IRDList<IAsynchronousProcess> AsynchronousProcesses { get; }
83 
84  IDatabaseServers DatabaseServers { get; }
85  IGroups Groups { get; }
86 
87  IIndexedRDList<ModuleType, IModule> Modules { get; }
88  IProjects Projects { get; }
89  IUsers Users { get; }
90  }
91 }