/// <summary>
        ///     The get document.
        /// </summary>
        /// <param name="parentCollection">
        ///     The parent collection.
        /// </param>
        /// <param name="path">
        ///     The path.
        /// </param>
        /// <param name="rootPath">
        ///     The root path.
        /// </param>
        /// <param name="rootGuid">
        ///     The root guid.
        /// </param>
        /// <returns>
        ///     The <see cref="WebDavSqlStoreDocument" />.
        /// </returns>
        public WebDavSqlStoreDocument GetDocument(IWebDavStoreCollection parentCollection, string path, string rootPath, Guid rootGuid)
        {
            if (!Enabled)
            {
                return(new WebDavSqlStoreDocument(parentCollection, path, rootPath, rootGuid, Store));
            }

            var       p                = PrincipleFactory.Instance.GetPrinciple(FromType.WebDav);
            string    userkey          = p.UserProfile.SecurityObjectId.ToString();
            CacheBase mc               = GetCachedObject(path) as CacheBase;
            WebDavSqlStoreDocument itm = null;

            if (mc != null)
            {
                itm = mc.GetCachedObject(userkey) as WebDavSqlStoreDocument;
            }

            if (itm != null)
            {
                return(itm);
            }

            itm = new WebDavSqlStoreDocument(parentCollection, path, rootPath, rootGuid, Store);
            if (mc == null)
            {
                mc = new CacheBase();
                mc.AddCacheObject(userkey, itm);
                AddCacheObject(path, mc);
            }
            else
            {
                mc.AddCacheObject(userkey, itm);
            }
            return(itm);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Retrieves all locks for the passed object
 /// </summary>
 /// <param name="storeItem">Item to look for locks for.</param>
 /// <returns></returns>
 public override List <IWebDavStoreItemLockInstance> GetLocks(IWebDavStoreItem storeItem)
 {
     try
     {
         List <IWebDavStoreItemLockInstance> items = new List <IWebDavStoreItemLockInstance>();
         using (var context = new OnlineFilesEntities())
         {
             List <ObjectLockInfo>    result;
             WebDavSqlStoreCollection item = storeItem as WebDavSqlStoreCollection;
             if (item != null)
             {
                 var collection = item;
                 result = context.ObjectLockInfoes.AsNoTracking().Where(d => d.ObjectGuid == collection.ObjectGuid && d.isFolder).ToList();
             }
             else
             {
                 WebDavSqlStoreDocument storeDocument = storeItem as WebDavSqlStoreDocument;
                 if (storeDocument != null)
                 {
                     var document = storeDocument;
                     result = context.ObjectLockInfoes.AsNoTracking().Where(d => d.ObjectGuid == document.ObjectGuid && !d.isFolder).ToList();
                 }
                 else
                 {
                     throw new NotSupportedException();
                 }
             }
             items.AddRange(result.Select(lockInfo => new WebDavSqlStoreItemLockInstance(
                                              PrincipleFactory.Instance.GetPrinciple(FromType.WebDav).UserProfile,
                                              lockInfo.Path,
                                              (WebDavLockScope)lockInfo.LockScope,
                                              (WebDavLockType)lockInfo.LockType,
                                              lockInfo.Owner.ToString(),
                                              lockInfo.RequestedLockTimeout,
                                              lockInfo.Token,
                                              new XmlDocument(),
                                              lockInfo.Depth,
                                              this,
                                              lockInfo.CreateDt
                                              )));
             return(items);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message + ex.StackTrace);
         throw;
     }
 }
        /// <summary>
        /// </summary>
        /// <param name="item"></param>
        public void Delete(IWebDavStoreItem item)
        {
#if DEBUG
            Log.Info("Deleting Item: " + item.Name);
#endif
            if (IsCheckedOut(item))
            {
                throw new Exception("Item is checked out.");
            }

            using (var context = new OnlineFilesEntities())
            {
                var collection = item as WebDavSqlStoreCollection;
                if (collection != null)
                {
                    Folder folder = context.Folders.FirstOrDefault(d => d.pk_FolderId == collection.ObjectGuid);
                    if (folder == null)
                    {
                        throw new WebDavNotFoundException("Folder Not Found.");
                    }
                    folder.SetDeleted(PrincipleFactory.Instance.GetPrinciple(FromType.WebDav).UserProfile);
                    context.SaveChanges();
                    WebDavSqlStoreCollectionFactory.Instance.InvalidateCollection(item.ItemPath);
                    WebDavSqlStoreCollectionFactory.Instance.InvalidateCollection(ItemPath);
                }
                else
                {
                    WebDavSqlStoreDocument document = item as WebDavSqlStoreDocument;
                    if (document == null)
                    {
                        return;
                    }
                    var  doc  = document;
                    File file = context.Files.FirstOrDefault(d => d.pk_FileId == doc.ObjectGuid);
                    if (file == null)
                    {
                        throw new WebDavNotFoundException("Folder Not Found.");
                    }
                    file.SetDeleted(PrincipleFactory.Instance.GetPrinciple(FromType.WebDav).UserProfile);
                    context.SaveChanges();
                    WebDavSqlStoreCollectionFactory.Instance.InvalidateCollection(ItemPath);
                    WebDavSqlStoreDocumentFactory.Instance.InvalidateDocumentPath(doc.ItemPath);
                }
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destinationName"></param>
        /// <returns></returns>
        public IWebDavStoreItem MoveItemHere(IWebDavStoreItem source, string destinationName)
        {
            //this -> is where it wants to be moved to.
            //source is the item
            //destination name is the name they want it to be.
            IWebDavStoreItem returnitem;

            using (var context = new OnlineFilesEntities())
            {
                var sourceFolder = source as WebDavSqlStoreCollection;
                if (sourceFolder != null)
                {
                    Folder targetFolder = context.Folders.FirstOrDefault(d => d.pk_FolderId == sourceFolder.ObjectGuid);
                    if (targetFolder == null)
                    {
                        return(null);
                    }

                    Folder destination = context.Folders.FirstOrDefault(d => d.pk_FolderId == ObjectGuid);
                    destination.MoveFolderHere(targetFolder.pk_FolderId, destinationName, PrincipleFactory.Instance.GetPrinciple(FromType.WebDav));
                    context.SaveChanges();
                    WebDavSqlStoreCollectionFactory.Instance.InvalidateCollection(ItemPath);
                    WebDavSqlStoreCollectionFactory.Instance.InvalidateCollection(sourceFolder.ItemPath);
                    WebDavSqlStoreCollectionFactory.Instance.InvalidateCollection(Path.Combine(ItemPath, destinationName));
                    returnitem = WebDavSqlStoreCollectionFactory.Instance.GetCollection(this, Path.Combine(ItemPath, destinationName), RootPath, RootGuid);
                }
                else
                {
                    WebDavSqlStoreDocument document = source as WebDavSqlStoreDocument;
                    if (document == null)
                    {
                        return(null);
                    }
                    WebDavSqlStoreDocument doc = document;
                    var destFolder             = context.Folders.FirstOrDefault(d => d.pk_FolderId == ObjectGuid);
                    destFolder.MoveFileHere((Guid)document.ObjectGuid, destinationName, PrincipleFactory.Instance.GetPrinciple(FromType.WebDav));
                    WebDavSqlStoreDocumentFactory.Instance.InvalidateDocumentPath(Path.Combine(ItemPath, destinationName));
                    WebDavSqlStoreCollectionFactory.Instance.InvalidateCollection(ItemPath);
                    returnitem = WebDavSqlStoreDocumentFactory.Instance.GetDocument(this, Path.Combine(ItemPath, destinationName), RootPath, RootGuid);
                }
            }
            return(returnitem);
        }
        /// <summary>
        ///     The get document.
        /// </summary>
        /// <param name="parentCollection">
        ///     The parent collection.
        /// </param>
        /// <param name="path">
        ///     The path.
        /// </param>
        /// <param name="rootPath">
        ///     The root path.
        /// </param>
        /// <param name="rootGuid">
        ///     The root guid.
        /// </param>
        /// <returns>
        ///     The <see cref="WebDavSqlStoreDocument" />.
        /// </returns>
        public WebDavSqlStoreDocument GetDocument(IWebDavStoreCollection parentCollection, string path, string rootPath, Guid rootGuid)
        {
            if (!Enabled)
                return new WebDavSqlStoreDocument(parentCollection, path, rootPath, rootGuid, Store);

            var p = PrincipleFactory.Instance.GetPrinciple(FromType.WebDav);
            string userkey = p.UserProfile.SecurityObjectId.ToString();
            CacheBase mc = GetCachedObject(path) as CacheBase;
            WebDavSqlStoreDocument itm = null;
            if (mc != null)
                itm = mc.GetCachedObject(userkey) as WebDavSqlStoreDocument;

            if (itm != null)
                return itm;

            itm = new WebDavSqlStoreDocument(parentCollection, path, rootPath, rootGuid, Store);
            if (mc == null)
            {
                mc = new CacheBase();
                mc.AddCacheObject(userkey, itm);
                AddCacheObject(path, mc);
            }
            else
                mc.AddCacheObject(userkey, itm);
            return itm;
        }