SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IPublicationFolderSetting.cs
Go to the documentation of this file.
1 ï»¿// SmartAPI - .Net programmatic access to RedDot servers
2 //
3 // Copyright (C) 2013 erminas GbR
4 //
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free Software Foundation,
7 // either version 3 of the License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 // See the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program.
14 // If not, see <http://www.gnu.org/licenses/>.
15 
16 using System;
17 using System.Xml;
18 using erminas.SmartAPI.Exceptions;
19 using erminas.SmartAPI.Utils;
20 
21 namespace erminas.SmartAPI.CMS.Project.Publication
22 {
24  {
25  void Commit();
26  IPublicationFolder PublicationFolder { get; set; }
27  IPublicationSetting PublicationSetting { get; set; }
28  }
29 
30  internal class PublicationFolderSetting : PartialRedDotProjectObject, IPublicationFolderSetting
31  {
32  private IPublicationFolder _publicationFolder;
33 
34  public PublicationFolderSetting(IPublicationSetting parent, Guid guid) : base(parent.Project, guid)
35  {
36  PublicationSetting = parent;
37  }
38 
39  internal PublicationFolderSetting(IPublicationSetting parent, XmlElement element)
40  : base(parent.Project, element)
41  {
42  PublicationSetting = parent;
43 
44  LoadXml();
45  }
46 
47  public void Commit()
48  {
49  const string SAVE_SETTING =
50  @"<PROJECT><EXPORTSETTING action=""save"" guid=""{0}""><FOLDEREXPORTSETTING folderguid=""{1}"" guid=""{2}""/></EXPORTSETTING></PROJECT>";
51 
52  XmlDocument xmlDoc =
53  Project.ExecuteRQL(string.Format(SAVE_SETTING, PublicationSetting.Guid.ToRQLString(),
54  _publicationFolder.Guid.ToRQLString(), Guid.ToRQLString()));
55 
56  if (!xmlDoc.IsContainingOk())
57  {
58  throw new SmartAPIException(Session.ServerLogin,
59  string.Format("Could not change publication folder setting for {0}", this));
60  }
61  }
62 
63  public IPublicationFolder PublicationFolder
64  {
65  get { return LazyLoad(ref _publicationFolder); }
66  set { _publicationFolder = value; }
67  }
68 
69  public IPublicationSetting PublicationSetting { get; set; }
70 
71  protected override void LoadWholeObject()
72  {
73  LoadXml();
74  }
75 
76  protected override XmlElement RetrieveWholeObject()
77  {
78  const string LOAD_FOLDER_SETTING =
79  @"<PROJECT><EXPORTSETTING guid=""{0}"" action=""load"" ><FOLDEREXPORTSETTING guid=""{1}""/></EXPORTSETTING></PROJECT>";
80 
81  XmlDocument xmlDoc =
82  PublicationSetting.PublicationPackage.Project.ExecuteRQL(String.Format(LOAD_FOLDER_SETTING,
83  PublicationSetting.Guid
84  .ToRQLString(),
85  Guid.ToRQLString()));
86 
87  return (XmlElement) xmlDoc.GetElementsByTagName("FOLDEREXPORTSETTING")[0];
88  }
89 
90  private void LoadXml()
91  {
92  const string FOLDER_GUID = "folderguid";
93  Guid tmpGuid;
94  _publicationFolder = _xmlElement.TryGetGuid(FOLDER_GUID, out tmpGuid)
95  ? new PublicationFolder(PublicationSetting.PublicationPackage.Project, tmpGuid)
96  : null;
97  }
98  }
99 }