Esempio n. 1
0
        /// <summary>
        /// Create a usual Response Element for an directory
        /// </summary>
        /// <param name="xmlDocument"></param>
        /// <param name="hRef"></param>
        /// <param name="displayname"></param>
        /// <returns></returns>
        private XmlElement CreateResponseElement_Dir(HTTPHeader header, XmlDocument xmlDocument, String hRef, String displayname, IDirectoryObject directoryObject, PropfindProperties propfindProperties)
        {
            String CreationDate = "";
            String LastModificationDate = "";

            //if (DirectoryObject != null && DirectoryObject.INodeReference != null)
            //{
            //    CreationDate = GetConvertedDateTime(DirectoryObject.INodeReference.CreationTime).ToString(S_DATETIME_FORMAT);
            //    LastModificationDate = GetConvertedDateTime(DirectoryObject.INodeReference.LastModificationTime).ToString(S_DATETIME_FORMAT);
            //}

            XmlElement ElemResponse = xmlDocument.CreateElement(S_DAV_PREFIX, "response", S_DAV_NAMESPACE_URI);
            #region response elements

            XmlElement ElemHref = xmlDocument.CreateElement(S_DAV_PREFIX, "href", S_DAV_NAMESPACE_URI);
            ElemHref.InnerText = hRef;

            Dictionary<String, String> Props = new Dictionary<String, String>();
            /*
            if (myPropfindProperties == PropfindProperties.NONE)
            {
                // Should return ALL props

                Props.Add(PropfindProperties.Creationdate.ToString(), CreationDate);//, "2008-12-29T15:28:29Z");
                Props.Add(PropfindProperties.Displayname.ToString(), Displayname);
                Props.Add(PropfindProperties.Getcontentlanguage.ToString(), ""); // If no Content-Language is specified, the default is that the content is intended for all language audiences.
                Props.Add(PropfindProperties.Getcontentlength.ToString(), "0");
                Props.Add(PropfindProperties.Getcontenttype.ToString(), System.Net.Mime.MediaTypeNames.Application.Octet);
                Props.Add(PropfindProperties.Getetag.ToString(), CacheUUID.NewGuid().ToString()); // to identify a single ressource for update purposes (see If-Match)
                Props.Add(PropfindProperties.Getlastmodified.ToString(), LastModificationDate);//"2009-02-09T08:11:12Z");
                Props.Add(PropfindProperties.Lockdiscovery.ToString(), "");
                Props.Add(PropfindProperties.Resourcetype.ToString(), "collection");
                Props.Add(PropfindProperties.Supportedlock.ToString(), "");

                // Do we want to add some MS specific data?
                if (Header.ClientType == ClientTypes.MicrosoftWebDAVMiniRedir)
                {
                    //Props.Add("isFolder", "f");
                    //If the element contains the 'collection' child element plus additional unrecognized elements, it should generally be treated as a collection. If the element contains no recognized child elements, it should be treated as a non-collection resource
                    //Props.Add("isCollection", "1");
                    //Props.Add("ishidden", "0");
                }

            }else{
                */
            if ((propfindProperties == PropfindProperties.NONE) || ((propfindProperties & PropfindProperties.Creationdate)       == PropfindProperties.Creationdate))
                Props.Add(PropfindProperties.Creationdate.ToString(), CreationDate);
            if ((propfindProperties == PropfindProperties.NONE) || ((propfindProperties & PropfindProperties.Displayname)        == PropfindProperties.Displayname))
                Props.Add(PropfindProperties.Displayname.ToString(), displayname);
            if ((propfindProperties == PropfindProperties.NONE) || ((propfindProperties & PropfindProperties.Getcontentlanguage) == PropfindProperties.Getcontentlanguage))
                Props.Add(PropfindProperties.Getcontentlanguage.ToString(), "");
            if ((propfindProperties == PropfindProperties.NONE) || ((propfindProperties & PropfindProperties.Getcontentlength)   == PropfindProperties.Getcontentlength))
                Props.Add(PropfindProperties.Getcontentlength.ToString(), "0");
            if ((propfindProperties == PropfindProperties.NONE) || ((propfindProperties & PropfindProperties.Getcontenttype)     == PropfindProperties.Getcontenttype))
                Props.Add(PropfindProperties.Getcontenttype.ToString(), System.Net.Mime.MediaTypeNames.Application.Octet);
            if ((propfindProperties == PropfindProperties.NONE) || ((propfindProperties & PropfindProperties.Getetag)            == PropfindProperties.Getetag))
                Props.Add(PropfindProperties.Getetag.ToString(), Guid.NewGuid().ToString());
            if ((propfindProperties == PropfindProperties.NONE) || ((propfindProperties & PropfindProperties.Getlastmodified)    == PropfindProperties.Getlastmodified))
                Props.Add(PropfindProperties.Getlastmodified.ToString(), LastModificationDate);
            if ((propfindProperties == PropfindProperties.NONE) || ((propfindProperties & PropfindProperties.Lockdiscovery)      == PropfindProperties.Lockdiscovery))
                Props.Add(PropfindProperties.Lockdiscovery.ToString(), "");
            if ((propfindProperties == PropfindProperties.NONE) || ((propfindProperties & PropfindProperties.Resourcetype)       == PropfindProperties.Resourcetype))
                Props.Add(PropfindProperties.Resourcetype.ToString(), "collection");
            if ((propfindProperties == PropfindProperties.NONE) || ((propfindProperties & PropfindProperties.Supportedlock)      == PropfindProperties.Supportedlock))
                Props.Add(PropfindProperties.Supportedlock.ToString(), "");
            //}

            XmlElement ElemPropstat = CreatePropstatElement(header, xmlDocument, Props, hRef.Replace(header.GetFullHTTPHost(), ""));

            #endregion
            ElemResponse.AppendChild(ElemHref);
            ElemResponse.AppendChild(ElemPropstat);

            return ElemResponse;
        }
