2 using System.Collections.Generic;
3 using System.Globalization;
5 using erminas.SmartAPI.CMS.ServerManagement;
6 using erminas.SmartAPI.Exceptions;
7 using erminas.SmartAPI.Utils;
9 namespace erminas.SmartAPI.CMS.Project.Pages
11 internal class PagePublishJob : IPagePublishJob
13 internal PagePublishJob(IPage page)
16 LanguageVariants =
new List<ILanguageVariant>();
17 ProjectVariants =
new List<IProjectVariant>();
20 public ISession Session {
get {
return Page.Session; } }
21 public IProject Project {
get {
return Page.Project; } }
22 public IPage Page {
get;
private set; }
23 public bool IsPublishingAllFollowingPages {
get;
set; }
24 public bool IsPublishingRelatedPages {
get;
set; }
25 public bool IsSendingEmailOnCompletion {
get;
set; }
26 public IUser EMailReceipient {
get;
set; }
28 public DateTime PublishAccordingTo {
get;
set; }
29 public DateTime PublishOn {
get;
set; }
30 public IEnumerable<ILanguageVariant> LanguageVariants {
get;
set; }
31 public IEnumerable<IProjectVariant> ProjectVariants {
get;
set; }
32 public void RunAsync()
36 const string PUBLISH =
@"<PROJECT guid=""{0}"" sessionkey=""{10}""><PAGE guid=""{1}""><EXPORTJOB action=""save"" email=""{2}"" toppriority=""0"" generatenextpages=""{3}"" generaterelativepages=""{4}"" reddotserver=""{5}"" application="""" generatedate=""{6}"" startgenerationat=""{7}""><LANGUAGEVARIANTS action=""checkassigning"">{8}</LANGUAGEVARIANTS><PROJECTVARIANTS action=""checkassigning"">{9}</PROJECTVARIANTS></EXPORTJOB></PAGE></PROJECT>";
38 var languageVariants = GetLanguageVariantsString();
39 var projectVariants = GetProjectVariantsString();
41 var publishAccordingToString = ToRQLString(PublishAccordingTo);
42 var publishOnString = ToRQLString(PublishOn);
44 var query = PUBLISH.RQLFormat(Project, Page, IsSendingEmailOnCompletion ? EMailReceipient : null,
45 IsPublishingAllFollowingPages, IsPublishingRelatedPages, Server, publishAccordingToString,
46 publishOnString, languageVariants, projectVariants, Session.SessionKey);
48 Project.ExecuteRQL(query);
51 private void CheckValidity()
53 if (LanguageVariants == null || !LanguageVariants.Any())
57 "Missing language variant assignment for the publication of page {0}", Page));
60 if (ProjectVariants == null || !ProjectVariants.Any())
63 string.Format(
"Missing project variant assignment for the publication of page {0}",
68 private static string ToRQLString(DateTime dt)
70 return dt !=
default(DateTime)
71 ? dt.ToString(
"M/d/yyyy", CultureInfo.InvariantCulture)
72 : RQL.SESSIONKEY_PLACEHOLDER;
75 private string GetLanguageVariantsString()
77 const string SINGLE_LANGUAGE_VARIANT =
@"<LANGUAGEVARIANT guid=""{0}"" checked=""{1}""/>";
79 var checkedLanguageVariants = LanguageVariants.Aggregate(
"",
81 s + SINGLE_LANGUAGE_VARIANT.RQLFormat(variant.Guid.ToRQLString(),
true));
82 var uncheckedLanguageVariants = Project.LanguageVariants.Except(LanguageVariants)
85 s + SINGLE_LANGUAGE_VARIANT.RQLFormat(variant.Guid.ToRQLString(),
false));
87 var languageVariants = checkedLanguageVariants + uncheckedLanguageVariants;
88 return languageVariants;
91 private string GetProjectVariantsString()
93 const string SINGLE_PROJECT_VARIANT =
@"<PROJECTVARIANT guid=""{0}"" checked=""{1}""/>";
95 var checkedProjectVariants = ProjectVariants.Aggregate(
"",
97 s + SINGLE_PROJECT_VARIANT.RQLFormat(variant,
true));
99 var uncheckedProjectVariants = Project.ProjectVariants.Except(ProjectVariants)
102 s + SINGLE_PROJECT_VARIANT.RQLFormat(variant,
false));
103 var projectVariants = checkedProjectVariants + uncheckedProjectVariants;
104 return projectVariants;
112 bool IsPublishingAllFollowingPages {
get;
set; }
113 bool IsPublishingRelatedPages {
get;
set; }
114 bool IsSendingEmailOnCompletion {
get;
set; }
119 DateTime PublishAccordingTo {
get;
set; }
120 DateTime PublishOn {
get;
set; }
121 IEnumerable<ILanguageVariant> LanguageVariants{
get;
set; }
122 IEnumerable<IProjectVariant> ProjectVariants {
get;
set; }