WebDAVLockRequest ParseRequest(OSHttpRequest request) { WebDAVLockRequest lockRequest = new WebDAVLockRequest(); lockRequest.Path = request.Url.AbsolutePath; lockRequest.RequestedTimeout = request.Headers.GetValues("timeout"); //can contain multiple values, for example: "Timeout: Infinite, Second-604800" lockRequest.IfHeaders = request.Headers.GetValues("If"); //might be a request to refresh lock if (request.ContentLength != 0) { XPathNavigator requestNavigator = new XPathDocument(request.InputStream).CreateNavigator(); XPathNodeIterator propNodeIterator = requestNavigator.SelectDescendants("lockinfo", "DAV:", false); if (propNodeIterator.MoveNext()) { XPathNodeIterator nodeChildren = propNodeIterator.Current.SelectChildren(XPathNodeType.All); while (nodeChildren.MoveNext()) { XPathNavigator currentNode = nodeChildren.Current; if (currentNode.LocalName == "lockscope") { if (currentNode.HasChildren) { if (currentNode.MoveToFirstChild()) { lockRequest.LockScope = (LockScope)Enum.Parse(typeof(LockScope), currentNode.LocalName.ToLower()); currentNode.MoveToParent(); } } } else if (currentNode.LocalName == "owner") { lockRequest.OwnerNamespaceUri = currentNode.NamespaceURI; if (currentNode.Value != null && currentNode.Value != String.Empty) lockRequest.OwnerValue = currentNode.Value; if (currentNode.MoveToFirstChild()) { lockRequest.OwnerValues.Add(currentNode.LocalName, currentNode.Value); while (currentNode.MoveToNext()) { lockRequest.OwnerValues.Add(currentNode.LocalName, currentNode.Value); } currentNode.MoveToParent(); } } else if (currentNode.LocalName == "locktype") { if (currentNode.MoveToFirstChild()) { lockRequest.LockType = (LockType)Enum.Parse(typeof(LockType), currentNode.LocalName.ToLower()); currentNode.MoveToParent(); } } } } } return lockRequest; }
internal WebDAVLockResponse OnLockConnector(WebDAVLockRequest request) { if (OnLock != null) { try { return OnLock(request); } catch (Exception ex) { Console.WriteLine("Caught exception in OnLock callback: " + ex); } } return null; }