SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IDatabaseConnection.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.ServerManagement;
19 using erminas.SmartAPI.Utils;
20 
21 namespace erminas.SmartAPI.CMS.Project
22 {
24  {
28  string DatabaseName { get; }
29 
33  IDatabaseServer DatabaseServer { get; }
34 
38  string DescriptionInCurrentDisplayLanguage { get; }
39  }
40 
44  internal class DatabaseConnection : PartialRedDotProjectObject, IDatabaseConnection
45  {
46  private string _databaseName;
47  private DatabaseServer _databaseServer;
48  private string _description;
49 
50  internal DatabaseConnection(IProject project, Guid guid) : base(project, guid)
51  {
52  }
53 
54  internal DatabaseConnection(IProject project, XmlElement xmlElement) : base(project, xmlElement)
55  {
56  LoadXml();
57  }
58 
62  public string DatabaseName
63  {
64  get { return LazyLoad(ref _databaseName); }
65  }
66 
70  public IDatabaseServer DatabaseServer
71  {
72  get { return LazyLoad(ref _databaseServer); }
73  }
74 
78  public string DescriptionInCurrentDisplayLanguage
79  {
80  get { return LazyLoad(ref _description); }
81  }
82 
83  protected override void LoadWholeObject()
84  {
85  LoadXml();
86  }
87 
88  protected override XmlElement RetrieveWholeObject()
89  {
90  const string LOAD_DATABASE_CONNECTION = @"<DATABASE action=""load"" guid=""{0}""/>";
91  XmlDocument xmlDoc = Project.ExecuteRQL(String.Format(LOAD_DATABASE_CONNECTION, Guid.ToRQLString()),
92  RqlType.SessionKeyInProject);
93  XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName("DATABASE");
94  if (xmlNodes.Count != 1)
95  {
96  throw new ArgumentException("Could not find database connection with guid " + Guid.ToRQLString());
97  }
98  return (XmlElement) xmlNodes[0];
99  }
100 
101  private void LoadXml()
102  {
103  InitIfPresent(ref _description, "description", x => x);
104  InitIfPresent(ref _databaseServer, "databaseserverguid",
105  x => new DatabaseServer(Project.Session, GuidConvert(x)));
106  InitIfPresent(ref _databaseName, "databasename", x => x);
107  }
108  }
109 }