コード例 #1
0
        public WebDavSqlStoreCollection GetCollection(IWebDavStoreCollection parentCollection, string path, String rootPath, Guid rootGuid)
        {
            var       p                  = PrincipleFactory.Instance.GetPrinciple(FromType.WebDav);
            string    userkey            = p.UserProfile.SecurityObjectId.ToString();
            CacheBase mc                 = GetCachedObject(path) as CacheBase;
            WebDavSqlStoreCollection itm = null;

            if (mc != null)
            {
                itm = mc.GetCachedObject(userkey) as WebDavSqlStoreCollection;
            }
            if (itm != null)
            {
                return(itm);
            }
            itm = new WebDavSqlStoreCollection(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);
        }
コード例 #2
0
        /// <summary>
        /// Get the item in the collection from the requested
        /// <see cref="Uri" />.
        /// <see cref="WebDavException" /> 409 Conflict possible.
        /// </summary>
        /// <param name="collection">The parent collection as a <see cref="IWebDavStoreCollection" /></param>
        /// <param name="childUri">The <see cref="Uri" /> object containing the specific location of the child</param>
        /// <returns>
        /// The <see cref="IWebDavStoreItem" /> from the <see cref="IWebDavStoreCollection" />
        /// </returns>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavUnauthorizedException">If user is not authorized to get access to the item</exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException">If item not found.</exception>
        public static IWebDavStoreItem GetItemFromCollection(IWebDavStoreCollection collection, Uri childUri)
        {
            IWebDavStoreItem item;
            String           name = null;

            try
            {
                name = childUri.GetLastSegment();
                item = collection.GetItemByName(name);
            }
            catch (UnauthorizedAccessException)
            {
                throw new WebDavUnauthorizedException();
            }
            catch (WebDavNotFoundException wex)
            {
                throw new WebDavNotFoundException(String.Format("Cannot found name {0} from uri {1} father {2}", name, childUri, collection.ItemPath), wex);
            }
            if (item == null)
            {
                throw new WebDavNotFoundException(String.Format("Cannot found name {0} from uri {1} father {2}", name, childUri, collection.ItemPath));
            }

            return(item);
        }
コード例 #3
0
        /// <summary>
        /// Moves the
        /// </summary>
        /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
        /// <param name="context">The
        /// <see cref="IHttpListenerContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        /// <param name="sourceWebDavStoreItem">The <see cref="IWebDavStoreItem" /> that will be moved</param>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavForbiddenException">If the source path is the same as the destination path</exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavPreconditionFailedException">If one of the preconditions failed</exception>
        private void MoveItem(WebDavServer server, IHttpListenerContext context, IWebDavStore store,
                              IWebDavStoreItem sourceWebDavStoreItem)
        {
            Uri destinationUri = GetDestinationHeader(context.Request);
            IWebDavStoreCollection destinationParentCollection = GetParentCollection(server, store, destinationUri);

            bool isNew = true;

            string           destinationName = Uri.UnescapeDataString(destinationUri.Segments.Last().TrimEnd('/', '\\'));
            IWebDavStoreItem destination     = destinationParentCollection.GetItemByName(destinationName);

            if (destination != null)
            {
                if (sourceWebDavStoreItem.ItemPath == destination.ItemPath)
                {
                    throw new WebDavForbiddenException();
                }
                // if the overwrite header is F, statuscode = precondition failed
                if (!GetOverwriteHeader(context.Request))
                {
                    throw new WebDavPreconditionFailedException();
                }
                // else delete destination and set isNew to false
                destinationParentCollection.Delete(destination);
                isNew = false;
            }

            destinationParentCollection.MoveItemHere(sourceWebDavStoreItem, destinationName);

            // send correct response
            context.SendSimpleResponse(isNew ? HttpStatusCode.Created : HttpStatusCode.NoContent);
        }
        /// <summary>
        /// Convert the given
        /// <see cref="IWebDavStoreItem" /> to a
        /// <see cref="List{T}" /> of
        /// <see cref="IWebDavStoreItem" />
        /// This list depends on the "Depth" header
        /// </summary>
        /// <param name="iWebDavStoreItem">The <see cref="IWebDavStoreItem" /> that needs to be converted</param>
        /// <param name="depth">The "Depth" header</param>
        /// <returns>
        /// A <see cref="List{T}" /> of <see cref="IWebDavStoreItem" />
        /// </returns>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavConflictException"></exception>
        private HashSet <IWebDavStoreItem> GetWebDavStoreItems(IWebDavStoreItem iWebDavStoreItem, int depth)
        {
            HashSet <IWebDavStoreItem> list = new HashSet <IWebDavStoreItem>();

            //IWebDavStoreCollection
            // if the item is a collection
            IWebDavStoreCollection collection = iWebDavStoreItem as IWebDavStoreCollection;

            if (collection != null)
            {
                list.Add(collection);
                if (depth == 0)
                {
                    return(list);
                }

                foreach (var item in collection.Items)
                {
                    list.Add(item);
                }

                return(list);
            }
            // if the item is not a document, throw conflict exception
            if (!(iWebDavStoreItem is IWebDavStoreDocument))
            {
                throw new WebDavConflictException(String.Format("Web dav item is not a document nor a collection: {0} depth {1}", iWebDavStoreItem.ItemPath, depth));
            }

            // add the item to the list
            list.Add(iWebDavStoreItem);

            return(list);
        }
 public WebDaveSqlStoreFileInfo(SqlStoreFileInfo fileInfo, IWebDavStoreCollection parent, string path)
 {
     ObjectGuid = fileInfo.ObjectGuid;
     Archive = fileInfo.Archive;
     Compressed = fileInfo.Compressed;
     CreationTime = fileInfo.CreationTime;
     Device = fileInfo.Device;
     Directory = fileInfo.Directory;
     Encrypted = fileInfo.Encrypted;
     Exists = fileInfo.Exists;
     Hidden = fileInfo.Hidden;
     IntegrityStream = fileInfo.IntegrityStream;
     LastAccessTime = fileInfo.LastAccessTime;
     LastWriteTime = fileInfo.LastWriteTime;
     NoScrubData = fileInfo.NoScrubData;
     Normal = fileInfo.Normal;
     NotContentIndexed = fileInfo.NotContentIndexed;
     Offline = fileInfo.Offline;
     Parent = parent;
     Path = path;
     ReadOnly = fileInfo.ReadOnly;
     ReparsePoint = fileInfo.ReparsePoint;
     SparseFile = fileInfo.SparseFile;
     System = fileInfo.System;
     Temporary = fileInfo.Temporary;
 }
