17 using System.Collections.Generic;
18 using System.Collections.ObjectModel;
20 using System.Security;
21 using erminas.SmartAPI.CMS.ServerManagement;
22 using erminas.SmartAPI.Exceptions;
23 using erminas.SmartAPI.Utils;
24 using erminas.SmartAPI.Utils.CachedCollections;
26 namespace erminas.SmartAPI.CMS.Project.Folder
43 ReadOnlyCollection<IFile> GetByAuthor(
IUser user);
44 ReadOnlyCollection<IFile> GetByLastModifier(
IUser user);
45 void UpdateThumbnailAndFileInformation(
string filename);
46 void UpdateThumbnailAndFileInformationForAll();
47 void UpdateThumbnailAndFileInformationRange(IEnumerable<string> filenames);
50 internal class AssetManagerFiles : Files, IAssetManagerFiles
52 internal AssetManagerFiles(IAssetManagerFolder folder,
Caching caching) : base(folder, caching)
54 RetrieveFunc = GetFiles;
57 public new IAssetManagerFolder Folder
59 get {
return (IAssetManagerFolder) base.Folder; }
62 [VersionIsGreaterThanOrEqual(10, VersionName =
"Version 10")]
66 VersionVerifier.EnsureVersion(Session);
68 const string FILTER_FILES_BY_COMMAND =
69 @"<MEDIA><FOLDER guid=""{0}"" subdirguid=""{0}""><FILES action=""list"" view=""thumbnail"" sectioncount=""30"" maxfilesize=""0"" command=""{1}"" op=""{2}"" value=""{3}"" startcount=""1"" orderby=""name""/></FOLDER></MEDIA>";
71 var rqlString = FILTER_FILES_BY_COMMAND.RQLFormat(Folder, ComparisonAttributeToString(attribute),
72 ComparisonOperatorToString(@
operator), value);
73 return RetrieveFiles(rqlString).AsReadOnly();
76 public ReadOnlyCollection<IFile> GetByAuthor(
IUser author)
78 const string FILTER_FILES_BY_CREATOR =
79 @"<MEDIA><FOLDER guid=""{0}"" subdirguid=""{0}""><FILES action=""list"" view=""thumbnail"" maxfilesize=""0"" createguid=""{1}"" pattern="""" startcount=""1"" orderby=""name""/></FOLDER></MEDIA>";
81 var query = FILTER_FILES_BY_CREATOR.RQLFormat(Folder, author);
82 return RetrieveFiles(query).AsReadOnly();
85 public ReadOnlyCollection<IFile> GetByLastModifier(
IUser lastModifier)
87 const string FILTER_FILES_BY_CHANGEAUTHOR =
88 @"<MEDIA><FOLDER guid=""{0}"" subdirguid=""{0}""><FILES action=""list"" view=""thumbnail"" maxfilesize=""0"" changeguid=""{1}"" pattern="""" startcount=""1"" orderby=""name""/></FOLDER></MEDIA>";
90 var query = FILTER_FILES_BY_CHANGEAUTHOR.RQLFormat(Folder, lastModifier);
91 return RetrieveFiles(query).AsReadOnly();
94 public void UpdateThumbnailAndFileInformation(
string filename)
96 UpdateThumbnailAndFileInformationRange(
new[] {filename});
99 public void UpdateThumbnailAndFileInformationForAll()
101 UpdateThumbnailAndFileInformationRange(this.Select(file => file.Name));
104 public void UpdateThumbnailAndFileInformationRange(IEnumerable<string> filenames)
106 const string FILE_TO_UPDATE =
@"<FILE action=""update"" sourcename=""{0}"" tempdir=""{1}""/>";
108 var enumerable = filenames as IList<string> ?? filenames.ToList();
112 FILE_TO_UPDATE.SecureRQLFormat(s, Session.ServerManager.ApplicationServers.Current.TempDirectoryPath));
113 var files =
string.Join(
string.Empty, rqlFiles);
115 const string UPDATE_FILES_IN_FOLDER =
@"<MEDIA><FOLDER guid=""{0}"">{1}</FOLDER></MEDIA>";
116 var xmlDoc = Project.ExecuteRQL(UPDATE_FILES_IN_FOLDER.RQLFormat(Folder, files));
117 if (xmlDoc.GetElementsByTagName(
"THUMB").Count == 0)
121 "Could not update thumbnails/file information in folder {0} on: {1}",
122 Folder,
string.Join(
", ", enumerable)));
126 protected override string GetDeleteFilesStatement(
string files)
128 const string DELETE_FILES =
129 @"<MEDIA loginguid=""{0}""><FOLDER guid=""{1}"" subdirguid=""{1}"" tempdir=""{2}{0}\""><FILES action=""deletefiles"">{3}</FILES></FOLDER></MEDIA>";
131 return DELETE_FILES.RQLFormat(Session.LogonGuid, Folder,
132 SecurityElement.Escape(
133 Session.ServerManager.ApplicationServers.Current.TempDirectoryPath), files);
136 protected override string GetSingleFilenameTemplate()
138 return @"<FILE sourcename=""{0}"" deletereal=""1"" languagevariantid=""" +
139 Project.LanguageVariants.Main.Abbreviation +
@"""/>";
155 throw new ArgumentException(
string.Format(
"Unknown file attribute: {0}", attribute));
174 throw new ArgumentException(
string.Format(
"Unknown comparison operator: {0}", @
operator));
178 private List<IFile> GetFiles()
180 const string LIST_FILES =
181 @"<MEDIA><FOLDER guid=""{0}"" subdirguid=""{0}""><FILES action=""list"" view=""thumbnail"" maxfilesize=""0"" attributeguid="""" searchtext=""*"" pattern="""" startcount=""1"" orderby=""name""/></FOLDER></MEDIA>";
183 return RetrieveFiles(LIST_FILES.RQLFormat(Folder));