SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IPublicationSettings.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 using System.Linq;
3 using System.Xml;
4 using erminas.SmartAPI.Utils;
5 using erminas.SmartAPI.Utils.CachedCollections;
6 
7 namespace erminas.SmartAPI.CMS.Project.Publication
8 {
9  public interface IPublicationSettings : ICachedList<IPublicationSetting>, IProjectObject
10  {
11  IPublicationPackage PublicationPackage { get; }
12 
13  void Add(IProjectVariant projectVariant, ILanguageVariant languageVariant);
14 
15  void Remove(IProjectVariant projectVariant, ILanguageVariant languageVariant);
16  }
17 
18  internal class PublicationSettings : CachedList<IPublicationSetting>, IPublicationSettings
19  {
20  internal PublicationSettings(IPublicationPackage publicationPackage, Caching caching = Caching.Enabled) : base(caching)
21  {
22  PublicationPackage = publicationPackage;
23  RetrieveFunc = GetPublicationSettings;
24  }
25 
26  public IPublicationPackage PublicationPackage { get; private set; }
27 
28  public ISession Session
29  {
30  get { return PublicationPackage.Session; }
31  }
32 
33  public IProject Project
34  {
35  get { return PublicationPackage.Project; }
36  }
37 
38  public void Add(IProjectVariant projectVariant, ILanguageVariant languageVariant)
39  {
40  const string ADD =
41  @"<PROJECT><EXPORTSETTING action=""save"" guid=""{0}"" projectvariantguid=""{1}"" languagevariantguid=""{2}"" copyguid="""" /></PROJECT>";
42 
43  var doc = Project.ExecuteRQL(ADD.RQLFormat(PublicationPackage, projectVariant, languageVariant.Guid.ToRQLString()));
44  //TODO check answer?
45 
46  InvalidateCache();
47  }
48 
49  public void Remove(IProjectVariant projectVariant, ILanguageVariant languageVariant)
50  {
51  var entry =
52  this.FirstOrDefault(x => x.ProjectVariant.Guid == projectVariant.Guid && x.LanguageVariant.Guid == languageVariant.Guid);
53  if (entry != null)
54  {
55  entry.Delete();
56  }
57  }
58 
59  private List<IPublicationSetting> GetPublicationSettings()
60  {
61  const string LOAD_PUBLICATION_PACKAGE = @"<PROJECT><EXPORTPACKET action=""loadpacket"" guid=""{0}"" /></PROJECT>";
62  XmlDocument xmlDoc = Project.ExecuteRQL(LOAD_PUBLICATION_PACKAGE.RQLFormat(PublicationPackage));
63 
64  return (from XmlElement curSetting in xmlDoc.GetElementsByTagName("EXPORTSETTING")
65  select (IPublicationSetting) new PublicationSetting(this, curSetting)).ToList();
66  }
67  }
68 }