SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IFolders.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.Collections.Generic;
18 using System.Linq;
19 using System.Xml;
20 using erminas.SmartAPI.CMS.Project.Folder;
21 using erminas.SmartAPI.CMS.Project.Publication;
22 using erminas.SmartAPI.Utils;
23 using erminas.SmartAPI.Utils.CachedCollections;
24 
25 namespace erminas.SmartAPI.CMS.Project
26 {
27  //public interface IFolders : IIndexedRDList<string, IFolder>, IProjectObject
28  //{
29  // IEnumerable<IFolder> ForAssetManager();
30  //}
31 
32  //internal class Folders : NameIndexedRDList<IFolder>, IFolders
33  //{
34  // private readonly IProject _project;
35 
36  // internal Folders(IProject project, Caching caching) : base(caching)
37  // {
38  // _project = project;
39  // RetrieveFunc = GetFolders;
40  // }
41 
42  // public IEnumerable<IFolder> ForAssetManager()
43  // {
44  // return this.Where(folder => folder.IsAssetManagerFolder).ToList();
45  // }
46 
47  // public IProject Project
48  // {
49  // get { return _project; }
50  // }
51 
52  // public ISession Session
53  // {
54  // get { return _project.Session; }
55  // }
56 
57  // private List<IFolder> GetFolders()
58  // {
59  // const string LIST_FILE_FOLDERS =
60  // @"<PROJECT><FOLDERS action=""list"" foldertype=""0"" withsubfolders=""1""/></PROJECT>";
61  // var xmlDoc = Project.ExecuteRQL(LIST_FILE_FOLDERS);
62 
63  // return
64  // (from XmlElement curNode in xmlDoc.GetElementsByTagName("FOLDER")
65  // select (IFolder) new Folder(Project, curNode)).ToList();
66  // }
67  //}
68 
69  public interface IFolders : IIndexedRDList<string, IFolder>, IProjectObject
70  {
71  IRDEnumerable<IFolder> AllIncludingSubFolders { get; }
72  IRDEnumerable<IAssetManagerFolder> AssetManagerFolders { get; }
73  void CreateFolder(DatabaseAssetFolderConfiguration config);
74  }
75 
76  public abstract class AssetFolderConfiguration
77  {
78  public AssetFolderConfiguration(string name)
79  {
80  Name = name;
81  }
82 
83  public bool AreAttributesMandatory { get; set; }
84  public string Description { get; set; }
85  public bool IsFolderNotAvailableInEditor { get; set; }
86  public bool IsPublishingPersonalizationAttributes { get; set; }
87  public int MaximumNumberOfAssetsDisplayed { get; set; }
88  public string Name { get; set; }
89  public IPublicationFolder PublicationFolder { get; set; }
90  }
91 
93  {
94  public DatabaseAssetFolderConfiguration(string name) : base(name)
95  {
96  }
97  }
98 
100  {
101  public FileAssetFolderConfiguration(string folderName, string path) : base(folderName)
102  {
103  Path = path;
104  }
105 
106  public bool IsTransmittingCredentials { get; set; }
107  public bool IsVersioningActive { get; set; }
108  public string Path { get; set; }
109 
110  public string UserName { get; set; }
111  public string UserPassword { get; set; }
112  }
113 
114  internal class Folders : NameIndexedRDList<IFolder>, IFolders
115  {
116  private readonly IProject _project;
117 
118  internal Folders(IProject project, Caching caching) : base(caching)
119  {
120  _project = project;
121  RetrieveFunc = GetFolders;
122  }
123 
124  public IRDEnumerable<IFolder> AllIncludingSubFolders
125  {
126  get
127  {
128  return
129  this.Union(
130  this.Where(folder => folder is IAssetManagerFolder)
131  .Cast<IAssetManagerFolder>()
132  .SelectMany(folder => folder.SubFolders)).ToRDEnumerable();
133  }
134  }
135 
136  public IRDEnumerable<IAssetManagerFolder> AssetManagerFolders
137  {
138  get { return this.Where(folder => folder is IAssetManagerFolder).Cast<IAssetManagerFolder>().ToRDEnumerable(); }
139  }
140 
141  public void CreateFolder(DatabaseAssetFolderConfiguration config)
142  {
143  const string CREATE_FOLDER =
144  @"<PROJECT><FOLDER shared=""0"" name=""{0}"" description=""{1}"" foldertype=""0"" catalog=""1"" savetype=""0"" action=""addnew"" webfolder=""{2}"" exportfolder="""" obligatoryattributes=""{3}"" personalization=""{4}"" maxlistcount=""{5}"" hideintexteditor=""{6}""></FOLDER></PROJECT>";
145 
146  Project.ExecuteRQL(CREATE_FOLDER.SecureRQLFormat(config.Name, config.Description, config.PublicationFolder,
147  config.AreAttributesMandatory,
148  config.IsPublishingPersonalizationAttributes,
149  config.MaximumNumberOfAssetsDisplayed,
150  config.IsFolderNotAvailableInEditor));
151  }
152 
153  public IFolder GetByGuidIncludingSubFolders(Guid folderGuid)
154  {
155  return AllIncludingSubFolders.First(folder => folder.Guid == folderGuid);
156  }
157 
158  public IProject Project
159  {
160  get { return _project; }
161  }
162 
163  public ISession Session
164  {
165  get { return _project.Session; }
166  }
167 
168  public bool TryGetByGuidIncludingSubFolders(Guid folderGuid, out IFolder folder)
169  {
170  folder = AllIncludingSubFolders.FirstOrDefault(folder2 => folder2.Guid == folderGuid);
171  return folder != null;
172  }
173 
174  private List<IFolder> GetFolders()
175  {
176  const string LIST_FILE_FOLDERS = @"<PROJECT><FOLDERS action=""list"" withsubfolders=""0""/></PROJECT>";
177  var xmlDoc = Project.ExecuteRQL(LIST_FILE_FOLDERS);
178 
179  return (from XmlElement curNode in xmlDoc.GetElementsByTagName("FOLDER")
180  where InternalFolderFactory.HasSupportedFolderType(curNode)
181  select InternalFolderFactory.CreateFolder(_project, curNode)).ToList();
182  }
183  }
184 }