16 using System.Collections.Generic;
19 using erminas.SmartAPI.Exceptions;
20 using erminas.SmartAPI.Utils;
21 using erminas.SmartAPI.Utils.CachedCollections;
23 namespace erminas.SmartAPI.CMS.Project.Publication
27 IIndexedRDList<string, IPublicationFolderSetting> ExportFolderSettings {
get; }
31 IEnumerable<IPublicationTarget> PublishingTargets {
get; }
32 void SetPublishingTargetsAndCommit(List<IPublicationTarget> newTargets);
35 internal class PublicationSetting : RedDotProjectObject, IPublicationSetting
37 private readonly NameIndexedRDList<IPublicationFolderSetting> _exportFolderSettings;
38 private List<IPublicationTarget> _publishingTargets;
39 private readonly IPublicationSettings _publicationSettings;
41 internal PublicationSetting(IPublicationSettings settings, XmlElement xmlElement)
42 : base(settings.Project, xmlElement)
44 _exportFolderSettings =
new NameIndexedRDList<IPublicationFolderSetting>(LoadExportFolderSettings,
46 _publicationSettings = settings;
50 public IIndexedRDList<string, IPublicationFolderSetting> ExportFolderSettings
52 get {
return _exportFolderSettings; }
55 public ILanguageVariant LanguageVariant {
get;
private set; }
56 public IProjectVariant ProjectVariant {
get;
private set; }
58 public IPublicationPackage PublicationPackage {
get {
return _publicationSettings.PublicationPackage; } }
60 public IEnumerable<IPublicationTarget> PublishingTargets
62 get {
return _publishingTargets.ToList(); }
65 public void SetPublishingTargetsAndCommit(List<IPublicationTarget> newTargets)
67 const string SAVE_EXPORT_TARGETS =
68 @"<PROJECT><EXPORTSETTING guid=""{0}""><EXPORTTARGETS action=""save"">{1}</EXPORTTARGETS></EXPORTSETTING></PROJECT>";
69 const string SINGLE_EXPORT_TARGET =
@"<EXPORTTARGET guid=""{0}"" selected=""{1}"" />";
71 string targets = newTargets.Aggregate(
"",
72 (current, curTarget) =>
74 string.Format(SINGLE_EXPORT_TARGET, curTarget.Guid.ToRQLString(),
"1"));
75 string removeTargets = _publishingTargets.Where(x => newTargets.All(y => y.Guid != x.Guid))
77 (current, curTarget) =>
79 string.Format(SINGLE_EXPORT_TARGET,
80 curTarget.Guid.ToRQLString(),
"0"));
83 PublicationPackage.Project.ExecuteRQL(
string.Format(SAVE_EXPORT_TARGETS, Guid.ToRQLString(),
84 targets + removeTargets));
86 if (!xmlDoc.InnerXml.Contains(
"ok"))
89 string.Format(
"Could not set publishing targets for {0}",
this));
91 _exportFolderSettings.InvalidateCache();
94 private List<IPublicationFolderSetting> LoadExportFolderSettings()
96 const string LIST_EXPORT_FOLDER_SETTINGS =
97 @"<TREESEGMENT type=""project.1710"" action=""load"" guid=""{0}"" descent=""project"" parentguid=""{1}""/>";
99 PublicationPackage.Project.ExecuteRQL(
string.Format(LIST_EXPORT_FOLDER_SETTINGS, Guid.ToRQLString(),
100 PublicationPackage.Guid.ToRQLString()));
102 return (from XmlElement curSegment in xmlDoc.GetElementsByTagName(
"SEGMENT")
104 (IPublicationFolderSetting)
105 new PublicationFolderSetting(this, curSegment.GetGuid())
107 Name = curSegment.GetAttributeValue(
"value")
111 private void LoadXml()
113 ProjectVariant = ProjectVariantFactory.CreateFromGuid(PublicationPackage.Project,
114 _xmlElement.GetGuid(
"projectvariantguid"));
116 _name = _xmlElement.GetAttributeValue(
"projectvariantname") +
"/" +
117 _xmlElement.GetAttributeValue(
"languagevariantname");
119 PublicationPackage.Project.LanguageVariants.GetByGuid(_xmlElement.GetGuid(
"languagevariantguid"));
120 XmlNodeList exportTargets = (XmlElement).GetElementsByTagName(
"EXPORTTARGET");
121 _publishingTargets = (from XmlElement curTarget in exportTargets
122 select (IPublicationTarget) new PublicationTarget(Project, curTarget.GetGuid()))
128 const string DELETE =
@"<PROJECT><EXPORTSETTING action=""deletesetting"" packetguid=""{0}"" guid=""{1}""/></PROJECT>";
129 Project.ExecuteRQL(DELETE.RQLFormat(PublicationPackage,
this));
131 _publicationSettings.InvalidateCache();