18 using erminas.SmartAPI.Utils;
20 namespace erminas.SmartAPI.CMS.Project.Folder
38 Guid? ThumbnailGuid {
get; }
39 string ThumbnailPath {
get; }
42 internal class File : IFile
47 private readonly IFolder _folder;
52 private readonly
string _name;
55 private readonly Guid? _thumbnailGuid;
56 private readonly XmlElement _xmlElement;
58 internal File(
IProject project, XmlElement xmlElement)
61 _xmlElement = xmlElement;
62 _name = xmlElement.GetAttributeValue(
"name");
63 var folderGuid = xmlElement.GetGuid(
"folderguid");
66 if (_xmlElement.TryGetGuid(
"thumbguid", out guid))
68 _thumbnailGuid = guid;
70 if (IsAssetWithThumbnail)
73 ThumbnailPath = xmlElement.GetAttributeValue(
"thumbnailpath") ?? CreateThumbnailPath();
77 public File(IFolder folder,
string fileName)
79 _project = folder.Project;
84 public FileAttributes Attributes
88 const string LIST_FILE_ATTRIBUTES =
89 @"<MEDIA><FOLDER guid=""{0}""><FILE sourcename=""{1}""><FILEATTRIBUTES action=""list""/></FILE></FOLDER></MEDIA>";
91 XmlDocument xmlDoc = Project.ExecuteRQL(LIST_FILE_ATTRIBUTES.RQLFormat(_folder, _name));
93 var node = (XmlElement) xmlDoc.GetElementsByTagName(
"EXTERNALATTRIBUTES")[0];
94 return new FileAttributes(_folder, node);
101 const string DELETE_FILE =
102 "<MEDIA><FOLDER guid=\"{0}\" ><FILES action=\"deletefiles\"><FILE sourcename=\"{1}\" languagevariantid=\"ENG\" checkfolder=\"1\"/></FILES></FOLDER></MEDIA>";
104 _project.ExecuteRQL(
string.Format(DELETE_FILE, _folder.Guid.ToRQLString(), _name));
107 public override bool Equals(
object obj)
109 if (ReferenceEquals(null, obj))
113 if (ReferenceEquals(
this, obj))
117 return obj.GetType() == GetType() && Equals((File) obj);
123 public IFolder Folder
125 get {
return _folder; }
128 public override int GetHashCode()
132 return ((_folder != null ? _folder.GetHashCode() : 0)*397) ^ (_name != null ? _name.GetHashCode() : 0);
141 get {
return _name; }
144 public IProject Project
146 get {
return _project; }
149 public int ReferenceCount()
151 const string GET_REFERENCES =
152 "<PROJECT><TRANSFER action=\"checkimage\" getreferences=\"1\" sync=\"1\" folderguid=\"{0}\" filename=\"{1}\" /></PROJECT>";
154 XmlDocument xmlDoc = _project.ExecuteRQL(
string.Format(GET_REFERENCES, _folder.Guid.ToRQLString(), _name));
155 return xmlDoc.GetElementsByTagName(
"REFERENCE").Count;
158 public ISession Session
160 get {
return Project.Session; }
163 public Guid? ThumbnailGuid
165 get {
return _thumbnailGuid; }
168 public string ThumbnailPath {
get;
private set; }
170 public override string ToString()
173 if (_folder is IAssetManagerFolder)
175 var assetFolder = (IAssetManagerFolder) _folder;
176 if (assetFolder.IsSubFolder)
178 path = assetFolder.ParentFolder.Name +
"/";
181 return _folder != null ? path + _folder.Name +
"/" + Name :
"";
184 protected bool Equals(File other)
186 return Equals(_folder, other._folder) &&
string.Equals(_name, other._name);
189 private string CreateThumbnailPath()
191 return @"THUMBNAIL\{0}\{1}\{2}.JPG".RQLFormat(_project, _folder, _thumbnailGuid.Value);
194 private bool IsAssetWithThumbnail
196 get {
return _thumbnailGuid != null; }