コード例 #6
0
        /// <summary>
        /// Copies the item.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="store">The store.</param>
        /// <param name="source">The source.</param>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavForbiddenException"></exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavPreconditionFailedException"></exception>
        private static void CopyItem(IWebDavContext context, IWebDavStore store, IWebDavStoreItem source)
        {
            Uri destinationUri = GetDestinationHeader(context.Request);
            IWebDavStoreCollection destinationParentCollection = GetParentCollection(store, context, destinationUri);

            bool copyContent = (GetDepthHeader(context.Request) != 0);
            bool isNew       = true;

            string           destinationName = Uri.UnescapeDataString(destinationUri.Segments.Last().TrimEnd('/', '\\'));
            IWebDavStoreItem destination     = destinationParentCollection.GetItemByName(destinationName);

            if (destination != null)
            {
                if (source.ItemPath == destination.ItemPath)
                {
                    throw new WebDavForbiddenException();
                }
                if (!GetOverwriteHeader(context.Request))
                {
                    throw new WebDavPreconditionFailedException();
                }
                if (destination is IWebDavStoreCollection)
                {
                    destinationParentCollection.Delete(destination);
                }
                isNew = false;
            }

            destinationParentCollection.CopyItemHere(source, destinationName, copyContent);

            var statusCode = isNew ? HttpStatusCode.Created : HttpStatusCode.NoContent;

            context.SetStatusCode(statusCode);
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebDavStoreBase" /> class.
        /// </summary>
        /// <param name="root">The root <see cref="IWebDavStoreCollection" />.</param>
        /// <exception cref="System.ArgumentNullException">root</exception>
        /// <exception cref="ArgumentNullException"><paramref name="root" /> is <c>null</c>.</exception>
        protected WebDavStoreBase(IWebDavStoreCollection root)
        {
            if (root == null)
                throw new ArgumentNullException("root");

            _root = root;
        }
コード例 #8
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
        /// <param name="context">The
        /// <see cref="IHttpListenerContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavUnsupportedMediaTypeException"></exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavMethodNotAllowedException"></exception>
        /// <param name="response"></param>
        /// <param name="request"></param>
        protected override void OnProcessRequest(
            WebDavServer server,
            IHttpListenerContext context,
            IWebDavStore store,
            XmlDocument request,
            XmlDocument response)
        {
            if (context.Request.ContentLength64 > 0)
            {
                throw new WebDavUnsupportedMediaTypeException();
            }

            IWebDavStoreCollection collection = GetParentCollection(server, store, context.Request.Url);

            string           collectionName = context.Request.Url.GetLastSegment();
            IWebDavStoreItem item;

            if ((item = collection.GetItemByName(collectionName)) != null)
            {
                WebDavServer.Log.Warning("MKCOL Failed: item {0} already exists as child of {1}. ",
                                         collectionName, collection.ItemPath);
                throw new WebDavMethodNotAllowedException();
            }


            collection.CreateCollection(collectionName);

            context.SendSimpleResponse((int)HttpStatusCode.Created);
        }
コード例 #9
0
        /// <summary>
        /// Copies the item.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="context">The context.</param>
        /// <param name="store">The store.</param>
        /// <param name="source">The source.</param>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavForbiddenException"></exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavPreconditionFailedException"></exception>
        private static void CopyItem(WebDavServer server, IHttpListenerContext context, IWebDavStore store,
                                     IWebDavStoreItem source)
        {
            Uri destinationUri = GetDestinationHeader(context.Request);
            IWebDavStoreCollection destinationParentCollection = GetParentCollection(server, store, destinationUri);

            bool copyContent = (GetDepthHeader(context.Request) != 0);
            bool isNew       = true;

            string           destinationName = destinationUri.GetLastSegment();
            IWebDavStoreItem destination     = destinationParentCollection.GetItemByName(destinationName);

            if (destination != null)
            {
                if (source.ItemPath == destination.ItemPath)
                {
                    throw new WebDavForbiddenException();
                }
                if (!GetOverwriteHeader(context.Request))
                {
                    throw new WebDavPreconditionFailedException();
                }
                if (destination is IWebDavStoreCollection)
                {
                    destinationParentCollection.Delete(destination);
                }
                isNew = false;
            }

            destinationParentCollection.CopyItemHere(source, destinationName, copyContent);

            context.SendSimpleResponse(isNew ? (int)HttpStatusCode.Created : (int)HttpStatusCode.NoContent);
        }
コード例 #10
0
        /// <summary>
        /// Convert the given
        /// <see cref="IWebDavStoreItem" /> to a
        /// <see cref="List{T}" /> of
        /// <see cref="IWebDavStoreItem" />
        /// This list depends on the "Depth" header
        /// </summary>
        /// <param name="iWebDavStoreItem">The <see cref="IWebDavStoreItem" /> that needs to be converted</param>
        /// <param name="depth">The "Depth" header</param>
        /// <returns>
        /// A <see cref="List{T}" /> of <see cref="IWebDavStoreItem" />
        /// </returns>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavConflictException"></exception>
        private static List <IWebDavStoreItem> GetWebDavStoreItems(IWebDavStoreItem iWebDavStoreItem, int depth)
        {
            List <IWebDavStoreItem> list = new List <IWebDavStoreItem>();

            //IWebDavStoreCollection
            // if the item is a collection
            IWebDavStoreCollection collection = iWebDavStoreItem as IWebDavStoreCollection;

            if (collection != null)
            {
                list.Add(collection);
                if (depth == 0)
                {
                    return(list);
                }

                foreach (IWebDavStoreItem item in collection.Items.Where(item => !list.Contains(item)))
                {
                    list.Add(item);
                }

                return(list);
            }
            // if the item is not a document, throw conflict exception
            if (!(iWebDavStoreItem is IWebDavStoreDocument))
            {
                throw new WebDavConflictException();
            }

            // add the item to the list
            list.Add(iWebDavStoreItem);

            return(list);
        }
コード例 #11
0
 public WebDaveSqlStoreFileInfo(SqlStoreFileInfo fileInfo, IWebDavStoreCollection parent, string path)
 {
     ObjectGuid        = fileInfo.ObjectGuid;
     Archive           = fileInfo.Archive;
     Compressed        = fileInfo.Compressed;
     CreationTime      = fileInfo.CreationTime;
     Device            = fileInfo.Device;
     Directory         = fileInfo.Directory;
     Encrypted         = fileInfo.Encrypted;
     Exists            = fileInfo.Exists;
     Hidden            = fileInfo.Hidden;
     IntegrityStream   = fileInfo.IntegrityStream;
     LastAccessTime    = fileInfo.LastAccessTime;
     LastWriteTime     = fileInfo.LastWriteTime;
     NoScrubData       = fileInfo.NoScrubData;
     Normal            = fileInfo.Normal;
     NotContentIndexed = fileInfo.NotContentIndexed;
     Offline           = fileInfo.Offline;
     Parent            = parent;
     Path         = path;
     ReadOnly     = fileInfo.ReadOnly;
     ReparsePoint = fileInfo.ReparsePoint;
     SparseFile   = fileInfo.SparseFile;
     System       = fileInfo.System;
     Temporary    = fileInfo.Temporary;
 }
コード例 #12
0
        /// <summary>
        /// Retrieves a store item through the specified
        /// <see cref="Uri" /> from the
        /// specified
        /// <see cref="WebDavServer" /> and
        /// <see cref="IWebDavStore" />.
        /// </summary>
        /// <param name="uri">The <see cref="Uri" /> to retrieve the store item for.</param>
        /// <param name="server">The <see cref="WebDavServer" /> that hosts the <paramref name="store" />.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> from which to retrieve the store item.</param>
        /// <returns>
        /// The retrieved store item.
        /// </returns>
        /// <exception cref="System.ArgumentNullException"><para>
        ///   <paramref name="uri" /> is <c>null</c>.</para>
        /// <para>
        ///   <paramref name="server" /> is <c>null</c>.</para>
        /// <para>
        ///   <paramref name="store" /> is <c>null</c>.</para></exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException">If the item was not found.</exception>
        /// <exception cref="WebDavConflictException"><paramref name="uri" /> refers to a document in a collection, where the collection does not exist.</exception>
        /// <exception cref="WebDavNotFoundException"><paramref name="uri" /> refers to a document that does not exist.</exception>
        public static IWebDavStoreItem GetItem(
            this Uri uri,
            WebDavServer server,
            IWebDavStore store)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            Uri prefixUri = uri.GetPrefixUri(server);
            IWebDavStoreCollection collection = store.Root;

            IWebDavStoreItem item = null;

            if (prefixUri.Segments.Length == uri.Segments.Length)
            {
                return(collection);
            }

            string[] segments = SplitUri(uri, prefixUri);

            for (int index = 0; index < segments.Length; index++)
            {
                string segmentName = Uri.UnescapeDataString(segments[index]);

                IWebDavStoreItem nextItem = collection.GetItemByName(segmentName);
                if (nextItem == null)
                {
                    throw new WebDavNotFoundException(String.Format("Cannot find item {0} from collection {1}", segmentName, collection.ItemPath)); //throw new WebDavConflictException();
                }
                if (index == segments.Length - 1)
                {
                    item = nextItem;
                }
                else
                {
                    collection = nextItem as IWebDavStoreCollection;
                    if (collection == null)
                    {
                        throw new WebDavNotFoundException(String.Format("NextItem [{0}] is not a collection", nextItem.ItemPath));
                    }
                }
            }

            if (item == null)
            {
                throw new WebDavNotFoundException(String.Format("Unable to find {0}", uri));
            }

            return(item);
        }
