SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IProjects.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.CMS.Project;
21 using erminas.SmartAPI.Exceptions;
22 using erminas.SmartAPI.Utils;
23 using erminas.SmartAPI.Utils.CachedCollections;
24 
25 namespace erminas.SmartAPI.CMS.ServerManagement
26 {
27  internal class Projects : NameIndexedRDList<IProject>, IProjects
28  {
29  private readonly ISession _session;
30 
31  public Projects(ISession session, Caching caching) : base(caching)
32  {
33  _session = session;
34  RetrieveFunc = GetProjects;
35  ForCurrentUser =
36  new NameIndexedRDList<IProject>(() => ForUser(_session.ServerManager.Users.Current.Guid).ToList(),
37  Caching.Enabled);
38  }
39 
40  public IProjectImportJob CreateImportJob(string newProjectName, string importPath)
41  {
42  return new ProjectImportJob(_session, newProjectName, importPath);
43  }
44 
45  public IProject CreateProjectMsSql(string projectName, IApplicationServer appServer, IDatabaseServer dbServer,
46  string databaseName, ISystemLocale language, CreatedProjectType type,
47  UseVersioning useVersioning, IUser user)
48  {
49  const string CREATE_PROJECT =
50  @"<ADMINISTRATION><PROJECT action=""addnew"" projectname=""{0}"" databaseserverguid=""{1}"" editorialserverguid=""{2}"" databasename=""{3}""
51 versioning=""{4}"" testproject=""{5}""><LANGUAGEVARIANTS><LANGUAGEVARIANT language=""{7}"" name=""{8}"" /></LANGUAGEVARIANTS><USERS><USER action=""assign"" guid=""{6}""/></USERS></PROJECT></ADMINISTRATION>";
52 
53  XmlDocument result = Session.ParseRQLResult(_session,
54  _session.ExecuteRQLRaw(
55  CREATE_PROJECT.RQLFormat(projectName, dbServer, appServer,
56  databaseName, (int) useVersioning,
57  (int) type, user,
58  language.LanguageAbbreviation,
59  language.Language),
60  RQL.IODataFormat.SessionKeyAndLogonGuid));
61 
62  string guidStr = result.InnerText;
63  Guid projectGuid;
64  if (!Guid.TryParse(guidStr, out projectGuid))
65  {
66  throw new SmartAPIException(_session.ServerLogin,
67  string.Format("Could not create project {0}", projectName));
68  }
69 
70  InvalidateCache();
71  return new Project.Project(_session, projectGuid);
72  }
73 
74  public IIndexedRDList<string, IProject> ForCurrentUser { get; private set; }
75 
81  public IRDEnumerable<IProject> ForUser(Guid userGuid)
82  {
83  const string LIST_PROJECTS_FOR_USER =
84  @"<ADMINISTRATION><USER guid=""{0}""><PROJECTS action=""list"" extendedinfo=""1""/></USER></ADMINISTRATION>";
85  XmlDocument xmlDoc = _session.ExecuteRQL(String.Format(LIST_PROJECTS_FOR_USER, userGuid.ToRQLString()));
86  XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName("PROJECT");
87  return
88  (from XmlElement curNode in xmlNodes select (IProject) new Project.Project(_session, curNode))
89  .ToRDEnumerable();
90  }
91 
92  private List<IProject> GetProjects()
93  {
94  const string LIST_PROJECTS = @"<ADMINISTRATION><PROJECTS action=""list""/></ADMINISTRATION>";
95  XmlDocument xmlDoc = _session.ExecuteRQL(LIST_PROJECTS);
96  XmlNodeList projectNodes = xmlDoc.GetElementsByTagName("PROJECT");
97  return
98  (from XmlElement curNode in projectNodes select (IProject) new Project.Project(_session, curNode))
99  .ToList();
100  }
101  }
102 
103  public interface IProjects : IIndexedRDList<string, IProject>
104  {
105  IProjectImportJob CreateImportJob(string newProjectName, string importPath);
106 
107  IProject CreateProjectMsSql(string projectName, IApplicationServer appServer, IDatabaseServer dbServer,
108  string databaseName, ISystemLocale language, CreatedProjectType type,
109  UseVersioning useVersioning, IUser user);
110 
111  IIndexedRDList<string, IProject> ForCurrentUser { get; }
112  IRDEnumerable<IProject> ForUser(Guid userGuid);
113  }
114 }