18 using erminas.SmartAPI.Exceptions;
19 using erminas.SmartAPI.Utils;
20 using erminas.SmartAPI.Utils.CachedCollections;
22 namespace erminas.SmartAPI.CMS.Project.Folder
36 bool IsAssetManager {
get; }
37 bool IsFileFolder {
get; }
42 internal static class InternalFolderFactory
44 public static bool HasSupportedFolderType(XmlElement element)
46 var folderType = element.GetIntAttributeValue(
"foldertype");
47 if (!folderType.HasValue)
61 internal static IFolder CreateFolder(IProject project, XmlElement element)
63 var folderType = element.GetIntAttributeValue(
"foldertype");
64 if (!folderType.HasValue)
66 throw new SmartAPIException(project.Session.ServerLogin,
"Could not load folder information");
68 switch (folderType.Value)
71 var isAssetManagerFolder = element.GetBoolAttributeValue(
"catalog").GetValueOrDefault();
72 if (!isAssetManagerFolder)
74 return new FileFolder(project, element);
76 return new AssetManagerFolder(project, element);
83 internal abstract class BaseFolder : PartialRedDotProjectObject, IFolder
85 private IFolder _linkedFolder;
87 internal BaseFolder(IProject project, XmlElement xmlElement) : base(project, xmlElement)
89 Files =
new Files(
this,
Caching.Enabled);
93 internal BaseFolder(IProject project, Guid guid) : base(project, guid)
95 Files =
new Files(
this,
Caching.Enabled);
100 const string DELETE =
@"<PROJECT><FOLDER action=""delete"" guid=""{0}""/></PROJECT>";
101 Project.ExecuteRQL(DELETE.RQLFormat(
this));
104 public IFiles Files {
get;
protected set; }
106 public virtual bool IsAssetManager
108 get {
return false; }
111 public bool IsFileFolder
116 public IFolder LinkedFolder
118 get {
return LazyLoad(ref _linkedFolder); }
123 protected override void LoadWholeObject()
128 protected override XmlElement RetrieveWholeObject()
130 const string LOAD_FOLDER =
@"<PROJECT><FOLDER action=""load"" guid=""{0}""/></PROJECT>";
131 return Project.ExecuteRQL(LOAD_FOLDER.RQLFormat(
this)).GetSingleElement(
"FOLDER");
134 private void LoadXml()
136 Guid linkedProjectGuid;
137 if (_xmlElement.TryGetGuid(
"linkedprojectguid", out linkedProjectGuid))
139 var project = Project.Session.ServerManager.Projects.GetByGuid(linkedProjectGuid);
145 var linkedFolderGuid = _xmlElement.GetGuid(
"linkedfolderguid");
146 _linkedFolder = project.Folders.AllIncludingSubFolders.GetByGuid(linkedFolderGuid);
152 internal class FileFolder : BaseFolder
154 public FileFolder(IProject project, XmlElement xmlElement) : base(project, xmlElement)
158 public FileFolder(IProject project, Guid guid) : base(project, guid)
193 Directory = directory.EndsWith(
"\\") ? directory : directory +
"\\";