コード例 #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebDavStoreItemBase" /> class.
        /// </summary>
        /// <param name="parentCollection">The parent <see cref="IWebDavStoreCollection" /> that contains this <see cref="IWebDavStoreItem" /> implementation.</param>
        /// <param name="name">The name of this <see cref="IWebDavStoreItem" /></param>
        /// <exception cref="System.ArgumentNullException">name</exception>
        /// <exception cref="ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
        protected WebDavStoreItemBase(IWebDavStoreCollection parentCollection, string name)
        {
            if (String.IsNullOrWhiteSpace(name))
                throw new ArgumentNullException("name");

            _parentCollection = parentCollection;
            _name = name;
        }
コード例 #14
0
        /// <summary>
        ///     Get the item in the collection from the requested
        ///     <see cref="Uri" />.
        ///     <see cref="WebDavException" /> 409 Conflict possible.
        /// </summary>
        /// <param name="collection">The parent collection as a <see cref="IWebDavStoreCollection" /></param>
        /// <param name="childUri">The <see cref="Uri" /> object containing the specific location of the child</param>
        /// <returns>
        ///     The <see cref="IWebDavStoreItem" /> from the <see cref="IWebDavStoreCollection" />
        /// </returns>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavUnauthorizedException">
        ///     If user is not authorized to get access to
        ///     the item
        /// </exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException">If item not found.</exception>
        public static IWebDavStoreItem GetItemFromCollection(IWebDavStoreCollection collection, Uri childUri)
        {
            IWebDavStoreItem item = collection.GetItemByName(Uri.UnescapeDataString(childUri.Segments.Last().TrimEnd('/', '\\')));
            if (item == null)
                throw new WebDavNotFoundException();
            item.Href = childUri;

            return item;
        }
コード例 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebDavStoreBase" /> class.
        /// </summary>
        /// <param name="root">The root <see cref="IWebDavStoreCollection" />.</param>
        /// <exception cref="System.ArgumentNullException">root</exception>
        /// <exception cref="ArgumentNullException"><paramref name="root" /> is <c>null</c>.</exception>
        protected WebDavStoreBase(IWebDavStoreCollection root)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            _root = root;
        }
