/// <summary> /// Gets the web dav URL by WebDavTicket. /// </summary> /// <param name="ticket">The ticket.</param> /// <returns></returns> public static string GetWebDavUrl(string ticket) { string retVal = string.Empty; WebDavTicket webDavTicket = WebDavTicket.Parse(ticket); //Попытаемся определить имя файла if (String.IsNullOrEmpty(webDavTicket.AbsolutePath.FileName)) { if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_FileStorage) { FileStorageAbsolutePath fsAbsPath = webDavTicket.AbsolutePath as FileStorageAbsolutePath; if (fsAbsPath != null) { FileStorage fs = new FileStorage(); Mediachase.IBN.Business.ControlSystem.FileInfo fileInfo = fs.GetFile(fsAbsPath.UniqueId); if (fileInfo != null) { webDavTicket.AbsolutePath.FileName = fileInfo.Name; } } } else if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_MetaData) { MetaDataAbsolutePath mdAbsPath = webDavTicket.AbsolutePath as MetaDataAbsolutePath; if (mdAbsPath != null) { Mediachase.Ibn.Data.Meta.FileInfo fileInfo = new Mediachase.Ibn.Data.Meta.FileInfo(mdAbsPath.FileUID); webDavTicket.AbsolutePath.FileName = fileInfo.Name; } } else if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_MetaDataPlus) { MetaDataPlusAbsolutePath mdpAbsPath = webDavTicket.AbsolutePath as MetaDataPlusAbsolutePath; if (mdpAbsPath != null) { Mediachase.MetaDataPlus.MetaObject obj = MetaDataWrapper.LoadMetaObject(mdpAbsPath.MetaObjectId, mdpAbsPath.MetaObjectType); MetaFile mf = obj[mdpAbsPath.MetaFieldName] as MetaFile; if (mf != null) { webDavTicket.AbsolutePath.FileName = mf.Name; } } } else if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_Incident) { EmailStorageAbsolutePath emlAbsPath = webDavTicket.AbsolutePath as EmailStorageAbsolutePath; if (emlAbsPath != null) { EMailMessageInfo emlInfo = EMailMessageInfo.Load(emlAbsPath.EmailMsgId); AttachmentInfo attachInfo = emlInfo.Attachments[emlAbsPath.EmailAttachmentIndex]; webDavTicket.AbsolutePath.FileName = attachInfo.FileName; } } } retVal = GetWebDavUrl(webDavTicket.AbsolutePath, true); return(retVal); }
/// <summary> /// Opens the read. /// </summary> /// <param name="element">The element.</param> /// <returns></returns> public override System.IO.Stream OpenRead(Mediachase.Net.Wdom.WebDavElementInfo element) { if (element == null || element is CollectionInfo) { return(null); } Mediachase.Ibn.Data.Meta.FileInfo fileInfo = (Mediachase.Ibn.Data.Meta.FileInfo)element.Tag; return(fileInfo.OpenRead()); }
/// <summary> /// Gets the web dav URL. /// </summary> /// <param name="fileInfo">The file info.</param> /// <param name="withAuthToken">if set to <c>true</c> [with auth token].</param> /// <returns></returns> public static string GetMetaDataWebDavUrl(Mediachase.Ibn.Data.Meta.FileInfo fileInfo, bool withAuthToken) { if (fileInfo == null) { throw new ArgumentNullException("fileInfo"); } MetaDataAbsolutePath absPath = (MetaDataAbsolutePath)WebDavAbsolutePath.CreateInstance(ObjectTypes.File_MetaData); absPath.FileUID = fileInfo.FileUID; absPath.FileName = fileInfo.Name; return(GetWebDavUrl(absPath, withAuthToken)); }
/// <summary> /// Gets the web dav URL. /// </summary> /// <param name="property">The property.</param> /// <returns></returns> public static string GetMetaDataWebDavUrl(MetaObjectProperty property, bool withAuthToken) { if (property == null) { throw new ArgumentNullException("property"); } Mediachase.Ibn.Data.Meta.FileInfo fileInfo = property.Value as Mediachase.Ibn.Data.Meta.FileInfo; if (fileInfo == null) { throw new ArgumentException("metaproperty " + property.Name + " is not a FileInfo type"); } return(GetMetaDataWebDavUrl(fileInfo, withAuthToken)); }
/// <summary> /// Opens the write. /// </summary> /// <param name="element">The element.</param> /// <returns></returns> public override System.IO.Stream OpenWrite(Mediachase.Net.Wdom.WebDavElementInfo element, long contentLength) { if (element == null || element is CollectionInfo) { return(null); } Mediachase.Ibn.Data.Meta.FileInfo fileInfo = (Mediachase.Ibn.Data.Meta.FileInfo)element.Tag; try { AutoCommitedTransactedStream tranStream = new AutoCommitedTransactedStream(DataContext.Current.BeginTransaction(), contentLength); tranStream.InnerStream = fileInfo.OpenWrite(); tranStream.SetLength(0); return(tranStream); } catch (Exception) { throw new HttpException(404, "Not Found"); } }
protected override ResourceInfo GetResourceInfo(WebDavTicket ticket) { MetaDataAbsolutePath metaAbsPath = ticket.AbsolutePath as MetaDataAbsolutePath; if (metaAbsPath == null) { throw new ArgumentException("absPath"); } ResourceInfo retVal = new ResourceInfo(); Mediachase.Ibn.Data.Meta.FileInfo fileInfo = new Mediachase.Ibn.Data.Meta.FileInfo(metaAbsPath.FileUID); retVal.AbsolutePath = ticket.ToString(); retVal.Tag = fileInfo; retVal.Name = fileInfo.Name; retVal.ContentType = ContentTypeResolver.Resolve(Path.GetExtension(fileInfo.Name)); retVal.ContentLength = fileInfo.Length; retVal.ParentName = "root"; retVal.Modified = DateTime.Now; retVal.Created = DateTime.Now; return(retVal); }
/// <summary> /// Gets the web dav URL. /// </summary> /// <param name="fileUID">The file UID.</param> /// <param name="withAuthToken">if set to <c>true</c> [with auth token].</param> /// <returns></returns> public static string GetMetaDataWebDavUrl(Guid fileUID, bool withAuthToken) { Mediachase.Ibn.Data.Meta.FileInfo fileInfo = new Mediachase.Ibn.Data.Meta.FileInfo(fileUID); return(GetMetaDataWebDavUrl(fileInfo, withAuthToken)); }
/// <summary> /// Gets the web dav URL by WebDavTicket. /// </summary> /// <param name="ticket">The ticket.</param> /// <returns></returns> public static string GetWebDavUrl(string ticket) { string retVal = string.Empty; WebDavTicket webDavTicket = WebDavTicket.Parse(ticket); //Попытаемся определить имя файла if (String.IsNullOrEmpty(webDavTicket.AbsolutePath.FileName)) { if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_FileStorage) { FileStorageAbsolutePath fsAbsPath = webDavTicket.AbsolutePath as FileStorageAbsolutePath; if (fsAbsPath != null) { FileStorage fs = new FileStorage(); Mediachase.IBN.Business.ControlSystem.FileInfo fileInfo = fs.GetFile(fsAbsPath.UniqueId); if (fileInfo != null) { webDavTicket.AbsolutePath.FileName = fileInfo.Name; } } } else if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_MetaData) { MetaDataAbsolutePath mdAbsPath = webDavTicket.AbsolutePath as MetaDataAbsolutePath; if (mdAbsPath != null) { Mediachase.Ibn.Data.Meta.FileInfo fileInfo = new Mediachase.Ibn.Data.Meta.FileInfo(mdAbsPath.FileUID); webDavTicket.AbsolutePath.FileName = fileInfo.Name; } } else if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_MetaDataPlus) { MetaDataPlusAbsolutePath mdpAbsPath = webDavTicket.AbsolutePath as MetaDataPlusAbsolutePath; if (mdpAbsPath != null) { Mediachase.MetaDataPlus.MetaObject obj = MetaDataWrapper.LoadMetaObject(mdpAbsPath.MetaObjectId, mdpAbsPath.MetaObjectType); MetaFile mf = obj[mdpAbsPath.MetaFieldName] as MetaFile; if (mf != null) { webDavTicket.AbsolutePath.FileName = mf.Name; } } } else if (webDavTicket.AbsolutePath.StorageType == ObjectTypes.File_Incident) { EmailStorageAbsolutePath emlAbsPath = webDavTicket.AbsolutePath as EmailStorageAbsolutePath; if (emlAbsPath != null) { EMailMessageInfo emlInfo = EMailMessageInfo.Load(emlAbsPath.EmailMsgId); AttachmentInfo attachInfo = emlInfo.Attachments[emlAbsPath.EmailAttachmentIndex]; webDavTicket.AbsolutePath.FileName = attachInfo.FileName; } } } retVal = GetWebDavUrl(webDavTicket.AbsolutePath, true); return retVal; }
/// <summary> /// Gets the web dav URL. /// </summary> /// <param name="fileUID">The file UID.</param> /// <param name="withAuthToken">if set to <c>true</c> [with auth token].</param> /// <returns></returns> public static string GetMetaDataWebDavUrl(Guid fileUID, bool withAuthToken) { Mediachase.Ibn.Data.Meta.FileInfo fileInfo = new Mediachase.Ibn.Data.Meta.FileInfo(fileUID); return GetMetaDataWebDavUrl(fileInfo, withAuthToken); }
protected override ResourceInfo GetResourceInfo(WebDavTicket ticket) { MetaDataAbsolutePath metaAbsPath = ticket.AbsolutePath as MetaDataAbsolutePath; if (metaAbsPath == null) throw new ArgumentException("absPath"); ResourceInfo retVal = new ResourceInfo(); Mediachase.Ibn.Data.Meta.FileInfo fileInfo = new Mediachase.Ibn.Data.Meta.FileInfo(metaAbsPath.FileUID); retVal.AbsolutePath = ticket.ToString(); retVal.Tag = fileInfo; retVal.Name = fileInfo.Name; retVal.ContentType = ContentTypeResolver.Resolve(Path.GetExtension(fileInfo.Name)); retVal.ContentLength = fileInfo.Length; retVal.ParentName = "root"; retVal.Modified = DateTime.Now; retVal.Created = DateTime.Now; return retVal; }