SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IFolder.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 using erminas.SmartAPI.Utils.CachedCollections;
21 
22 namespace erminas.SmartAPI.CMS.Project.Folder
23 {
24  public enum FolderType
25  {
26  FileFolder,
27  AssetManager,
28  DotNet,
29  StyleSheet,
30  ExternalApplication
31  }
32 
34  {
35  IFiles Files { get; }
36  bool IsAssetManager { get; }
37  bool IsFileFolder { get; }
38  IFolder LinkedFolder { get; }
39  FolderType Type { get; }
40  }
41 
42  internal static class InternalFolderFactory
43  {
44  public static bool HasSupportedFolderType(XmlElement element)
45  {
46  var folderType = element.GetIntAttributeValue("foldertype");
47  if (!folderType.HasValue)
48  {
49  return false;
50  }
51 
52  switch (folderType)
53  {
54  case 0:
55  return true;
56  default:
57  return false;
58  }
59  }
60 
61  internal static IFolder CreateFolder(IProject project, XmlElement element)
62  {
63  var folderType = element.GetIntAttributeValue("foldertype");
64  if (!folderType.HasValue)
65  {
66  throw new SmartAPIException(project.Session.ServerLogin, "Could not load folder information");
67  }
68  switch (folderType.Value)
69  {
70  case 0:
71  var isAssetManagerFolder = element.GetBoolAttributeValue("catalog").GetValueOrDefault();
72  if (!isAssetManagerFolder)
73  {
74  return new FileFolder(project, element);
75  }
76  return new AssetManagerFolder(project, element);
77  default:
78  throw new SmartAPIInternalException(string.Format("Unsupported folder type: {0}", folderType));
79  }
80  }
81  }
82 
83  internal abstract class BaseFolder : PartialRedDotProjectObject, IFolder
84  {
85  private IFolder _linkedFolder;
86 
87  internal BaseFolder(IProject project, XmlElement xmlElement) : base(project, xmlElement)
88  {
89  Files = new Files(this, Caching.Enabled);
90  LoadXml();
91  }
92 
93  internal BaseFolder(IProject project, Guid guid) : base(project, guid)
94  {
95  Files = new Files(this, Caching.Enabled);
96  }
97 
98  public void Delete()
99  {
100  const string DELETE = @"<PROJECT><FOLDER action=""delete"" guid=""{0}""/></PROJECT>";
101  Project.ExecuteRQL(DELETE.RQLFormat(this));
102  }
103 
104  public IFiles Files { get; protected set; }
105 
106  public virtual bool IsAssetManager
107  {
108  get { return false; }
109  }
110 
111  public bool IsFileFolder
112  {
113  get { return Type == FolderType.FileFolder; }
114  }
115 
116  public IFolder LinkedFolder
117  {
118  get { return LazyLoad(ref _linkedFolder); }
119  }
120 
121  public abstract FolderType Type { get; }
122 
123  protected override void LoadWholeObject()
124  {
125  LoadXml();
126  }
127 
128  protected override XmlElement RetrieveWholeObject()
129  {
130  const string LOAD_FOLDER = @"<PROJECT><FOLDER action=""load"" guid=""{0}""/></PROJECT>";
131  return Project.ExecuteRQL(LOAD_FOLDER.RQLFormat(this)).GetSingleElement("FOLDER");
132  }
133 
134  private void LoadXml()
135  {
136  Guid linkedProjectGuid;
137  if (_xmlElement.TryGetGuid("linkedprojectguid", out linkedProjectGuid))
138  {
139  var project = Project.Session.ServerManager.Projects.GetByGuid(linkedProjectGuid);
140 
141  // project could be null if the linked project is not available (broken folder)
142  // in that case do not try to set the linked folder
143  if (project != null)
144  {
145  var linkedFolderGuid = _xmlElement.GetGuid("linkedfolderguid");
146  _linkedFolder = project.Folders.AllIncludingSubFolders.GetByGuid(linkedFolderGuid);
147  }
148  }
149  }
150  }
151 
152  internal class FileFolder : BaseFolder
153  {
154  public FileFolder(IProject project, XmlElement xmlElement) : base(project, xmlElement)
155  {
156  }
157 
158  public FileFolder(IProject project, Guid guid) : base(project, guid)
159  {
160  }
161 
162  public override FolderType Type
163  {
164  get { return FolderType.FileFolder; }
165  }
166  }
167 
169  {
170  Equal,
171  Less,
172  Greater,
173  LessEqual,
174  GreaterEqual
175  }
176 
178  {
179  Width,
180  Heigth,
181  Depth,
182  Size
183  }
184 
185  public class FileSource
186  {
187  public readonly string Directory;
188  public readonly string Filename;
189 
190  public FileSource(string filename, string directory)
191  {
192  Filename = filename;
193  Directory = directory.EndsWith("\\") ? directory : directory + "\\";
194  }
195  }
196 }