コード例 #16
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
        /// <param name="context">The
        /// <see cref="IHttpListenerContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavMethodNotAllowedException"></exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavLengthRequiredException">If the ContentLength header was not found</exception>
        /// <param name="response"></param>
        /// <param name="request"></param>
        protected override void OnProcessRequest(
            WebDavServer server,
            IHttpListenerContext context,
            IWebDavStore store,
            XmlDocument request,
            XmlDocument response)
        {
            // Get the parent collection
            IWebDavStoreCollection parentCollection = GetParentCollection(server, store, context.Request.Url);

            // Gets the item name from the url
            string itemName = context.Request.Url.GetLastSegment();

            IWebDavStoreItem     item = parentCollection.GetItemByName(itemName);
            IWebDavStoreDocument doc;

            if (item != null)
            {
                doc = item as IWebDavStoreDocument;
                if (doc == null)
                {
                    throw new WebDavMethodNotAllowedException();
                }
            }
            else
            {
                doc = parentCollection.CreateDocument(itemName);
            }

            Int64 contentLength = context.Request.ContentLength64;

            if (context.Request.ContentLength64 < 0)
            {
                var XLength = context.Request.Headers["x-expected-entity-length"];
                if (!Int64.TryParse(XLength, out contentLength))
                {
                    throw new WebDavLengthRequiredException();
                }
            }

            using (Stream stream = doc.OpenWriteStream(false))
            {
                long   left   = contentLength;
                byte[] buffer = new byte[4096];
                while (left > 0)
                {
                    int toRead   = Convert.ToInt32(Math.Min(left, buffer.Length));
                    int inBuffer = context.Request.InputStream.Read(buffer, 0, toRead);
                    stream.Write(buffer, 0, inBuffer);

                    left -= inBuffer;
                }
            }
            doc.FinishWriteOperation();

            context.SendSimpleResponse((int)HttpStatusCode.Created);
        }
コード例 #17
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="WebDavStoreItemBase" /> class.
        /// </summary>
        /// <param name="parentCollection">
        ///     The parent <see cref="IWebDavStoreCollection" /> that contains this
        ///     <see cref="IWebDavStoreItem" /> implementation.
        /// </param>
        /// <param name="name">The name of this <see cref="IWebDavStoreItem" /></param>
        /// <param name="store"></param>
        /// <exception cref="System.ArgumentNullException">name</exception>
        /// <exception cref="ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
        protected WebDavStoreItemBase(IWebDavStoreCollection parentCollection, string name, IWebDavStore store)
        {
            Store = store;
            if (IsNullOrWhiteSpace(name))
                throw new ArgumentNullException(nameof(name));

            ParentCollection = parentCollection;
            _name = name;
            UserIdentity = (WindowsIdentity)Thread.GetData(Thread.GetNamedDataSlot(WebDavServer.HttpUser));
        }
 /// <summary>
 /// </summary>
 /// <param name="parentCollection"></param>
 /// <param name="path"></param>
 /// <param name="rootPath"></param>
 /// <param name="rootGuid"></param>
 /// <param name="store"></param>
 public WebDavSqlStoreCollection(IWebDavStoreCollection parentCollection, string path, String rootPath, Guid rootGuid, IWebDavStore store)
     : base(parentCollection, path, rootPath, rootGuid, store)
 {
     using (var context = new OnlineFilesEntities())
     {
         Folder f = context.Folders.AsNoTracking().FirstOrDefault(d => d.pk_FolderId == ObjectGuid);
         if (f != null)
             _creationDt = f.CreateDt;
     }
 }
コード例 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebDavStoreItemBase" /> class.
        /// </summary>
        /// <param name="parentCollection">The parent <see cref="IWebDavStoreCollection" /> that contains this <see cref="IWebDavStoreItem" /> implementation.</param>
        /// <param name="name">The name of this <see cref="IWebDavStoreItem" /></param>
        /// <exception cref="System.ArgumentNullException">name</exception>
        /// <exception cref="ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
        protected WebDavStoreItemBase(IWebDavStoreCollection parentCollection, string name)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            _parentCollection = parentCollection;
            _name             = name;
        }
コード例 #20
0
        ///// <summary>
        ///// Gets the prefix <see cref="Uri" /> that matches the specified <see cref="Uri" />.
        ///// </summary>
        ///// <param name="uri">The <see cref="Uri" /> to find the most specific prefix <see cref="Uri" /> for.</param>
        ///// <param name="context">Context</param>
        ///// <returns>
        ///// The most specific <see cref="Uri" /> for the given <paramref name="uri" />.
        ///// </returns>
        ///// <exception cref="WebDAVSharp.Server.Exceptions.WebDavInternalServerException">Unable to find correct server root</exception>
        ///// <exception cref="WebDavInternalServerException"><paramref name="uri" /> specifies a <see cref="Uri" /> that is not known to the <paramref name="server" />.</exception>
        //public static Uri GetPrefixUri(this Uri uri, IWebDavContext context)
        //{
        //    string.Format("{0}://{1}", context.Request.Url.Scheme, context.Request.Url.Authority);

        //    string url = uri.ToString();
        //    foreach (
        //        string prefix in
        //            server.Listener.Prefixes.Where(
        //                prefix => url.StartsWith(uri.ToString(), StringComparison.OrdinalIgnoreCase)))
        //        return new Uri(prefix);
        //    throw new WebDavInternalServerException("Unable to find correct server root");
        //}

        /// <summary>
        /// Retrieves a store item through the specified
        /// <see cref="Uri" /> from the
        /// specified
        /// <see cref="WebDavServer" /> and
        /// <see cref="IWebDavStore" />.
        /// </summary>
        /// <param name="uri">The <see cref="Uri" /> to retrieve the store item for.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> from which to retrieve the store item.</param>
        /// <param name="context">Context</param>
        /// <returns>
        /// The retrieved store item.
        /// </returns>
        /// <exception cref="System.ArgumentNullException"><para>
        ///   <paramref name="uri" /> is <c>null</c>.</para>
        /// <para>
        ///   <paramref name="context" /> is <c>null</c>.</para>
        /// <para>
        ///   <paramref name="store" /> is <c>null</c>.</para></exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException">If the item was not found.</exception>
        /// <exception cref="WebDavConflictException"><paramref name="uri" /> refers to a document in a collection, where the collection does not exist.</exception>
        /// <exception cref="WebDavNotFoundException"><paramref name="uri" /> refers to a document that does not exist.</exception>
        public static IWebDavStoreItem GetItem(this Uri uri, IWebDavStore store, IWebDavContext context)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            IWebDavStoreCollection collection = store.Root;

            IWebDavStoreItem item = null;

            if (context.Request.Url.Segments.Length - 1 == uri.Segments.Length)
            {
                return(collection);
            }

            //todo пути с глубиной больше рута глючат. надо дописать логику далее.

            for (int index = uri.Segments.Length; index < context.Request.Url.Segments.Length; index++)
            {
                string           segmentName = Uri.UnescapeDataString(context.Request.Url.Segments[index]);
                IWebDavStoreItem nextItem    = collection.GetItemByName(segmentName.TrimEnd('/', '\\'));
                if (nextItem == null)
                {
                    throw new WebDavNotFoundException(); //throw new WebDavConflictException();
                }
                if (index == context.Request.Url.Segments.Length - 1)
                {
                    item = nextItem;
                }
                else
                {
                    collection = nextItem as IWebDavStoreCollection;
                    if (collection == null)
                    {
                        throw new WebDavNotFoundException();
                    }
                }
            }

            if (item == null)
            {
                throw new WebDavNotFoundException();
            }

            return(item);
        }
 protected WebDavSqlStoreItem(IWebDavStoreCollection parentCollection, string path, String rootPath, Guid rootGuid, IWebDavStore store)
     : base(parentCollection, path, store)
 {
     if (IsNullOrWhiteSpace(path))
         throw new ArgumentNullException(nameof(path));
     RootGuid = rootGuid;
     RootPath = rootPath;
     _path = path;
     ObjectGuid = GetObjectGuid(path);
     GetFileInfo();
 }
