예제 #1
0
        ExtractCollectionItems(XmlDocumentWithNamespaceManager responseXml, IGetVersionsLogger logger)
        {
            var responseNodes = responseXml.XmlDocument.SelectNodes("/D:multistatus/D:response", responseXml.XmlNamespaceManager);

            if (responseNodes == null)
            {
                return(new (WebResourceName, string)[0], new WebResourceName[0]);
        private IReadOnlyList <EntityVersion <WebResourceName, string> > ExtractVersions(XmlDocumentWithNamespaceManager responseXml)
        {
            var responseNodes = responseXml.XmlDocument.SelectNodes("/D:multistatus/D:response", responseXml.XmlNamespaceManager);

            if (responseNodes == null)
            {
                return(new EntityVersion <WebResourceName, string> [0]);
            }

            var entities = new List <EntityVersion <WebResourceName, string> >();

            // ReSharper disable once LoopCanBeConvertedToQuery
            // ReSharper disable once PossibleNullReferenceException
            foreach (XmlElement responseElement in responseNodes)
            {
                var urlNode  = responseElement.SelectSingleNode("D:href", responseXml.XmlNamespaceManager);
                var etagNode = responseElement.SelectSingleNode("D:propstat/D:prop/D:getetag", responseXml.XmlNamespaceManager);
                if (urlNode != null &&
                    etagNode != null &&
                    _serverUrl.AbsolutePath != UriHelper.DecodeUrlString(urlNode.InnerText))
                {
                    var uri  = new WebResourceName(urlNode.InnerText);
                    var etag = HttpUtility.GetQuotedEtag(etagNode.InnerText);
                    if (s_logger.IsDebugEnabled)
                    {
                        s_logger.DebugFormat($"Got version '{uri}': '{etag}'");
                    }
                    entities.Add(EntityVersion.Create(uri, etag));
                }
            }

            return(entities);
        }
    private IReadOnlyList<EntityVersion<WebResourceName, string>> ExtractVersions (XmlDocumentWithNamespaceManager responseXml)
    {
      s_logger.Debug ("Entered ExtractVersions.");

      var entities = new List<EntityVersion<WebResourceName, string>> ();

      XmlNodeList responseNodes = responseXml.XmlDocument.SelectNodes ("/D:multistatus/D:response", responseXml.XmlNamespaceManager);

      // ReSharper disable once LoopCanBeConvertedToQuery
      // ReSharper disable once PossibleNullReferenceException
      foreach (XmlElement responseElement in responseNodes)
      {
        var urlNode = responseElement.SelectSingleNode ("D:href", responseXml.XmlNamespaceManager);
        var etagNode = responseElement.SelectSingleNode ("D:propstat/D:prop/D:getetag", responseXml.XmlNamespaceManager);
        var contentTypeNode = responseElement.SelectSingleNode ("D:propstat/D:prop/D:getcontenttype", responseXml.XmlNamespaceManager);

        if (urlNode != null && etagNode != null)
        {
          string contentType = contentTypeNode?.InnerText ?? string.Empty;
          var eTag = HttpUtility.GetQuotedEtag (etagNode.InnerText);
          // the directory is also included in the list. It has a etag of '"None"' and is skipped
          // in Owncloud eTag is empty for directory
          // Yandex returns some eTag and the urlNode for the directory itself, so we need to filter that out aswell
          // TODO: add vlist support but for now filter out sogo vlists since we can't parse them atm

          if (!string.IsNullOrEmpty (eTag) &&
              String.Compare (eTag, @"""None""", StringComparison.OrdinalIgnoreCase) != 0 &&
              _serverUrl.AbsolutePath != UriHelper.DecodeUrlString (urlNode.InnerText) &&
              contentType != "text/x-vlist"
              )
          {
            if (s_logger.IsDebugEnabled)
              s_logger.DebugFormat ($"'{urlNode.InnerText}': '{eTag}'");
            entities.Add (EntityVersion.Create (new WebResourceName (urlNode.InnerText), eTag));
          }
        }
      }

      s_logger.Debug ("Exiting ExtractVersions.");
      return entities;
    }
예제 #4
0
        private IReadOnlyList <EntityVersion <WebResourceName, string> > ExtractVersions(XmlDocumentWithNamespaceManager responseXml)
        {
            s_logger.Debug("Entered ExtractVersions.");

            var entities = new List <EntityVersion <WebResourceName, string> > ();

            XmlNodeList responseNodes = responseXml.XmlDocument.SelectNodes("/D:multistatus/D:response", responseXml.XmlNamespaceManager);

            // ReSharper disable once LoopCanBeConvertedToQuery
            // ReSharper disable once PossibleNullReferenceException
            foreach (XmlElement responseElement in responseNodes)
            {
                var urlNode         = responseElement.SelectSingleNode("D:href", responseXml.XmlNamespaceManager);
                var etagNode        = responseElement.SelectSingleNode("D:propstat/D:prop/D:getetag", responseXml.XmlNamespaceManager);
                var contentTypeNode = responseElement.SelectSingleNode("D:propstat/D:prop/D:getcontenttype", responseXml.XmlNamespaceManager);

                if (urlNode != null && etagNode != null)
                {
                    string contentType = contentTypeNode?.InnerText ?? string.Empty;

                    var eTag = HttpUtility.GetQuotedEtag(etagNode.InnerText);
                    // the directory is also included in the list. It has a etag of '"None"' and is skipped
                    // in Owncloud eTag is empty for directory
                    // Yandex returns some eTag and the urlNode for the directory itself, so we need to filter that out aswell
                    // TODO: add vlist support but for now filter out sogo vlists since we can't parse them atm

                    if (!string.IsNullOrEmpty(eTag) &&
                        String.Compare(eTag, @"""None""", StringComparison.OrdinalIgnoreCase) != 0 &&
                        _serverUrl.AbsolutePath != UriHelper.DecodeUrlString(urlNode.InnerText) &&
                        _contentTypePredicate(contentType)
                        )
                    {
                        if (s_logger.IsDebugEnabled)
                        {
                            s_logger.DebugFormat($"'{urlNode.InnerText}': '{eTag}'");
                        }
                        entities.Add(EntityVersion.Create(new WebResourceName(urlNode.InnerText), eTag));
                    }
                }
            }

            s_logger.Debug("Exiting ExtractVersions.");
            return(entities);
        }