Esempio n. 2
0
        /// <summary>
        /// Create a WebDAV propstat Element
        /// </summary>
        /// <param name="xmlDocument">The XMLDocument where this propstat element will be added to</param>
        /// <param name="props">A list of properties where the key is the property Name and value is the content (innerText) or Empty</param>
        /// <param name="status">The HTTP status, usually "HTTP/1.1 200 OK"</param>
        /// <returns>An XmlElement containing all Properties etc.</returns>
        private XmlElement CreatePropstatElement(HTTPHeader header, XmlDocument xmlDocument, Dictionary<String, String> props, String status, String target)
        {
            XmlElement ElemPropstat = xmlDocument.CreateElement(S_DAV_PREFIX, "propstat", S_DAV_NAMESPACE_URI);

            #region propstat elements

            XmlElement ElemStatus = xmlDocument.CreateElement(S_DAV_PREFIX, "status", S_DAV_NAMESPACE_URI);
            ElemStatus.InnerText = status;

            XmlElement ElemProp = xmlDocument.CreateElement(S_DAV_PREFIX, "prop", S_DAV_NAMESPACE_URI);

            #region prop elements

            foreach (KeyValuePair<String, String> PropItem in props)
            {

                if (PropItem.Key == PropfindProperties.Lockdiscovery.ToString())
                    AddPropfindLockdiscoveryElements(ElemProp, target.Replace(header.GetFullHTTPHost(), ""), target);
                else if (PropItem.Key == PropfindProperties.Lockdiscovery.ToString())
                    AddPropfindSupportedLockElements(ElemProp);
                else if (PropItem.Key == PropfindProperties.Resourcetype.ToString())
                {
                    XmlElement ElemResourceType = xmlDocument.CreateElement(S_DAV_PREFIX, PropItem.Key.ToLower(), S_DAV_NAMESPACE_URI);
                    //If the element contains the 'collection' child element plus additional unrecognized elements, it should generally be treated as a collection. If the element contains no recognized child elements, it should be treated as a non-collection resource
                    XmlElement ElemCollection = xmlDocument.CreateElement(S_DAV_PREFIX, PropItem.Value, S_DAV_NAMESPACE_URI);
                    ElemResourceType.AppendChild(ElemCollection);

                    ElemProp.AppendChild(ElemResourceType);
                }

                #region SVN prop elements

                else if (PropItem.Key == PropfindProperties.VersionControlledConfiguration.ToString())
                {

                    XmlElement XmlVCC = xmlDocument.CreateElement(S_DAV_PREFIX, "version-controlled-configuration", S_DAV_NAMESPACE_URI);
                    XmlElement XmlVCCHref = xmlDocument.CreateElement(S_DAV_PREFIX, "href", S_DAV_NAMESPACE_URI);
                    XmlVCCHref.InnerText = DirectoryHelper.Combine(target.Replace(header.GetFullHTTPHost(), ""), "!svn/vcc/default");
                    XmlVCC.AppendChild(XmlVCCHref);

                    ElemProp.AppendChild(XmlVCC);

                }
                else if (PropItem.Key == PropfindProperties.CheckedIn.ToString())
                {

                    XmlElement XmlCI = xmlDocument.CreateElement(S_DAV_PREFIX, "checked-in", S_DAV_NAMESPACE_URI);
                    XmlElement XmlCIHref = xmlDocument.CreateElement(S_DAV_PREFIX, "href", S_DAV_NAMESPACE_URI);

                    if(PropItem.Value == "ver")
                        XmlCIHref.InnerText = DirectoryHelper.Combine(target.Replace(header.GetFullHTTPHost(), ""), "!svn/ver/37491");
                    else
                        XmlCIHref.InnerText = DirectoryHelper.Combine(target.Replace(header.GetFullHTTPHost(), ""), "!svn/bln/37491");

                    XmlCI.AppendChild(XmlCIHref);

                    ElemProp.AppendChild(XmlCI);

                }
                else if (PropItem.Key == PropfindProperties.BaselineRelativePath.ToString())
                {

                    XmlElement Eleme = xmlDocument.CreateElement(S_SVN_PREFIX, "baseline-relative-path", S_SVN_NAMESPACE_URI);
                    ElemProp.AppendChild(Eleme);

                }
                else if (PropItem.Key == PropfindProperties.RepositoryUuid.ToString())
                {

                    XmlElement Eleme = xmlDocument.CreateElement(S_SVN_PREFIX, "repository-uuid", S_SVN_NAMESPACE_URI);
                    Eleme.InnerText = PropItem.Value;
                    ElemProp.AppendChild(Eleme);

                }
                else if (PropItem.Key == PropfindProperties.BaselineCollection.ToString())
                {

                    XmlElement XmlCI = xmlDocument.CreateElement(S_DAV_PREFIX, "baseline-collection", S_DAV_NAMESPACE_URI);
                    XmlElement XmlCIHref = xmlDocument.CreateElement(S_DAV_PREFIX, "href", S_DAV_NAMESPACE_URI);
                    if (header.SVNParameters != null && header.SVNParameters.Contains("bln"))
                        XmlCIHref.InnerText = DirectoryHelper.Combine(target.Replace(header.GetFullHTTPHost(), ""), "!svn/bc/37491");
                    else
                        XmlCIHref.InnerText = DirectoryHelper.Combine(target.Replace(header.GetFullHTTPHost(), ""), "!svn/bln/37491");

                    XmlCI.AppendChild(XmlCIHref);

                    ElemProp.AppendChild(XmlCI);

                }
                else if (PropItem.Key == PropfindProperties.VersionName.ToString())
                {

                    XmlElement XmlCI = xmlDocument.CreateElement(S_DAV_PREFIX, "version-Name", S_DAV_NAMESPACE_URI);
                    if (header.SVNParameters != null && header.SVNParameters.Contains("bln"))
                    {
                        XmlCI.InnerText = "37491";
                    }
                    else
                    {
                        XmlElement XmlCIHref = xmlDocument.CreateElement(S_DAV_PREFIX, "href", S_DAV_NAMESPACE_URI);
                        XmlCIHref.InnerText = "37491";
                        XmlCI.AppendChild(XmlCIHref);
                    }
                    ElemProp.AppendChild(XmlCI);

                }
                #endregion

                else
                {

                    XmlElement XmlElement = xmlDocument.CreateElement(S_DAV_PREFIX, PropItem.Key.ToLower(), S_DAV_NAMESPACE_URI);
                    if (PropItem.Value != null && PropItem.Value != String.Empty)
                        XmlElement.InnerText = PropItem.Value;

                    ElemProp.AppendChild(XmlElement);
                }

            }

            #endregion

            #endregion

            ElemPropstat.AppendChild(ElemStatus);
            ElemPropstat.AppendChild(ElemProp);

            return ElemPropstat;
        }