コード例 #22
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="context">The
        /// <see cref="IWebDavContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        public void ProcessRequest(IWebDavContext context, IWebDavStore store)
        {
            // Get the parent collection of the item
            IWebDavStoreCollection collection = GetParentCollection(store, context, context.Request.Url);

            // Get the item from the collection
            IWebDavStoreItem item = GetItemFromCollection(collection, context.Request.Url);

            // Deletes the item
            collection.Delete(item);
        }
コード例 #23
0
        /// <summary>
        /// Retrieves a store item through the specified
        /// <see cref="Uri" /> from the
        /// specified
        /// <see cref="WebDavServer" /> and
        /// <see cref="IWebDavStore" />.
        /// </summary>
        /// <param name="uri">The <see cref="Uri" /> to retrieve the store item for.</param>
        /// <param name="server">The <see cref="WebDavServer" /> that hosts the <paramref name="store" />.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> from which to retrieve the store item.</param>
        /// <returns>
        /// The retrieved store item.
        /// </returns>
        /// <exception cref="System.ArgumentNullException"><para>
        ///   <paramref name="uri" /> is <c>null</c>.</para>
        /// <para>
        ///   <paramref name="server" /> is <c>null</c>.</para>
        /// <para>
        ///   <paramref name="store" /> is <c>null</c>.</para></exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException">If the item was not found.</exception>
        /// <exception cref="WebDavConflictException"><paramref name="uri" /> refers to a document in a collection, where the collection does not exist.</exception>
        /// <exception cref="WebDavNotFoundException"><paramref name="uri" /> refers to a document that does not exist.</exception>
        public static IWebDavStoreItem GetItem(this Uri uri, WebDavServer server, IWebDavStore store)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            Uri prefixUri = uri.GetPrefixUri(server);
            IWebDavStoreCollection collection = store.Root;

            IWebDavStoreItem item = null;

            if (prefixUri.Segments.Length == uri.Segments.Length)
            {
                return(collection);
            }

            for (int index = prefixUri.Segments.Length; index < uri.Segments.Length; index++)
            {
                string           segmentName = Uri.UnescapeDataString(uri.Segments[index]);
                IWebDavStoreItem nextItem    = collection.GetItemByName(segmentName.TrimEnd('/', '\\'));
                if (nextItem == null)
                {
                    throw new WebDavNotFoundException(); //throw new WebDavConflictException();
                }
                if (index == uri.Segments.Length - 1)
                {
                    item = nextItem;
                }
                else
                {
                    collection = nextItem as IWebDavStoreCollection;
                    if (collection == null)
                    {
                        throw new WebDavNotFoundException();
                    }
                }
            }

            if (item == null)
            {
                throw new WebDavNotFoundException();
            }

            return(item);
        }
 /// <summary>
 /// </summary>
 /// <param name="parentCollection"></param>
 /// <param name="path"></param>
 /// <param name="rootPath"></param>
 /// <param name="rootGuid"></param>
 /// <param name="store"></param>
 public WebDavSqlStoreCollection(IWebDavStoreCollection parentCollection, string path, String rootPath, Guid rootGuid, IWebDavStore store)
     : base(parentCollection, path, rootPath, rootGuid, store)
 {
     using (var context = new OnlineFilesEntities())
     {
         Folder f = context.Folders.AsNoTracking().FirstOrDefault(d => d.pk_FolderId == ObjectGuid);
         if (f != null)
         {
             _creationDt = f.CreateDt;
         }
     }
 }
コード例 #25
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
        /// <param name="context">The
        /// <see cref="IHttpListenerContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        public void ProcessRequest(WebDavServer server, IHttpListenerContext context, IWebDavStore store)
        {
            // Get the parent collection of the item
            IWebDavStoreCollection collection = GetParentCollection(server, store, context.Request.Url);

            // Get the item from the collection
            IWebDavStoreItem item = GetItemFromCollection(collection, context.Request.Url);

            // Deletes the item
            collection.Delete(item);
            context.SendSimpleResponse();
        }
コード例 #26
0
 public static string GetFullItemPath(IWebDavStoreCollection collection)
 {
     System.Text.StringBuilder sb = new System.Text.StringBuilder();
     var current = collection;
     while (current != null)
     {
         sb.Insert(0, current.Name);
         sb.Append("/");
         current = current.ParentCollection;
     }
     sb.Length -= 1;
     return sb.ToString();
 }
 protected WebDavSqlStoreItem(IWebDavStoreCollection parentCollection, string path, String rootPath, Guid rootGuid, IWebDavStore store)
     : base(parentCollection, path, store)
 {
     if (IsNullOrWhiteSpace(path))
     {
         throw new ArgumentNullException(nameof(path));
     }
     RootGuid   = rootGuid;
     RootPath   = rootPath;
     _path      = path;
     ObjectGuid = GetObjectGuid(path);
     GetFileInfo();
 }
