16 using System.Collections.Generic;
19 using erminas.SmartAPI.Utils;
20 using erminas.SmartAPI.Utils.CachedCollections;
22 namespace erminas.SmartAPI.CMS.Project.Folder
24 internal class ContentClassFolderSharing : NameIndexedRDList<IProject>, IContentClassFolderSharing
26 private const string SHARING =
27 @"<SHAREDFOLDER shared=""{0}"" action=""save"" guid=""{1}"" ><PROJECTS>{2}</PROJECTS></SHAREDFOLDER>";
29 private const string SINGLE_PROJECT =
@"<PROJECT guid=""{0}"" sharedrights=""{1}"" />";
30 private readonly ContentClassFolder _contentClassFolder;
32 internal ContentClassFolderSharing(ContentClassFolder contentClassFolder,
Caching caching) : base(caching)
34 _contentClassFolder = contentClassFolder;
35 RetrieveFunc = GetSharedToProjects;
38 public void Add(IProject project)
40 AddRange(
new[] {project});
43 public void AddRange(IEnumerable<IProject> projects)
45 const bool IS_SHARED =
true;
46 var projectsRql = projects.Aggregate(
"", (s, project) => s + SINGLE_PROJECT.RQLFormat(project, IS_SHARED));
48 var query = SHARING.RQLFormat(IS_SHARED, _contentClassFolder, projectsRql);
49 Project.ExecuteRQL(query,
RqlType.SessionKeyInProject);
54 public IContentClassFolder ContentClassFolder
56 get {
return _contentClassFolder; }
59 public IProject Project
61 get {
return _contentClassFolder.Project; }
64 public void Remove(IProject project)
66 var isStillSharing = Count > 1 || (Count == 1 && !this.First().Equals(project));
68 SHARING.RQLFormat(isStillSharing, _contentClassFolder, SINGLE_PROJECT.RQLFormat(project, 0)),
74 public ISession Session
76 get {
return _contentClassFolder.Session; }
79 private List<IProject> GetSharedToProjects()
81 const string LOAD_SHARED =
@"<SHAREDFOLDER action=""load"" guid=""{0}""/>";
83 var xmlDoc = Project.ExecuteRQL(LOAD_SHARED.RQLFormat(_contentClassFolder),
RqlType.SessionKeyInProject);
84 var projectNodes = xmlDoc.SelectNodes(
"//PROJECT[@sharedrights=1]");
87 if (Session.CurrentUser.ModuleAssignment.IsServerManager)
90 (from XmlElement curProject in projectNodes
91 select Session.ServerManager.Projects.GetByGuid(curProject.GetGuid())).ToList();
94 return (from XmlElement curProject in projectNodes
95 select (IProject)
new Project(Session, curProject.GetGuid()) {Name = curProject.GetName()}).ToList();
102 void AddRange(IEnumerable<IProject> project);