/// <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); } } }
private static ResourceInfo GetResourceInfoFromPropertyRow(WebDavStorageElementPropertiesRow propertyRow) { if (propertyRow == null) { throw new ArgumentNullException("propertyRow"); } ResourceInfo retVal = null; WebDavAbstractFactory factory = new WebDavAbstractFactory(); //For MetaData stored int hash for Guid value is not possible restore back from hash to Guid if ((ObjectTypes)propertyRow.ObjectTypeId != ObjectTypes.File_MetaData) { WebDavElementStorageProvider provider = factory.Create <WebDavElementStorageProvider>(propertyRow.ObjectTypeId); WebDavAbsolutePath absPath = WebDavAbsolutePath.CreateInstance((ObjectTypes)propertyRow.ObjectTypeId); absPath.UniqueId = propertyRow.ObjectId; absPath.FileName = "file"; WebDavTicket ticket = WebDavTicket.CreateInstance(ePluginToken.webdav, Guid.Empty, absPath); try { retVal = provider.GetElementInfo(ticket.ToString()) as ResourceInfo; } catch (Exception) { } } return(retVal); }
/// <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"); } } }
private void DeleteWebDavStorageElementPropertiesRow(WebDavStorageElementPropertiesRow row) { if (row != null) { using (TransactionScope tran = DataContext.Current.BeginTransaction()) { row.Delete(); tran.Commit(); } } }
private WebDavStorageElementPropertiesRow GetWebDavStoragePropertyRow(ObjectTypes storageType, int objectId) { WebDavStorageElementPropertiesRow retVal = null; FilterElement filterEl1 = new FilterElement("ObjectTypeId", FilterElementType.Equal, (int)storageType); FilterElement filterEl2 = new FilterElement("ObjectId", FilterElementType.Equal, objectId); WebDavStorageElementPropertiesRow[] propertyRow = WebDavStorageElementPropertiesRow.List(filterEl1, filterEl2); if (propertyRow.Length > 0) { retVal = propertyRow[0]; } return(retVal); }
/// <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 active locked webdav resources. /// </summary> /// <returns></returns> public static IEnumerable <WebDavLockInfo> GetActiveLocksInfo() { WebDavAbstractFactory factory = new WebDavAbstractFactory(); foreach (WebDavStorageElementPropertiesRow row in WebDavStorageElementPropertiesRow.List()) { WebDavElementStorageProvider provider = factory.Create <WebDavElementStorageProvider>(row.ObjectTypeId); ResourceInfo resInfo = GetResourceInfoFromPropertyRow(row); if (resInfo != null) { foreach (ActiveLockElement activeLockEl in provider.GetActiveLocks(resInfo)) { OpaqueLockToken lockToken = OpaqueLockToken.Parse(activeLockEl.LockToken.InnerText); McLockElement mcLockEl = GetMcLockElement(lockToken, provider.GetProperties(resInfo)); WebDavLockInfo retval = new WebDavLockInfo(); retval.WebDavElementPropertyId = row.PrimaryKeyId.Value; retval.FileName = resInfo.Name; retval.ContentTypeId = ContentTypeResolver.GetContentTypeId(resInfo.ContentType); retval.StartLocking = new DateTime(mcLockEl.CreationDate * TimeSpan.TicksPerSecond); retval.Duration = DateTime.UtcNow - retval.StartLocking; UserLight user = UserLight.Load(activeLockEl.Owner); if (user != null) { retval.LockedBy = user.DisplayName; } else { retval.LockedBy = "Unknow"; } yield return(retval); } } } }