17 using System.Collections.Generic;
20 using erminas.SmartAPI.CMS.Project.ContentClasses;
21 using erminas.SmartAPI.Exceptions;
22 using erminas.SmartAPI.Utils;
23 using erminas.SmartAPI.Utils.CachedCollections;
25 namespace erminas.SmartAPI.CMS.Project.Folder
32 IIndexedRDList<string, IContentClass> ContentClasses {
get; }
34 bool IsBroken {
get; }
36 bool IsSharedToOtherProjects {
get; }
44 internal sealed
class ContentClassFolder : RedDotProjectObject, IContentClassFolder
47 private Lazy<IContentClassFolder> _sharedFrom;
49 internal ContentClassFolder(
IProject project, Guid guid) : base(project, guid)
54 internal ContentClassFolder(IProject project, XmlElement xmlElement) : base(project, xmlElement)
62 public IIndexedRDList<string, IContentClass> ContentClasses {
get;
private set; }
64 public bool IsBroken {
get;
internal set; }
66 public bool IsSharedToOtherProjects
68 get {
return SharedTo.Any(); }
71 public IContentClassFolder SharedFrom
73 get {
return _sharedFrom.Value; }
76 public IContentClassFolderSharing SharedTo {
get;
private set; }
78 private List<IContentClass> GetContentClasses()
82 const string LIST_CC_OF_FOLDER =
@"<TEMPLATES folderguid=""{0}"" action=""list""/>";
84 XMLDoc = _project.ExecuteRQL(
string.Format(LIST_CC_OF_FOLDER, Guid.ToRQLString()));
86 return (from XmlElement curNode in XMLDoc.GetElementsByTagName(
"TEMPLATE")
87 select (
IContentClass) new ContentClass(_project, curNode)).ToList();
90 private IContentClassFolder GetSharedFrom()
92 const string LOAD_FOLDER =
@"<PROJECT><FOLDER action=""load"" guid=""{0}""/></PROJECT>";
93 var xmlDoc = Project.ExecuteRQL(LOAD_FOLDER.RQLFormat(
this));
94 XmlElement = xmlDoc.GetSingleElement(
"FOLDER");
95 Guid sharedProjectGuid, sharedFolderGuid;
96 if (XmlElement.TryGetGuid(
"linkedprojectguid", out sharedProjectGuid) &&
97 XmlElement.TryGetGuid(
"linkedfolderguid", out sharedFolderGuid))
104 if (Session.CurrentUser.ModuleAssignment.IsServerManager)
106 IProject project = Session.ServerManager.Projects.GetByGuid(sharedProjectGuid);
107 return GetSharedFromFolder(project, sharedFolderGuid);
109 if (Session.ServerManager.Projects.ForCurrentUser.ContainsGuid(sharedProjectGuid))
111 IProject project = Session.ServerManager.Projects.ForCurrentUser.GetByGuid(sharedProjectGuid);
112 return GetSharedFromFolder(project, sharedFolderGuid);
114 var sharedProject =
new Project(Session, sharedProjectGuid);
115 return new ContentClassFolder(sharedProject, sharedFolderGuid);
120 private static IContentClassFolder GetSharedFromFolder(IProject project, Guid sharedFolderGuid)
123 project.ContentClassFolders.Union(project.ContentClassFolders.Broken)
124 .First(x => x.Guid == sharedFolderGuid);
127 private void Init(IProject project)
129 ContentClasses =
new NameIndexedRDList<IContentClass>(GetContentClasses,
Caching.Enabled);
130 SharedTo =
new ContentClassFolderSharing(
this,
Caching.Enabled);
132 _sharedFrom =
new Lazy<IContentClassFolder>(GetSharedFrom);