17 using System.Collections.Generic;
20 using erminas.SmartAPI.CMS.Project;
21 using erminas.SmartAPI.Exceptions;
22 using erminas.SmartAPI.Utils;
23 using erminas.SmartAPI.Utils.CachedCollections;
25 namespace erminas.SmartAPI.CMS.ServerManagement
27 internal class Projects : NameIndexedRDList<IProject>, IProjects
29 private readonly ISession _session;
31 public Projects(ISession session,
Caching caching) : base(caching)
34 RetrieveFunc = GetProjects;
36 new NameIndexedRDList<IProject>(() => ForUser(_session.ServerManager.Users.Current.Guid).ToList(),
40 public IProjectImportJob CreateImportJob(
string newProjectName,
string importPath)
42 return new ProjectImportJob(_session, newProjectName, importPath);
45 public IProject CreateProjectMsSql(
string projectName, IApplicationServer appServer, IDatabaseServer dbServer,
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>";
53 XmlDocument result = Session.ParseRQLResult(_session,
54 _session.ExecuteRQLRaw(
55 CREATE_PROJECT.RQLFormat(projectName, dbServer, appServer,
56 databaseName, (
int) useVersioning,
58 language.LanguageAbbreviation,
60 RQL.IODataFormat.SessionKeyAndLogonGuid));
62 string guidStr = result.InnerText;
64 if (!Guid.TryParse(guidStr, out projectGuid))
67 string.Format(
"Could not create project {0}", projectName));
71 return new Project.Project(_session, projectGuid);
74 public IIndexedRDList<string, IProject> ForCurrentUser {
get;
private set; }
81 public IRDEnumerable<IProject> ForUser(Guid userGuid)
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");
88 (from XmlElement curNode in xmlNodes select (
IProject)
new Project.Project(_session, curNode))
92 private List<IProject> GetProjects()
94 const string LIST_PROJECTS =
@"<ADMINISTRATION><PROJECTS action=""list""/></ADMINISTRATION>";
95 XmlDocument xmlDoc = _session.ExecuteRQL(LIST_PROJECTS);
96 XmlNodeList projectNodes = xmlDoc.GetElementsByTagName(
"PROJECT");
98 (from XmlElement curNode in projectNodes select (
IProject)
new Project.Project(_session, curNode))
103 public interface IProjects : IIndexedRDList<string, IProject>
111 IIndexedRDList<string, IProject> ForCurrentUser {
get; }
112 IRDEnumerable<IProject> ForUser(Guid userGuid);