18 using System.Security;
19 using erminas.SmartAPI.CMS.ServerManagement;
20 using erminas.SmartAPI.Utils;
22 namespace erminas.SmartAPI.CMS.Project
26 string DatabaseName {
get;
set; }
28 bool IsCopyingArchive {
get;
set; }
29 bool IsLoggingOffActiveUsersInProject {
get;
set; }
30 string NewProjectName {
get; }
34 internal sealed
class ProjectCopyJob : AbstractAsyncProjectJob, IProjectCopyJob
36 private readonly
string _newProjectName;
38 internal ProjectCopyJob(IProject sourceProject,
string newProjectName) : base(sourceProject)
40 _newProjectName = newProjectName;
41 DatabaseName = _newProjectName;
42 IsLoggingOffActiveUsersInProject =
true;
44 EmailSubject = String.Format(
"Finished copying project ({0})", sourceProject.Name);
45 EmailMessage = String.Format(
"Finished copying project. ({0})", sourceProject.Name);
47 if (!Session.ServerManager.DatabaseServers.TryGetByName(
"localhost", out dbServer))
49 dbServer = Session.ServerManager.DatabaseServers.First(server => server.IsCreateAllowed);
51 DatabaseServer = dbServer;
54 public string DatabaseName {
get;
set; }
56 public bool IsCopyingArchive {
get;
set; }
57 public bool IsLoggingOffActiveUsersInProject {
get;
set; }
59 public string NewProjectName
61 get {
return _newProjectName; }
66 public override void RunAsync()
68 const string COPY_PROJECT =
69 @"<ADMINISTRATION><PROJECT userguid=""{0}"" action=""copy"" guid=""{1}"" newprojectname=""{2}"" newdatabasename=""{3}"" includearchive=""{4}"" logoutusers=""{5}"" schema="""" testproject="""" schemapassword="""" databaseserver=""{6}"" editorialserver=""{7}"" reddotserverguid="""" emailnotification=""{8}"" to=""{9}"" provider="""" subject=""{10}"" message=""{11}"" /></ADMINISTRATION>";
71 string query = COPY_PROJECT.RQLFormat(Session.CurrentUser, Project, SecurityElement.Escape(NewProjectName),
72 SecurityElement.Escape(DatabaseName), IsCopyingArchive,
73 IsLoggingOffActiveUsersInProject, DatabaseServer, Server,
74 IsSendingEmailOnCompletion, EmailReceipient,
75 SecurityElement.Escape(EmailSubject),
76 SecurityElement.Escape(EmailMessage));
77 Session.ExecuteRQL(query);
80 public override void RunSync(TimeSpan maxWait)
83 if (
false && Session.ServerVersion <
new Version(11, 0))
88 Session.WaitForAsyncProcess(maxWait,
91 Project.Equals(process.Project));
95 var retryEverySecond =
new TimeSpan(0, 0, 1);
96 Session.ServerManager.Projects.WaitFor(list =>
99 return list.Refreshed().TryGetByName(NewProjectName, out project) &&
100 !project.Refreshed().IsLockedBySystem;
101 }, maxWait, retryEverySecond);