Esempio n. 1
0
 /// <summary>
 /// </summary>
 /// <param name="rootPath"></param>
 /// <param name="rootGuid"></param>
 /// <param name="lockSystem"></param>
 public WebDavSqlStore(string rootPath, Guid rootGuid, IWebDavStoreItemLock lockSystem)
     : base(lockSystem)
 {
     RootPath = rootPath;
     WebDavSqlStoreCollectionFactory.Instance.Store   = this;
     WebDavSqlStoreCollectionFactory.Instance.Enabled = true;
     WebDavSqlStoreDocumentFactory.Instance.Store     = this;
     WebDavSqlStoreDocumentFactory.Instance.Enabled   = true;
 }
 /// <summary>
 /// </summary>
 /// <param name="rootPath"></param>
 /// <param name="rootGuid"></param>
 /// <param name="lockSystem"></param>
 public WebDavSqlStore(string rootPath, Guid rootGuid, IWebDavStoreItemLock lockSystem)
     : base(lockSystem)
 {
     RootPath = rootPath;
     WebDavSqlStoreCollectionFactory.Instance.Store = this;
     WebDavSqlStoreCollectionFactory.Instance.Enabled = true;
     WebDavSqlStoreDocumentFactory.Instance.Store = this;
     WebDavSqlStoreDocumentFactory.Instance.Enabled = true;
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="WebDavDiskStore" /> class.
        /// </summary>
        /// <param name="rootPath">The root path of a folder on disk to host in this <see cref="WebDavDiskStore" />.</param>
        /// <param name="lockSystem"></param>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.IO.DirectoryNotFoundException"></exception>
        /// <exception cref="ArgumentNullException"><paramref name="rootPath" /> is <c>null</c>.</exception>
        /// <exception cref="DirectoryNotFoundException"><paramref name="rootPath" /> specifies a folder that does not exist.</exception>
        public WebDavDiskStore(string rootPath, IWebDavStoreItemLock lockSystem)
            : base(lockSystem)
        {
            if (rootPath == null)
                throw new ArgumentNullException(nameof(rootPath));
            if (!Directory.Exists(rootPath))
                throw new DirectoryNotFoundException(rootPath);

            _rootPath = rootPath;
        }
        /// <summary>
        /// </summary>
        /// <param name="path"></param>
        /// <param name="lockscope"></param>
        /// <param name="locktype"></param>
        /// <param name="owner"></param>
        /// <param name="requestedlocktimeout"></param>
        /// <param name="token"></param>
        /// <param name="requestdocument"></param>
        /// <param name="depth"></param>
        /// <param name="lockSystem"></param>
        /// <param name="createdate"></param>
        protected WebDavStoreItemLockInstanceBase(string path, WebDavLockScope lockscope, WebDavLockType locktype, string owner, double? requestedlocktimeout, Guid? token, XmlDocument requestdocument, int depth, IWebDavStoreItemLock lockSystem, DateTime? createdate = null)
        {
            Path = path;
            LockScope = lockscope;
            LockType = locktype;
            Owner = owner;
            Token = token;
            RequestDocument = requestdocument;
            Token = token; // token = "urn:uuid:" + Guid.NewGuid();     
            Depth = depth;
            LockSystem = lockSystem;

            if (createdate == null)
                CreateDate = DateTime.Now;
            else
                CreateDate = (DateTime) createdate;

            RequestedLockTimeout = requestedlocktimeout;

            RefreshLock(requestedlocktimeout);
        }
        /// <summary>
        ///     Returns the XML Format according to RFC
        ///     Name:
        ///     lockdiscovery
        ///     Purpose:
        ///     Describes the active locks on a resource
        ///     Protected:
        ///     MUST be protected. Clients change the list of locks through LOCK and UNLOCK, not through PROPPATCH.
        ///     COPY/MOVE behavior:
        ///     The value of this property depends on the lock state of the destination, not on the locks of the source resource.
        ///     Recall
        ///     that locks are not moved in a MOVE operation.
        ///     Description:
        ///     Returns a listing of who has a lock, what type of lock he has, the timeout type and the time remaining on the
        ///     timeout,
        ///     and the associated lock token. Owner information MAY be omitted if it is considered sensitive. If there are no
        ///     locks, but
        ///     the server supports locks, the property will be present but contain zero 'activelock' elements. If there are one or
        ///     more locks,
        ///     an 'activelock' element appears for each lock on the resource. This property is NOT lockable with respect to write
        ///     locks (Section 7).
        /// </summary>
        /// <param name="storeItem"></param>
        /// <param name="responsedoc"></param>
        /// <param name="lockSystem"></param>
        /// <returns></returns>
        private static XmlNode LockDiscovery(IWebDavStoreItem storeItem, ref XmlDocument responsedoc, IWebDavStoreItemLock lockSystem)
        {
            XmlNode node = new WebDavProperty("lockdiscovery").ToXmlElement(responsedoc);
            foreach (IWebDavStoreItemLockInstance ilock in lockSystem.GetLocks(storeItem))
            {
                XmlNode activelock = new WebDavProperty("activelock").ToXmlElement(responsedoc);
                node.AppendChild(activelock);

                XmlNode locktype = new WebDavProperty("locktype").ToXmlElement(responsedoc);
                activelock.AppendChild(locktype);

                XmlNode locktypeitem = new WebDavProperty(ilock.LockType.ToString().ToLower()).ToXmlElement(responsedoc);
                locktype.AppendChild(locktypeitem);

                XmlNode lockscope = new WebDavProperty("lockscope").ToXmlElement(responsedoc);
                activelock.AppendChild(lockscope);

                XmlNode lockscopeitem = new WebDavProperty(ilock.LockScope.ToString().ToLower()).ToXmlElement(responsedoc);
                lockscope.AppendChild(lockscopeitem);

                XmlNode depth = new WebDavProperty("depth").ToXmlElement(responsedoc);
                depth.InnerText = ilock.Depth.ToString(CultureInfo.InvariantCulture);
                activelock.AppendChild(depth);

                XmlNode owner = new WebDavProperty("owner").ToXmlElement(responsedoc);
                owner.InnerText = ilock.Owner;
                activelock.AppendChild(owner);

                XmlNode timeout = new WebDavProperty("timeout").ToXmlElement(responsedoc);
                timeout.InnerText = ilock.RequestedTimeout;
                activelock.AppendChild(timeout);

                XmlNode locktoken = new WebDavProperty("locktoken").ToXmlElement(responsedoc);
                activelock.AppendChild(locktoken);

                XmlNode tokenhref = new WebDavProperty("href").ToXmlElement(responsedoc);
                tokenhref.InnerText = ilock.Token.ToLockToken();
                locktoken.AppendChild(tokenhref);

                XmlNode lockroot = new WebDavProperty("lockroot").ToXmlElement(responsedoc);
                activelock.AppendChild(lockroot);

                XmlNode lockroothref = new WebDavProperty("href").ToXmlElement(responsedoc);
                lockroothref.InnerText = ilock.Path;
                lockroot.AppendChild(lockroothref);
            }

            return node;
        }
        /// <summary>
        ///     Builds the <see cref="XmlDocument" /> containing the response body
        /// </summary>
        /// <param name="context">The <see cref="IHttpListenerContext" /></param>
        /// <param name="propname">The boolean defining the Propfind propname request</param>
        /// <param name="requestUri"></param>
        /// <param name="requestedProperties"></param>
        /// <param name="webDavStoreItems"></param>
        /// <param name="lockSystem"></param>
        /// <param name="store"></param>
        /// <returns>
        ///     The <see cref="XmlDocument" /> containing the response body
        /// </returns>
        private string ResponseDocument(IHttpListenerContext context, bool propname, Uri requestUri, List<WebDavProperty> requestedProperties, List<IWebDavStoreItem> webDavStoreItems, IWebDavStoreItemLock lockSystem, IWebDavStore store)
        {
            // Create the basic response XmlDocument
            XmlDocument responseDoc = new XmlDocument();
            const string responseXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:multistatus xmlns:D=\"DAV:\" xmlns:Office=\"urn:schemas-microsoft-com:office:office\" xmlns:Repl=\"http://schemas.microsoft.com/repl/\" xmlns:Z=\"urn:schemas-microsoft-com:\"></D:multistatus>";
            responseDoc.LoadXml(responseXml);
            // Generate the manager
            XmlNamespaceManager manager = new XmlNamespaceManager(responseDoc.NameTable);
            manager.AddNamespace("D", "DAV:");
            manager.AddNamespace("Office", "schemas-microsoft-com:office:office");
            manager.AddNamespace("Repl", "http://schemas.microsoft.com/repl/");
            manager.AddNamespace("Z", "urn:schemas-microsoft-com:");
            List<string> xmlFragments = new List<string>();
            int count = 0;
            foreach (IWebDavStoreItem webDavStoreItem in webDavStoreItems)
            {
                string frag;
                if (count == 0)
                {
                    frag = CreateFragment(true, responseDoc, webDavStoreItem, context, propname, requestUri, requestedProperties, lockSystem);
                }
                else
                {
                    WindowsIdentity userIdentity = (WindowsIdentity) Thread.GetData(Thread.GetNamedDataSlot(WebDavServer.HttpUser));
                    string cacheValue = (string) store.GetCacheObject(this, userIdentity.Name, webDavStoreItem.ItemPath);
                    if (cacheValue != null)
                    {
                        xmlFragments.Add(cacheValue);
                        continue;
                    }
                    frag = CreateFragment(false, responseDoc, webDavStoreItem, context, propname, requestUri, requestedProperties, lockSystem);
                    store.AddCacheObject(this, userIdentity.Name, webDavStoreItem.ItemPath, frag);
                }

                count++;

                xmlFragments.Add(frag);
            }

            StringBuilder sb = new StringBuilder(5000);
            sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:multistatus xmlns:D=\"DAV:\" xmlns:Office=\"urn:schemas-microsoft-com:office:office\" xmlns:Repl=\"http://schemas.microsoft.com/repl/\" xmlns:Z=\"urn:schemas-microsoft-com:\">");
            foreach (string xmlFragment in xmlFragments)
                sb.Append(xmlFragment);
            sb.Append("</D:multistatus>");

            string t = sb.ToString();

            return t;
        }
        internal string CreateFragment(bool isRoot, XmlDocument responseDoc, IWebDavStoreItem webDavStoreItem, IHttpListenerContext context, bool propname, Uri requestUri, List<WebDavProperty> requestedProperties, IWebDavStoreItemLock lockSystem)
        {
            // Create the response element
            WebDavProperty responseProperty = new WebDavProperty("response", Empty);
            XmlElement responseElement = responseProperty.ToXmlElement(responseDoc);

            // The href element
            Uri result;
            if (isRoot)
                Uri.TryCreate(requestUri, Empty, out result);
            else
                Uri.TryCreate(requestUri, webDavStoreItem.Name, out result);

            WebDavProperty hrefProperty = new WebDavProperty("href", result.AbsoluteUri);
            responseElement.AppendChild(hrefProperty.ToXmlElement(responseDoc));

            // The propstat element
            WebDavProperty propstatProperty = new WebDavProperty("propstat", Empty);
            XmlElement propstatElement = propstatProperty.ToXmlElement(responseDoc);

            // The prop element
            WebDavProperty propProperty = new WebDavProperty("prop", Empty);
            XmlElement propElement = propProperty.ToXmlElement(responseDoc);


            //All properties but lockdiscovery and supportedlock can be handled here.
            foreach (WebDavProperty davProperty in requestedProperties)
            {
                XmlNode toAdd;
                switch (davProperty.Name)
                {
                    case "lockdiscovery":
                        toAdd = LockDiscovery(webDavStoreItem, ref responseDoc, lockSystem);
                        break;
                    case "supportedlock":
                        toAdd = SupportedLocks(ref responseDoc);
                        break;
                    default:
                        toAdd = PropChildElement(davProperty, responseDoc, webDavStoreItem, propname);
                        break;
                }

                if (toAdd != null)
                    propElement.AppendChild(toAdd);
            }


            // Add the prop element to the propstat element
            propstatElement.AppendChild(propElement);

            // The status element
            WebDavProperty statusProperty = new WebDavProperty("status", "HTTP/1.1 " + context.Response.StatusCode + " " + HttpWorkerRequest.GetStatusDescription(context.Response.StatusCode));
            propstatElement.AppendChild(statusProperty.ToXmlElement(responseDoc));

            // Add the propstat element to the response element
            responseElement.AppendChild(propstatElement);

            if (responseDoc.DocumentElement == null)
                throw new Exception("Not Possible.");

            return responseElement.OuterXml.Replace("xmlns:D=\"DAV:\"", "");
        }
 public WebDavSqlStoreItemLockInstance(SecurityObject so, string path, WebDavLockScope lockscope, WebDavLockType locktype, string owner, double? requestedlocktimeout, Guid? token, XmlDocument requestdocument, int depth, IWebDavStoreItemLock lockSystem, DateTime? createdate = null)
     : base(path, lockscope, locktype, owner, requestedlocktimeout, token, requestdocument, depth, lockSystem, createdate)
 {
     SoOwner = so;
 }
 public WebDavSqlStoreItemLockInstance(SecurityObject so, string path, WebDavLockScope lockscope, WebDavLockType locktype, string owner, double?requestedlocktimeout, Guid?token, XmlDocument requestdocument, int depth, IWebDavStoreItemLock lockSystem, DateTime?createdate = null)
     : base(path, lockscope, locktype, owner, requestedlocktimeout, token, requestdocument, depth, lockSystem, createdate)
 {
     SoOwner = so;
 }
 ///
 public WebDavDiskStore(IWebDavStoreCollection root, IWebDavStoreItemLock lockSystem)
     : base(root, lockSystem)
 {
 }