Exemple #1
0
        /// <summary>
        /// Append a resource's properties to the xml text writer
        /// </summary>
        /// <param name="davResource"></param>
        /// <param name="xmlWriter"></param>
        private static void AppendResourceNodeProperties(DavResourceBase davResource, XmlTextWriter xmlWriter)
        {
            //Open the response element
            xmlWriter.WriteStartElement("response", "DAV:");

            //Load the valid items HTTP/1.1 200 OK
            xmlWriter.WriteElementString("href", "DAV:", davResource.ResourcePath);

            //Open the propstat element section
            xmlWriter.WriteStartElement("propstat", "DAV:");

            //Open the prop element section
            xmlWriter.WriteStartElement("prop", "DAV:");

            //Load the valid properties
            foreach (DavProperty _davProperty in davResource.ResourceProperties)
            {
                _davProperty.ToXML(xmlWriter);
            }

            //Close the prop element section
            xmlWriter.WriteEndElement();

            //Write the status record
            xmlWriter.WriteElementString("status", "DAV:", InternalFunctions.GetEnumHttpResponse(ServerResponseCode.Ok));

            //Close the propstat element section
            xmlWriter.WriteEndElement();
            //END Load the valid items HTTP/1.1 200 OK

            //Close the response element
            xmlWriter.WriteEndElement();
        }
Exemple #2
0
        /// <summary>
        /// Append a resource to the xml text writer
        /// </summary>
        /// <param name="davResource"></param>
        /// <param name="requestedProperties"></param>
        /// <param name="xmlWriter"></param>
        private static void AppendResourceNode(DavResourceBase davResource, DavPropertyCollection requestedProperties, XmlTextWriter xmlWriter)
        {
            DavPropertyCollection _validProperties   = new DavPropertyCollection();
            DavPropertyCollection _invalidProperties = new DavPropertyCollection();

            davResource.GetPropertyValues(requestedProperties, _validProperties, _invalidProperties);

            //Open the response element
            xmlWriter.WriteStartElement("response", "DAV:");

            //Load the valid items HTTP/1.1 200 OK
            xmlWriter.WriteElementString("href", "DAV:", davResource.ResourcePath);

            //Open the propstat element section
            xmlWriter.WriteStartElement("propstat", "DAV:");

            //Open the prop element section
            xmlWriter.WriteStartElement("prop", "DAV:");

            //Load the valid properties
            foreach (DavProperty _davProperty in _validProperties)
            {
                _davProperty.ToXML(xmlWriter);
            }

            //Close the prop element section
            xmlWriter.WriteEndElement();

            //Write the status record
            xmlWriter.WriteElementString("status", "DAV:", InternalFunctions.GetEnumHttpResponse(ServerResponseCode.Ok));

            //Close the propstat element section
            xmlWriter.WriteEndElement();
            //END Load the valid items HTTP/1.1 200 OK

            //Load the invalid items HTTP/1.1 404 Not Found
            if (_invalidProperties.Count > 0)
            {
                xmlWriter.WriteStartElement("propstat", "DAV:");
                xmlWriter.WriteElementString("status", "DAV:", InternalFunctions.GetEnumHttpResponse(ServerResponseCode.NotFound));

                //Open the prop element section
                xmlWriter.WriteStartElement("prop", "DAV:");

                //Load all the invalid properties
                foreach (DavProperty _davProperty in _invalidProperties)
                {
                    _davProperty.ToXML(xmlWriter);
                }

                //Close the prop element section
                xmlWriter.WriteEndElement();
                //Close the propstat element section
                xmlWriter.WriteEndElement();
            }
            //END Load the invalid items HTTP/1.1 404 Not Found

            //Close the response element
            xmlWriter.WriteEndElement();
        }