コード例 #28
0
        public static string GetFullItemPath(IWebDavStoreCollection collection)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            var current = collection;

            while (current != null)
            {
                sb.Insert(0, current.Name);
                sb.Append("/");
                current = current.ParentCollection;
            }
            sb.Length -= 1;
            return(sb.ToString());
        }
コード例 #29
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
        /// <param name="context">The
        /// <see cref="IHttpListenerContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        public void ProcessRequest(WebDavServer server, IHttpListenerContext context, IWebDavStore store)
        {
            // Get the parent collection of the item
            IWebDavStoreCollection collection = GetParentCollection(server, store, context.Request.Url);

            // Get the item from the collection
            IWebDavStoreItem item = GetItemFromCollection(collection, context.Request.Url);

            /***************************************************************************************************
            * Send the response
            ***************************************************************************************************/

            context.SendSimpleResponse(HttpStatusCode.NoContent);
        }
コード例 #30
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="context">The
        /// <see cref="IWebDavContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException"></exception>
        /// <exception cref="WebDavNotFoundException"><para>
        ///   <paramref name="context" /> specifies a request for a store item that does not exist.</para>
        /// <para>- or -</para>
        /// <para>
        ///   <paramref name="context" /> specifies a request for a store item that is not a document.</para></exception>
        /// <exception cref="WebDavConflictException"><paramref name="context" /> specifies a request for a store item using a collection path that does not exist.</exception>
        public void ProcessRequest(IWebDavContext context, IWebDavStore store)
        {
            IWebDavStoreCollection collection = GetParentCollection(store, context, context.Request.Url);
            IWebDavStoreItem       item       = GetItemFromCollection(collection, context.Request.Url);
            IWebDavStoreDocument   doc        = item as IWebDavStoreDocument;

            if (doc == null)
            {
                throw new WebDavNotFoundException();
            }

            long docSize = doc.Size;

            if (docSize == 0)
            {
                context.Response.StatusCode      = (int)HttpStatusCode.OK;
                context.Response.ContentLength64 = 0;
            }

            using (Stream stream = doc.OpenReadStream())
            {
                if (stream == null)
                {
                    context.Response.StatusCode      = (int)HttpStatusCode.OK;
                    context.Response.ContentLength64 = 0;
                }
                else
                {
                    context.Response.StatusCode = (int)HttpStatusCode.OK;

                    //todo Это статика. Надо определять MIME тип по расширению
                    context.Response.AppendHeader("Content-type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");

                    if (docSize > 0)
                    {
                        context.Response.ContentLength64 = docSize;
                    }

                    byte[] buffer = new byte[4096];
                    int    inBuffer;
                    while ((inBuffer = stream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        context.Response.OutputStream.Write(buffer, 0, inBuffer);
                    }
                    context.Response.OutputStream.Flush();
                }
            }
        }
コード例 #31
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
        /// <param name="context">The
        /// <see cref="IHttpListenerContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavMethodNotAllowedException"></exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavLengthRequiredException">If the ContentLength header was not found</exception>
        public void ProcessRequest(WebDavServer server, IHttpListenerContext context, IWebDavStore store)
        {
            // Get the parent collection
            IWebDavStoreCollection parentCollection = GetParentCollection(server, store, context.Request.Url);

            // Gets the item name from the url
            string itemName = Uri.UnescapeDataString(context.Request.Url.Segments.Last().TrimEnd('/', '\\'));

            IWebDavStoreItem     item = parentCollection.GetItemByName(itemName);
            IWebDavStoreDocument doc;

            if (item != null)
            {
                doc = item as IWebDavStoreDocument;
                if (doc == null)
                {
                    throw new WebDavMethodNotAllowedException();
                }
            }
            else
            {
                doc = parentCollection.CreateDocument(itemName);
            }

            if (context.Request.ContentLength64 < 0)
            {
                throw new WebDavLengthRequiredException();
            }

            using (Stream stream = doc.OpenWriteStream(false))
            {
                long   left   = context.Request.ContentLength64;
                byte[] buffer = new byte[4096];
                while (left > 0)
                {
                    int toRead   = Convert.ToInt32(Math.Min(left, buffer.Length));
                    int inBuffer = context.Request.InputStream.Read(buffer, 0, toRead);
                    stream.Write(buffer, 0, inBuffer);

                    left -= inBuffer;
                }
            }

            context.SendSimpleResponse(HttpStatusCode.Created);
        }
        /// <summary>
        /// </summary>
        /// <param name="parentCollection"></param>
        /// <param name="name"></param>
        /// <param name="rootPath"></param>
        /// <param name="rootGuid"></param>
        /// <param name="store"></param>
        public WebDavSqlStoreDocument(IWebDavStoreCollection parentCollection, string name, String rootPath, Guid rootGuid, IWebDavStore store)
            : base(parentCollection, name, rootPath, rootGuid, store)
        {
            using (var context = new OnlineFilesEntities())
            {
                File file = context.Files.AsNoTracking()
                    .Include(x => x.FileDatas)
                    .FirstOrDefault(d => d.pk_FileId == ObjectGuid && !d.IsDeleted);

                if (file == null)
                    throw new Exception("Non existant file.");
                _createDate = file.CreateDt;

                FileData lastmod = file.FileDatas.OrderByDescending(d => d.Revision).FirstOrDefault();

                _modificationDate = lastmod?.CreateDt ?? file.CreateDt;
                _filesize = lastmod?.Size ?? 1;
            }
        }
コード例 #33
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="context">The
        /// <see cref="IWebDavContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        /// <exception cref="WebDavNotFoundException"><para>
        ///   <paramref name="context" /> specifies a request for a store item that does not exist.</para>
        /// <para>- or -</para>
        /// <para>
        ///   <paramref name="context" /> specifies a request for a store item that is not a document.</para></exception>
        /// <exception cref="WebDavConflictException"><paramref name="context" /> specifies a request for a store item using a collection path that does not exist.</exception>
        public void ProcessRequest(IWebDavContext context, IWebDavStore store)
        {
            // Get the parent collection of the item
            IWebDavStoreCollection collection = GetParentCollection(store, context, context.Request.Url);

            // Get the item from the collection
            IWebDavStoreItem item = GetItemFromCollection(collection, context.Request.Url);

            /***************************************************************************************************
            * Send the response
            ***************************************************************************************************/

            // HttpStatusCode doesn't contain WebDav status codes, but HttpWorkerRequest can handle these WebDav status codes
            context.SetStatusCode();

            // set the headers of the response
            context.Response.ContentLength64 = 0;
            context.Response.AppendHeader("Content-Type", "text/html");
            context.Response.AppendHeader("Last-Modified", item.ModificationDate.ToUniversalTime().ToString("R"));
        }
コード例 #34
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
        /// <param name="context">The
        /// <see cref="IHttpListenerContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="response"></param>
        /// <param name="request"></param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        protected override void OnProcessRequest(
            WebDavServer server,
            IHttpListenerContext context,
            IWebDavStore store,
            XmlDocument request,
            XmlDocument response)
        {
            // Get the parent collection of the item
            IWebDavStoreCollection collection = GetParentCollection(server, store, context.Request.Url);

            // Get the item from the collection
            IWebDavStoreItem item = GetItemFromCollection(collection, context.Request.Url);

            // Deletes the item
            collection.Delete(item);
            //do not forget to clear all locks, if the object gets deleted there is no need to keep locks around.
            WebDavStoreItemLock.ClearLocks(context.Request.Url);

            context.SendSimpleResponse();
        }
