SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IAssetManagerFolder.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.Xml;
17 using erminas.SmartAPI.Exceptions;
18 using erminas.SmartAPI.Utils;
19 using erminas.SmartAPI.Utils.CachedCollections;
20 
21 namespace erminas.SmartAPI.CMS.Project.Folder
22 {
23  internal class AssetManagerFolder : BaseFolder, IAssetManagerFolder
24  {
25  private readonly IAssetManagerFolder _parentFolder;
26 
27  public AssetManagerFolder(IProject project, XmlElement xmlElement) : base(project, xmlElement)
28  {
29  _parentFolder = null;
30  SubFolders = new SubFolders(this, Caching.Enabled);
31  Files = new AssetManagerFiles(this, Caching.Enabled);
32  }
33 
34  public AssetManagerFolder(IAssetManagerFolder parentFolder, XmlElement xmlElement)
35  : base(parentFolder.Project, xmlElement)
36  {
37  _parentFolder = parentFolder;
38  SubFolders = new EmptySubFolders(this);
39  Files = new AssetManagerFiles(this, Caching.Enabled);
40  }
41 
42  public void CreateSubfolder(string name, string description, string filesystemDirectoryName)
43  {
44  if (ParentFolder != null)
45  {
46  throw new SmartAPIException(Session.ServerLogin,
47  string.Format("Can not create subfolder in another subfolder ({0}).", this));
48  }
49 
50  const string CREATE_SUBFOLDER =
51  @"<FOLDER guid=""{0}""><SUBFOLDER action=""addnew"" name=""{1}"" dirname=""{2}"" description=""{3}"" /></FOLDER>";
52 
53  Project.ExecuteRQL(CREATE_SUBFOLDER.SecureRQLFormat(this, name, filesystemDirectoryName, description));
54  }
55 
56  public new IAssetManagerFiles Files
57  {
58  get { return (IAssetManagerFiles) base.Files; }
59  private set { base.Files = value; }
60  }
61 
62  public override bool IsAssetManager
63  {
64  get { return true; }
65  }
66 
67  public bool IsDatabaseFolder
68  {
69  get { return StorageType == AssetManagerFolderStorageType.Database; }
70  }
71 
72  public bool IsFileSystemFolder
73  {
74  get { return StorageType == AssetManagerFolderStorageType.FileSystem; }
75  }
76 
77  public bool IsSubFolder
78  {
79  get { return _parentFolder != null; }
80  }
81 
82  public IAssetManagerFolder ParentFolder
83  {
84  get { return _parentFolder; }
85  }
86 
87  public AssetManagerFolderStorageType StorageType
88  {
89  get { return (AssetManagerFolderStorageType) XmlElement.GetIntAttributeValue("savetype").GetValueOrDefault(); }
90  }
91 
92  public ISubFolders SubFolders { get; private set; }
93 
94  public override FolderType Type
95  {
96  get { return FolderType.AssetManager; }
97  }
98  }
99 
101  {
102  Database = 0,
103  FileSystem = 2
104  }
105 
106  public interface IAssetManagerFolder : IFolder
107  {
108  void CreateSubfolder(string name, string description, string filesystemDirectoryName);
109  new IAssetManagerFiles Files { get; }
110  bool IsDatabaseFolder { get; }
111  bool IsFileSystemFolder { get; }
112  bool IsSubFolder { get; }
113  IAssetManagerFolder ParentFolder { get; }
114  AssetManagerFolderStorageType StorageType { get; }
115  ISubFolders SubFolders { get; }
116  }
117 }