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;
 }
Beispiel #2
0
        /// <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>
        /// 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);
                }
            }
        }
Beispiel #4
0
        private void DeleteWebDavStorageElementPropertiesRow(WebDavStorageElementPropertiesRow row)
        {
            if (row != null)
            {
                using (TransactionScope tran = DataContext.Current.BeginTransaction())
                {
                    row.Delete();
                    tran.Commit();
                }

            }
        }