コード例 #35
0
        /// <summary>
        /// Get the item in the collection from the requested
        /// <see cref="Uri" />.
        /// <see cref="WebDavException" /> 409 Conflict possible.
        /// </summary>
        /// <param name="collection">The parent collection as a <see cref="IWebDavStoreCollection" /></param>
        /// <param name="childUri">The <see cref="Uri" /> object containing the specific location of the child</param>
        /// <returns>
        /// The <see cref="IWebDavStoreItem" /> from the <see cref="IWebDavStoreCollection" />
        /// </returns>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavUnauthorizedException">If user is not authorized to get access to the item</exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException">If item not found.</exception>
        public static IWebDavStoreItem GetItemFromCollection(IWebDavStoreCollection collection, Uri childUri)
        {
            IWebDavStoreItem item;
            try
            {
                item = collection.GetItemByName(Uri.UnescapeDataString(childUri.Segments.Last().TrimEnd('/', '\\')));
            }
            catch (UnauthorizedAccessException)
            {
                throw new WebDavUnauthorizedException();
            }
            catch (WebDavNotFoundException)
            {
                throw new WebDavNotFoundException();
            }
            if (item == null)
                throw new WebDavNotFoundException();

            return item;
        }
コード例 #36
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
        /// <param name="context">The
        /// <see cref="IHttpListenerContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        /// <param name="response"></param>
        /// <param name="request"></param>
        protected override void OnProcessRequest(
            WebDavServer server,
            IHttpListenerContext context,
            IWebDavStore store,
            XmlDocument request,
            XmlDocument response)
        {
            if (!WebDavStoreItemLock.LockEnabled)
            {
                throw new WebDavNotImplementedException("Lock support disabled");
            }

            /***************************************************************************************************
            * Send the response
            ***************************************************************************************************/
            WindowsIdentity Identity     = (WindowsIdentity)Thread.GetData(Thread.GetNamedDataSlot(WebDavServer.HttpUser));
            var             unlockResult = WebDavStoreItemLock.UnLock(context.Request.Url, GetLockTokenHeader(context.Request), Identity.Name);

            IWebDavStoreCollection collection = GetParentCollection(server, store, context.Request.Url);

            try
            {
                var item = GetItemFromCollection(collection, context.Request.Url);
                if (item != null)
                {
                    //we already have an item
                    var resourceCanBeUnLocked = item.UnLock(Identity.Name);
                    if (!resourceCanBeUnLocked)
                    {
                        //TODO: decide what to do if the resource cannot be locked.
                    }
                }
            }
            catch (Exception ex)
            {
                WebDavServer.Log.Warn(
                    String.Format("Request unlock on a resource that does not exists: {0}", context.Request.Url), ex);
            }

            context.SendSimpleResponse(unlockResult);
        }