Exemple #3
0
        private int DavLockBase_InternalProcessDavRequest(object sender, EventArgs e)
        {
            int _responseCode = (int)DavLockResponseCode.Ok;

            string[] _lockTokens = this.RequestLock.GetLockTokens();

            //Check to see if a lock refresh was requested
            if (base.HttpApplication.Request.Headers["If"] != null)
            {
                if (_lockTokens.Length == 1)
                {
                    DavRefreshEventArgs _refreshEventArgs = new DavRefreshEventArgs(_lockTokens[0], this.RequestLock.LockTimeout);
                    OnRefreshLockDavRequest(_refreshEventArgs);
                }

                base.HttpApplication.Response.AppendHeader("Timeout", "Second-" + this.ResponseLock.LockTimeout);
            }
            else
            {
                //New lock request
                StringBuilder _opaquelockTokens = new StringBuilder();
                foreach (string _lockToken in _lockTokens)
                {
                    _opaquelockTokens.Append("<opaquelocktoken:" + _lockToken + ">");
                }

                base.HttpApplication.Response.AppendHeader("Lock-Token", _opaquelockTokens.ToString());
            }

            //Check to see if there were any process errors...
            Enum[] _errorResources = this.ProcessErrorResources;
            if (_errorResources.Length > 0)
            {
                //Append a response node
                XmlDocument _xmlDocument  = new XmlDocument();
                XmlNode     _responseNode = _xmlDocument.CreateNode(XmlNodeType.Element, _xmlDocument.GetPrefixOfNamespace("DAV:"), "response", "DAV:");

                //Add the HREF
                XmlElement _requestLockHrefElement = _xmlDocument.CreateElement("href", "DAV:");
                _requestLockHrefElement.InnerText = base.RelativeRequestPath;
                _responseNode.AppendChild(_requestLockHrefElement);


                //Add the propstat
                XmlElement _propstatElement      = _xmlDocument.CreateElement("propstat", "DAV:");
                XmlElement _propElement          = _xmlDocument.CreateElement("prop", "DAV:");
                XmlElement _lockDiscoveryElement = _xmlDocument.CreateElement("lockdiscovery", "DAV:");
                _propElement.AppendChild(_lockDiscoveryElement);
                _propstatElement.AppendChild(_propElement);

                XmlElement _statusElement = _xmlDocument.CreateElement("status", "DAV:");
                _statusElement.InnerText = InternalFunctions.GetEnumHttpResponse(DavLockResponseCode.FailedDependency);
                _propstatElement.AppendChild(_statusElement);

                _responseNode.AppendChild(_propstatElement);

                base.SetResponseXml(InternalFunctions.ProcessErrorRequest(this.ProcessErrors, _responseNode));
                _responseCode = (int)ServerResponseCode.MultiStatus;
            }
            else
            {
                //No issues
                using (Stream _responseStream = new MemoryStream())
                {
                    XmlTextWriter _xmlWriter = new XmlTextWriter(_responseStream, new UTF8Encoding(false));

                    _xmlWriter.Formatting  = Formatting.Indented;
                    _xmlWriter.IndentChar  = '\t';
                    _xmlWriter.Indentation = 1;
                    _xmlWriter.WriteStartDocument();

                    //Open the prop element section
                    _xmlWriter.WriteStartElement("D", "prop", "DAV:");
                    _xmlWriter.WriteStartElement("lockdiscovery", "DAV:");
                    this.ResponseLock.ActiveLock.WriteTo(_xmlWriter);
                    _xmlWriter.WriteEndElement();
                    _xmlWriter.WriteEndElement();

                    _xmlWriter.WriteEndDocument();
                    _xmlWriter.Flush();

                    base.SetResponseXml(_responseStream);
                    _xmlWriter.Close();
                }
            }

            return(_responseCode);
        }
Exemple #4
0
        private int DavPropPatchBase_InternalProcessDavRequest(object sender, EventArgs e)
        {
            if (this.PatchedResource == null)
            {
                base.AbortRequest(ServerResponseCode.NotFound);
            }
            else
            {
                using (Stream _responseStream = new MemoryStream())
                {
                    XmlTextWriter _xmlWriter = new XmlTextWriter(_responseStream, new UTF8Encoding(false));

                    _xmlWriter.Formatting  = Formatting.Indented;
                    _xmlWriter.IndentChar  = '\t';
                    _xmlWriter.Indentation = 1;
                    _xmlWriter.WriteStartDocument();

                    //Set the Multistatus
                    _xmlWriter.WriteStartElement("D", "multistatus", "DAV:");

                    //Open the response element
                    _xmlWriter.WriteStartElement("response", "DAV:");

                    //Load the valid items HTTP/1.1 200 OK
                    _xmlWriter.WriteElementString("href", "DAV:", this.PatchedResource.ResourcePath);

                    //Check to see what properties have been added / removed
                    this.RequestDeleteProperties
                    .Concat(this.RequestModifyProperties)
                    .ForEach
                    (
                        _prop =>
                    {
                        //Open the propstat element section
                        _xmlWriter.WriteStartElement("propstat", "DAV:");

                        //Open the prop element section
                        _xmlWriter.WriteStartElement("prop", "DAV:");

                        _xmlWriter.WriteStartElement(_prop.Name, _prop.Namespace);
                        _xmlWriter.WriteEndElement();

                        //Close the prop element section
                        _xmlWriter.WriteEndElement();

                        int _count = this.PatchedResource.CustomProperties
                                     .Count
                                     (
                            p => p.Name == _prop.Name &&
                            p.Namespace == _prop.Namespace
                                     );

                        if (_count == 0)
                        {
                            _xmlWriter.WriteElementString("status", "DAV:", InternalFunctions.GetEnumHttpResponse(ServerResponseCode.NotFound));
                        }
                        else
                        {
                            _xmlWriter.WriteElementString("status", "DAV:", InternalFunctions.GetEnumHttpResponse(ServerResponseCode.Ok));
                        }

                        //Close the propstat element section
                        _xmlWriter.WriteEndElement();
                    }
                    );

                    //Close the response element
                    _xmlWriter.WriteEndElement();

                    //Close the Multistatus element
                    _xmlWriter.WriteEndElement();
                    _xmlWriter.WriteEndDocument();
                    _xmlWriter.Flush();

                    base.SetResponseXml(_responseStream);
                    _xmlWriter.Close();
                }
            }

            return((int)ServerResponseCode.MultiStatus);
        }