/// <summary> /// Gets the web dav ticket. /// <remarks> Получает web dav ticket is URI формата shema://PortalHost:PortalPort/[App Portal Path]?/Ticket /// т.е абсолютный путь состоит только из авбсолютного пути портала http://ibn.mediachase.ru/portals/ + ticket </remarks> /// <remarks>Абсолютный путь портала может быть взят как из конфига в случае вызова без httpContexta так и из веб контекста /// при вызове из веба</remarks> /// </summary> /// <exception cref="Exception">Incorrect URI</exception> /// <param name="uriString">The URI string.</param> /// <returns></returns> internal static WebDavTicket GetWebDavTicket(string uriString) { WebDavTicket retVal = null; ////Берем за базовый урл портала так как получить доступ к http request нет возможности //String appPath = Configuration.PortalLink; //if (HttpContext.Current != null) //{ // HttpRequest request = HttpContext.Current.Request; // //Используем HttpContext // appPath = request.ApplicationPath; // appPath = appPath.TrimEnd('/'); //} //int index = uriString.IndexOf(appPath, StringComparison.InvariantCultureIgnoreCase); //if (index != -1) //{ // //oтбрасывем общую часть, оставляем только ticket // uriString = uriString.Substring(index + appPath.Length); //} Match match = RegExpWebDavTicketFromUri.Match(uriString.Trim()); try { retVal = WebDavTicket.Parse(match.Groups["ticket"].Value); } catch (System.Exception) { throw new Exception("Incorrect URI."); } return(retVal); }
/// <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> /// Unlocks the webdav resource. /// </summary> /// <param name="resource">The resource.</param> public static void UnlockResource(int webDavElementPropertyId) { WebDavAbstractFactory factory = new WebDavAbstractFactory(); WebDavStorageElementPropertiesRow propertyRow = null; try { propertyRow = new WebDavStorageElementPropertiesRow(webDavElementPropertyId); } catch { return; } ResourceInfo resInfo = GetResourceInfoFromPropertyRow(propertyRow); if (resInfo != null) { WebDavTicket ticket = WebDavTicket.Parse(resInfo.AbsolutePath); WebDavElementStorageProvider storageProvider = factory.Create <WebDavElementStorageProvider>(ticket.AbsolutePath.StorageType); foreach (ActiveLockElement activeLockEl in storageProvider.GetActiveLocks(resInfo)) { OpaqueLockToken lockToken = OpaqueLockToken.Parse(activeLockEl.LockToken.InnerText); storageProvider.Unlock(resInfo, lockToken); } } }
/// <summary> /// Saves the property collection. /// </summary> /// <param name="collection">The collection.</param> private void SavePropertyCollection(PropertyInfoCollection collection) { if (collection == null) { return; } bool haveStoredProp = false; WebDavStorageElementPropertiesRow row = null; foreach (PropertyInfo prop in collection) { if (prop.Calculated == false) { haveStoredProp = true; try { WebDavTicket ticket = WebDavTicket.Parse(collection.ElementInfo.AbsolutePath); using (TransactionScope tran = DataContext.Current.BeginTransaction()) { row = GetWebDavStoragePropertyRow(ticket.AbsolutePath.StorageType, ticket.AbsolutePath.UniqueId); if (row == null) { row = new WebDavStorageElementPropertiesRow(); row.ObjectTypeId = (int)ticket.AbsolutePath.StorageType; row.ObjectId = ticket.AbsolutePath.UniqueId; row.Key = "propertyCollection"; } string value = Mediachase.Ibn.Data.McXmlSerializer.GetString <PropertyInfoCollection>(collection); row.Value = value; row.Update(); tran.Commit(); } } catch (Exception) { throw new HttpException(500, "Internal Server Error"); } break; } } //remove property file if empty if (haveStoredProp == false) { try { DeleteWebDavStorageElementPropertiesRow(row); } catch (Exception) { throw new HttpException(500, "Unable to delete property"); } } }
/// <summary> /// Gets the properties. /// </summary> /// <param name="element">The element.</param> /// <returns></returns> public override Mediachase.Net.Wdom.PropertyInfoCollection GetProperties(Mediachase.Net.Wdom.WebDavElementInfo element) { PropertyInfoCollection retVal = null; PropertyInfo prop = null; WebDavDocument tmpDoc = WebDavDocument.CreateDocument(); if (element == null) { return(retVal); } retVal = new PropertyInfoCollection(); //FileInfo fileInfo = !!!!(FileInfo)element.Tag;!!! WebDavTicket ticket = WebDavTicket.Parse(element.AbsolutePath); WebDavStorageElementPropertiesRow row = GetWebDavStoragePropertyRow(ticket.AbsolutePath.StorageType, ticket.AbsolutePath.UniqueId); if (row != null) { retVal = Mediachase.Ibn.Data.McXmlSerializer.GetObject <PropertyInfoCollection>(row.Value); } #region CreateDefaultProperties foreach (PropertyInfo defaultProp in PropertyInfo.CreateDefaultProperties(element)) { SetPropertyAndSave(retVal, defaultProp, false, false); } #endregion //Add <supportedlock> property if (((int)(WebDavApplication.Class & WebDavServerClass.Class2)) != 0) { prop = PropertyInfo.CreateSupportedLockProperty(); prop.Calculated = false; SetPropertyAndSave(retVal, prop, false, false); } //Add <resourcetype> property prop = PropertyInfo.CreateResourceTypeProperty(element); SetPropertyAndSave(retVal, prop, false, false); //Assign context and set closure to class member retVal.ElementInfo = element; return(retVal); }
/// <summary> /// Gets the element info. /// </summary> /// <param name="webDavAbsPath">The web dav abs path.</param> /// <returns></returns> public override WebDavElementInfo GetElementInfo(string strTicket) { WebDavElementInfo retVal = null; try { WebDavTicket ticket = WebDavTicket.Parse(strTicket); if (ticket.IsCollection) { retVal = GetCollectionInfo(ticket); } else { retVal = GetResourceInfo(ticket); } } catch (System.FormatException) { } return(retVal); }