コード例 #37
0
        /// <summary>
        /// Convert the given
        /// <see cref="IWebDavStoreItem" /> to a
        /// <see cref="List{T}" /> of
        /// <see cref="IWebDavStoreItem" />
        /// This list depends on the "Depth" header
        /// </summary>
        /// <param name="iWebDavStoreItem">The <see cref="IWebDavStoreItem" /> that needs to be converted</param>
        /// <param name="depth">The "Depth" header</param>
        /// <returns>
        /// A <see cref="List{T}" /> of <see cref="IWebDavStoreItem" />
        /// </returns>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavConflictException"></exception>
        private static List <IWebDavStoreItem> GetWebDavStoreItems(IWebDavStoreItem iWebDavStoreItem, int depth)
        {
            //ILog _log = LogManager.GetCurrentClassLogger();
            ILog _log = LogManager.GetLogger("Logger");
            List <IWebDavStoreItem> list = new List <IWebDavStoreItem>();

            //IWebDavStoreCollection
            // if the item is a collection
            IWebDavStoreCollection collection = iWebDavStoreItem as IWebDavStoreCollection;

            if (collection != null)
            {
                list.Add(collection);
                if (depth == 0)
                {
                    return(list);
                }
                foreach (IWebDavStoreItem item in collection.Items)
                {
                    try
                    {
                        list.Add(item);
                    }
                    catch (Exception ex)
                    {
                        _log.Debug(ex.Message + "\r\n" + ex.StackTrace);
                    }
                }
                return(list);
            }
            // if the item is not a document, throw conflict exception
            if (!(iWebDavStoreItem is IWebDavStoreDocument))
            {
                throw new WebDavConflictException();
            }

            // add the item to the list
            list.Add(iWebDavStoreItem);

            return(list);
        }
 public WebDavSqlStoreCollection GetCollection(IWebDavStoreCollection parentCollection, string path, String rootPath, Guid rootGuid)
 {
     var p = PrincipleFactory.Instance.GetPrinciple(FromType.WebDav);
     string userkey = p.UserProfile.SecurityObjectId.ToString();
     CacheBase mc = GetCachedObject(path) as CacheBase;
     WebDavSqlStoreCollection itm = null;
     if (mc != null)
         itm = mc.GetCachedObject(userkey) as WebDavSqlStoreCollection;
     if (itm != null)
         return itm;
     itm = new WebDavSqlStoreCollection(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;
 }
コード例 #39
0
        /// <summary>
        /// </summary>
        /// <param name="parentCollection"></param>
        /// <param name="name"></param>
        /// <param name="rootPath"></param>
        /// <param name="rootGuid"></param>
        /// <param name="store"></param>
        public WebDavSqlStoreDocument(IWebDavStoreCollection parentCollection, string name, String rootPath, Guid rootGuid, IWebDavStore store)
            : base(parentCollection, name, rootPath, rootGuid, store)
        {
            using (var context = new OnlineFilesEntities())
            {
                File file = context.Files.AsNoTracking()
                            .Include(x => x.FileDatas)
                            .FirstOrDefault(d => d.pk_FileId == ObjectGuid && !d.IsDeleted);

                if (file == null)
                {
                    throw new Exception("Non existant file.");
                }
                _createDate = file.CreateDt;

                FileData lastmod = file.FileDatas.OrderByDescending(d => d.Revision).FirstOrDefault();

                _modificationDate = lastmod?.CreateDt ?? file.CreateDt;
                _filesize         = lastmod?.Size ?? 1;
            }
        }
コード例 #40
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
        /// <param name="context">The
        /// <see cref="IHttpListenerContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavUnsupportedMediaTypeException"></exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavMethodNotAllowedException"></exception>
        public void ProcessRequest(WebDavServer server, IHttpListenerContext context, IWebDavStore store)
        {
            if (context.Request.ContentLength64 > 0)
            {
                throw new WebDavUnsupportedMediaTypeException();
            }

            IWebDavStoreCollection collection = GetParentCollection(server, store, context.Request.Url);

            string collectionName = Uri.UnescapeDataString(
                context.Request.Url.Segments.Last().TrimEnd('/', '\\')
                );

            if (collection.GetItemByName(collectionName) != null)
            {
                throw new WebDavMethodNotAllowedException();
            }

            collection.CreateCollection(collectionName);

            context.SendSimpleResponse(HttpStatusCode.Created);
        }
コード例 #41
0
        /// <summary>
        /// Get the item in the collection from the requested
        /// <see cref="Uri" />.
        /// <see cref="WebDavException" /> 409 Conflict possible.
        /// </summary>
        /// <param name="collection">The parent collection as a <see cref="IWebDavStoreCollection" /></param>
        /// <param name="childUri">The <see cref="Uri" /> object containing the specific location of the child</param>
        /// <returns>
        /// The <see cref="IWebDavStoreItem" /> from the <see cref="IWebDavStoreCollection" />
        /// </returns>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavUnauthorizedException">If user is not authorized to get access to the item</exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException">If item not found.</exception>
        public static IWebDavStoreItem GetItemFromCollection(IWebDavStoreCollection collection, Uri childUri)
        {
            IWebDavStoreItem item;

            try
            {
                item = collection.GetItemByName(Uri.UnescapeDataString(childUri.Segments.Last().TrimEnd('/', '\\')));
            }
            catch (UnauthorizedAccessException)
            {
                throw new WebDavUnauthorizedException();
            }
            catch (WebDavNotFoundException)
            {
                throw new WebDavNotFoundException();
            }
            if (item == null)
            {
                throw new WebDavNotFoundException();
            }

            return(item);
        }
コード例 #42
0
 ///
 public WebDavDiskStore(IWebDavStoreCollection root, IWebDavStoreItemLock lockSystem)
     : base(root, lockSystem)
 {
 }
コード例 #43
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="WebDavStoreItemBase" /> class.
 /// </summary>
 /// <param name="parentCollection">
 ///     The parent <see cref="IWebDavStoreCollection" /> that contains this
 ///     <see cref="IWebDavStoreItem" /> implementation.
 /// </param>
 /// <param name="name">The name of this <see cref="IWebDavStoreItem" /></param>
 /// <param name="store"></param>
 /// <exception cref="ArgumentNullException"><paramref name="name" /> is <c>null</c>.</exception>
 protected WebDavStoreDocumentBase(IWebDavStoreCollection parentCollection, string name, IWebDavStore store)
     : base(parentCollection, name, store)
 {
 }
コード例 #44
0
        /// <summary>
        /// Get the item in the collection from the requested
        /// <see cref="Uri" />.
        /// <see cref="WebDavException" /> 409 Conflict possible.
        /// </summary>
        /// <param name="collection">The parent collection as a <see cref="IWebDavStoreCollection" /></param>
        /// <param name="childUri">The <see cref="Uri" /> object containing the specific location of the child</param>
        /// <returns>
        /// The <see cref="IWebDavStoreItem" /> from the <see cref="IWebDavStoreCollection" />
        /// </returns>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavUnauthorizedException">If user is not authorized to get access to the item</exception>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavNotFoundException">If item not found.</exception>
        public static IWebDavStoreItem GetItemFromCollection(IWebDavStoreCollection collection, Uri childUri)
        {
            IWebDavStoreItem item;
            String name = null;
            try
            {
                name = childUri.GetLastSegment(); 
                item = collection.GetItemByName(name);
            }
            catch (UnauthorizedAccessException)
            {
                throw new WebDavUnauthorizedException();
            }
            catch (WebDavNotFoundException wex)
            {
                throw new WebDavNotFoundException(String.Format("Cannot found name {0} from uri {1} father {2}", name, childUri, collection.ItemPath), wex);
            }
            if (item == null)
                throw new WebDavNotFoundException(String.Format("Cannot found name {0} from uri {1} father {2}", name, childUri, collection.ItemPath));

            return item;
        }