protected internal static void LoadElementExtensions(XmlReader reader, SyndicationCategory category, int maxExtensionSize)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            category.LoadElementExtensions(reader, maxExtensionSize);
        }
        protected internal static void WriteAttributeExtensions(XmlWriter writer, SyndicationCategory category, string version)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            category.WriteAttributeExtensions(writer, version);
        }
        protected internal static bool TryParseElement(XmlReader reader, SyndicationCategory category, string version)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            return(category.TryParseElement(reader, version));
        }
 public JsonSyndicationCategory(SyndicationCategory category)
 {
     if (category != null)
     {
         this.Label = category.Label;
         this.Name = category.Name;
         this.Scheme = category.Scheme;
     }
 }
 protected SyndicationCategory(SyndicationCategory source)
 {
     if (source == null)
         throw new ArgumentNullException ("source");
     name = source.name;
     scheme = source.scheme;
     label = source.label;
     extensions = source.extensions.Clone ();
 }
Exemplo n.º 6
0
        void ReadCategory(XmlReader reader, SyndicationCategory category)
        {
            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                    {
                        continue;
                    }
                    if (reader.NamespaceURI == String.Empty)
                    {
                        switch (reader.LocalName)
                        {
                        case "term":
                            category.Name = reader.Value;
                            continue;

                        case "scheme":
                            category.Scheme = reader.Value;
                            continue;

                        case "label":
                            category.Label = reader.Value;
                            continue;
                        }
                    }
                    if (!TryParseAttribute(reader.LocalName, reader.NamespaceURI, reader.Value, category, Version) && PreserveAttributeExtensions)
                    {
                        category.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                    }
                } while (reader.MoveToNextAttribute());
                reader.MoveToElement();
            }

            if (!reader.IsEmptyElement)
            {
                reader.Read();
                for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent())
                {
                    if (!TryParseElement(reader, category, Version))
                    {
                        if (PreserveElementExtensions)
                        {
                            // FIXME: what should be used for maxExtenswionSize
                            LoadElementExtensions(reader, category, int.MaxValue);
                        }
                        else
                        {
                            reader.Skip();
                        }
                    }
                }
            }
            reader.Read();              // </category> or <category ... />
        }
 public DataResultSyndicationItems GetByCategory(DataFilterSyndication filter)
 {
     SyndicationFeedFormatter feed = this.GetAll();
     SyndicationCategoryComparer categoryComparer = new SyndicationCategoryComparer();
     SyndicationCategory categoryToFind = new SyndicationCategory(filter.CategoryName);
     List<SyndicationItem> items = feed.Feed.Items
                                     .Where(p => p.Categories.Contains(categoryToFind, categoryComparer))
                                     .ToList();
     return this.GetDataResult(items, filter);
 }
Exemplo n.º 8
0
 protected SyndicationCategory(SyndicationCategory source)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     name       = source.name;
     scheme     = source.scheme;
     label      = source.label;
     extensions = source.extensions.Clone();
 }
Exemplo n.º 9
0
 protected SyndicationCategory(SyndicationCategory source)
 {
     if (source == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(source));
     }
     _label      = source._label;
     _name       = source._name;
     _scheme     = source._scheme;
     _extensions = source._extensions.Clone();
 }
Exemplo n.º 10
0
 protected SyndicationCategory(SyndicationCategory source)
 {
     if (source == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
     }
     this.label      = source.label;
     this.name       = source.name;
     this.scheme     = source.scheme;
     this.extensions = source.extensions.Clone();
 }
Exemplo n.º 11
0
 protected SyndicationCategory(SyndicationCategory source)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     _label      = source._label;
     _name       = source._name;
     _scheme     = source._scheme;
     _extensions = source._extensions.Clone();
 }
 protected SyndicationCategory(SyndicationCategory source)
 {
     if (source == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
     }
     this.label = source.label;
     this.name = source.name;
     this.scheme = source.scheme;
     this.extensions = source.extensions.Clone();
 }
Exemplo n.º 13
0
        protected SyndicationCategory(SyndicationCategory source)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            Label       = source.Label;
            Name        = source.Name;
            Scheme      = source.Scheme;
            _extensions = source._extensions.Clone();
        }
 protected void LoadCategories(Collection<SyndicationCategory> collection, EntitySet<Category> entitySet)
 {
   foreach (Category entity in entitySet)
   {
     SyndicationCategory s = new SyndicationCategory()
     {
       Label = entity.Label,
       Name = entity.Name,
       Scheme = entity.Scheme
     };
     LoadAttributes(s.AttributeExtensions, entity.Attributes);
     LoadElements(s.ElementExtensions, entity.Elements);
   }
 }
Exemplo n.º 15
0
 internal void WriteCategory(SyndicationCategory category, XmlWriter writer)
 {
     writer.WriteStartElement("category", AtomNamespace);
     if (category.Name != null)
     {
         writer.WriteAttributeString("term", category.Name);
     }
     if (category.Label != null)
     {
         writer.WriteAttributeString("label", category.Label);
     }
     if (category.Scheme != null)
     {
         writer.WriteAttributeString("scheme", category.Scheme);
     }
     WriteAttributeExtensions(writer, category, Version);
     WriteElementExtensions(writer, category, Version);
     writer.WriteEndElement();
 }
Exemplo n.º 16
0
		protected internal static bool TryParseAttribute (string name, string ns, string value, SyndicationCategory category, string version)
		{
			if (category == null)
				throw new ArgumentNullException ("category");
			return category.TryParseAttribute (name, ns, value, version);
		}
Exemplo n.º 17
0
		protected internal void WriteElementExtensions (XmlWriter writer, SyndicationCategory category, string version)
		{
			if (category == null)
				throw new ArgumentNullException ("category");
			category.WriteElementExtensions (writer, version);
		}
        private static async Task ReadInlineCategoriesAsync(XmlReaderWrapper reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int _maxExtensionSize)
        {
            inlineCategories.BaseUri = baseUri;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        inlineCategories.BaseUri = FeedUtils.CombineXmlBase(inlineCategories.BaseUri, await reader.GetValueAsync());
                    }
                    else if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        inlineCategories.Language = await reader.GetValueAsync();
                    }
                    else if (reader.LocalName == App10Constants.Fixed && reader.NamespaceURI == string.Empty)
                    {
                        inlineCategories.IsFixed = (reader.Value == "yes");
                    }
                    else if (reader.LocalName == Atom10Constants.SchemeTag && reader.NamespaceURI == string.Empty)
                    {
                        inlineCategories.Scheme = await reader.GetValueAsync();
                    }
                    else
                    {
                        string ns   = reader.NamespaceURI;
                        string name = reader.LocalName;
                        if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns))
                        {
                            continue;
                        }
                        string val = await reader.GetValueAsync();

                        if (!TryParseAttribute(name, ns, val, inlineCategories, version))
                        {
                            if (preserveAttributeExtensions)
                            {
                                inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), await reader.GetValueAsync());
                            }
                        }
                    }
                }
            }

            await SyndicationFeedFormatter.MoveToStartElementAsync(reader);

            bool isEmptyElement = reader.IsEmptyElement;
            await reader.ReadStartElementAsync();

            if (!isEmptyElement)
            {
                XmlBuffer           buffer    = null;
                XmlDictionaryWriter extWriter = null;
                try
                {
                    while (await reader.IsStartElementAsync())
                    {
                        if (await reader.IsStartElementAsync(Atom10Constants.CategoryTag, Atom10Constants.Atom10Namespace))
                        {
                            SyndicationCategory category = CreateCategory(inlineCategories);
                            await Atom10FeedFormatter.ReadCategoryAsync(reader, category, version, preserveAttributeExtensions, preserveElementExtensions, _maxExtensionSize);

                            if (category.Scheme == null)
                            {
                                category.Scheme = inlineCategories.Scheme;
                            }

                            inlineCategories.Categories.Add(category);
                        }
                        else if (!TryParseElement(reader, inlineCategories, version))
                        {
                            if (preserveElementExtensions)
                            {
                                var tuple = await SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNodeAsync(buffer, extWriter, reader, _maxExtensionSize);

                                buffer    = tuple.Item1;
                                extWriter = tuple.Item2;
                            }
                            else
                            {
                                await reader.SkipAsync();
                            }
                        }
                    }
                    LoadElementExtensions(buffer, extWriter, inlineCategories);
                }
                finally
                {
                    if (extWriter != null)
                    {
                        extWriter.Close();
                    }
                }

                await reader.ReadEndElementAsync();
            }
        }
Exemplo n.º 19
0
        // read

        void ReadXml(XmlReader reader, bool fromSerializable)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            SetItem(CreateItemInstance());

            reader.MoveToContent();

            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                    {
                        continue;
                    }
                    if (!TryParseAttribute(reader.LocalName, reader.NamespaceURI, reader.Value, Item, Version) && PreserveAttributeExtensions)
                    {
                        Item.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                    }
                } while (reader.MoveToNextAttribute());
            }

            reader.ReadStartElement();

            for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent())
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    throw new XmlException("Only element node is expected under 'entry' element");
                }
                if (reader.NamespaceURI == AtomNamespace)
                {
                    switch (reader.LocalName)
                    {
                    case "author":
                        SyndicationPerson p = Item.CreatePerson();
                        ReadPerson(reader, p);
                        Item.Authors.Add(p);
                        continue;

                    case "category":
                        SyndicationCategory c = Item.CreateCategory();
                        ReadCategory(reader, c);
                        Item.Categories.Add(c);
                        continue;

                    case "contributor":
                        p = Item.CreatePerson();
                        ReadPerson(reader, p);
                        Item.Contributors.Add(p);
                        continue;

                    case "id":
                        Item.Id = reader.ReadElementContentAsString();
                        continue;

                    case "link":
                        SyndicationLink l = Item.CreateLink();
                        ReadLink(reader, l);
                        Item.Links.Add(l);
                        continue;

                    case "published":
                        Item.PublishDate = XmlConvert.ToDateTimeOffset(reader.ReadElementContentAsString());
                        continue;

                    case "rights":
                        Item.Copyright = ReadTextSyndicationContent(reader);
                        continue;

                    case "source":
                        Item.SourceFeed = ReadSourceFeed(reader);
                        continue;

                    case "summary":
                        Item.Summary = ReadTextSyndicationContent(reader);
                        continue;

                    case "title":
                        Item.Title = ReadTextSyndicationContent(reader);
                        continue;

                    case "updated":
                        Item.LastUpdatedTime = XmlConvert.ToDateTimeOffset(reader.ReadElementContentAsString());
                        continue;

                    // Atom 1.0 does not specify "content" element, but it is required to distinguish Content property from extension elements.
                    case "content":
                        if (reader.GetAttribute("src") != null)
                        {
                            Item.Content = new UrlSyndicationContent(CreateUri(reader.GetAttribute("src")), reader.GetAttribute("type"));
                            reader.Skip();
                            continue;
                        }
                        switch (reader.GetAttribute("type"))
                        {
                        case "text":
                        case "html":
                        case "xhtml":
                            Item.Content = ReadTextSyndicationContent(reader);
                            continue;

                        default:
                            SyndicationContent content;
                            if (!TryParseContent(reader, Item, reader.GetAttribute("type"), Version, out content))
                            {
                                Item.Content = new XmlSyndicationContent(reader);
                            }
                            continue;
                        }
                    }
                }
                if (!TryParseElement(reader, Item, Version))
                {
                    if (PreserveElementExtensions)
                    {
                        // FIXME: what to specify for maxExtensionSize
                        LoadElementExtensions(reader, Item, int.MaxValue);
                    }
                    else
                    {
                        reader.Skip();
                    }
                }
            }

            reader.ReadEndElement();              // </item>
        }
Exemplo n.º 20
0
 internal static protected Task WriteAttributeExtensionsAsync(XmlWriter writer, SyndicationCategory category, string version)
 {
     if (category == null)
     {
         throw new ArgumentNullException(nameof(category));
     }
     return(category.WriteAttributeExtensionsAsync(writer, version));
 }
 private void ReadCategory(XmlReader reader, SyndicationCategory category)
 {
     bool isEmptyElement = reader.IsEmptyElement;
     if (reader.HasAttributes)
     {
         while (reader.MoveToNextAttribute())
         {
             string namespaceURI = reader.NamespaceURI;
             string localName = reader.LocalName;
             if (!FeedUtils.IsXmlns(localName, namespaceURI))
             {
                 string str3 = reader.Value;
                 if ((localName == "domain") && (namespaceURI == ""))
                 {
                     category.Scheme = str3;
                 }
                 else if (!SyndicationFeedFormatter.TryParseAttribute(localName, namespaceURI, str3, category, this.Version))
                 {
                     if (this.preserveAttributeExtensions)
                     {
                         category.AttributeExtensions.Add(new XmlQualifiedName(localName, namespaceURI), str3);
                         continue;
                     }
                     SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                 }
             }
         }
     }
     reader.ReadStartElement("category", "");
     if (!isEmptyElement)
     {
         category.Name = reader.ReadString();
         reader.ReadEndElement();
     }
 }
 protected internal static void WriteElementExtensions(System.Xml.XmlWriter writer, SyndicationCategory category, string version)
 {
 }
        private static void ReadInlineCategories(XmlReader reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize)
        {
            inlineCategories.BaseUri = baseUri;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if ((reader.LocalName == "base") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace"))
                    {
                        inlineCategories.BaseUri = FeedUtils.CombineXmlBase(inlineCategories.BaseUri, reader.Value);
                    }
                    else
                    {
                        if ((reader.LocalName == "lang") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace"))
                        {
                            inlineCategories.Language = reader.Value;
                            continue;
                        }
                        if ((reader.LocalName == "fixed") && (reader.NamespaceURI == string.Empty))
                        {
                            inlineCategories.IsFixed = reader.Value == "yes";
                            continue;
                        }
                        if ((reader.LocalName == "scheme") && (reader.NamespaceURI == string.Empty))
                        {
                            inlineCategories.Scheme = reader.Value;
                            continue;
                        }
                        string namespaceURI = reader.NamespaceURI;
                        string localName    = reader.LocalName;
                        if (!FeedUtils.IsXmlns(localName, namespaceURI) && !FeedUtils.IsXmlSchemaType(localName, namespaceURI))
                        {
                            string str3 = reader.Value;
                            if (!ServiceDocumentFormatter.TryParseAttribute(localName, namespaceURI, str3, inlineCategories, version))
                            {
                                if (preserveAttributeExtensions)
                                {
                                    inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                                    continue;
                                }
                                SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                            }
                        }
                    }
                }
            }
            SyndicationFeedFormatter.MoveToStartElement(reader);
            bool isEmptyElement = reader.IsEmptyElement;

            reader.ReadStartElement();
            if (!isEmptyElement)
            {
                XmlBuffer           buffer    = null;
                XmlDictionaryWriter extWriter = null;
                try
                {
                    while (reader.IsStartElement())
                    {
                        if (reader.IsStartElement("category", "http://www.w3.org/2005/Atom"))
                        {
                            SyndicationCategory category = ServiceDocumentFormatter.CreateCategory(inlineCategories);
                            Atom10FeedFormatter.ReadCategory(reader, category, version, preserveAttributeExtensions, preserveElementExtensions, maxExtensionSize);
                            if (category.Scheme == null)
                            {
                                category.Scheme = inlineCategories.Scheme;
                            }
                            inlineCategories.Categories.Add(category);
                        }
                        else if (!ServiceDocumentFormatter.TryParseElement(reader, inlineCategories, version))
                        {
                            if (preserveElementExtensions)
                            {
                                SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
                                continue;
                            }
                            SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                            reader.Skip();
                        }
                    }
                    ServiceDocumentFormatter.LoadElementExtensions(buffer, extWriter, inlineCategories);
                }
                finally
                {
                    if (extWriter != null)
                    {
                        extWriter.Close();
                    }
                }
                reader.ReadEndElement();
            }
        }
Exemplo n.º 24
0
    protected void Page_Load(object sender, EventArgs e)
    {
        WebProxy proxy = (WebProxy)WebProxy.GetDefaultProxy();
        if (proxy.Address != null)
        {
          proxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
          WebRequest.DefaultWebProxy = new System.Net.WebProxy(proxy.Address, proxy.BypassProxyOnLocal, proxy.BypassList, proxy.Credentials);
        }

        DataTable table = dsItems.Tables.Add("entries");
        DataColumn pkOrderID =
        table.Columns.Add("URL", typeof(string));
        table.Columns.Add("Title", typeof(string));
        table.Columns.Add("Description", typeof(string));

        try
        {
          WebRequest request = WebRequest.Create("http://blog.lamarelle.org.uk/feeds/posts/default");
          request.Timeout = 500;

          using (WebResponse response = request.GetResponse())
          using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
          {
        List<SyndicationItem> newItems = new List<SyndicationItem>();
        SyndicationFeed feed = SyndicationFeed.Load(reader);
        SyndicationCategory lookingFor = new SyndicationCategory("news");

        if (feed != null)
        {
          foreach (SyndicationItem item in feed.Items)
          {
            foreach (SyndicationCategory sc in item.Categories)
            {
              if (sc.Name == lookingFor.Name)
              {
                newItems.Add(item);
              }
            }
          }
        }

        if (newItems.Count > 0)
        {
          foreach (SyndicationItem item in newItems.Take(3))
          {
            DataRow row = table.NewRow();

            row["URL"] = item.Links.Where(l => l.RelationshipType == "alternate").FirstOrDefault().Uri.ToString();;
            row["Title"] = item.Title.Text;
            TextSyndicationContent tsc = (TextSyndicationContent)item.Content;
            row["Description"] = tsc.Text;
            table.Rows.Add(row);
          }
        }

        FormView1.DataSource = dsItems;
        FormView1.DataBind();
          }
        }
        catch (System.Net.WebException we)
        {
          DataRow row = table.NewRow();

          row["URL"] = "http://blog.lamarelle.org.uk/";
          row["Title"] = "See further information on Blogger.";
          row["Description"] = "";
          table.Rows.Add(row);
          FormView1.DataSource = dsItems;
          FormView1.DataBind();
        }
    }
Exemplo n.º 25
0
        // read

        void ReadXml(XmlReader reader, bool fromSerializable)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            SetFeed(CreateFeedInstance());

            reader.MoveToContent();

            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                    {
                        continue;
                    }
                    if (reader.LocalName == "lang" && reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace")
                    {
                        Feed.Language = reader.Value;
                        continue;
                    }
                    if (!TryParseAttribute(reader.LocalName, reader.NamespaceURI, reader.Value, Feed, Version) && PreserveAttributeExtensions)
                    {
                        Feed.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                    }
                } while (reader.MoveToNextAttribute());
            }

            reader.ReadStartElement();

            Collection <SyndicationItem> items = null;

            for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent())
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    throw new XmlException("Only element node is expected under 'feed' element");
                }
                if (reader.NamespaceURI == AtomNamespace)
                {
                    switch (reader.LocalName)
                    {
                    case "author":
                        SyndicationPerson p = Feed.CreatePerson();
                        ReadPerson(reader, p);
                        Feed.Authors.Add(p);
                        continue;

                    case "category":
                        SyndicationCategory c = Feed.CreateCategory();
                        ReadCategory(reader, c);
                        Feed.Categories.Add(c);
                        continue;

                    case "contributor":
                        p = Feed.CreatePerson();
                        ReadPerson(reader, p);
                        Feed.Contributors.Add(p);
                        continue;

                    case "generator":
                        Feed.Generator = reader.ReadElementContentAsString();
                        continue;

                    // "icon" is an extension
                    case "id":
                        Feed.Generator = reader.ReadElementContentAsString();
                        continue;

                    case "link":
                        SyndicationLink l = Feed.CreateLink();
                        ReadLink(reader, l);
                        Feed.Links.Add(l);
                        continue;

                    case "logo":
                        Feed.ImageUrl = CreateUri(reader.ReadElementContentAsString());
                        continue;

                    case "rights":
                        Feed.Copyright = ReadTextSyndicationContent(reader);
                        continue;

                    case "subtitle":
                        Feed.Description = ReadTextSyndicationContent(reader);
                        continue;

                    case "title":
                        Feed.Title = ReadTextSyndicationContent(reader);
                        continue;

                    case "updated":
                        // FIXME: somehow DateTimeOffset causes the runtime crash.
                        reader.ReadElementContentAsString();
                        // Feed.LastUpdatedTime = XmlConvert.ToDateTimeOffset (reader.ReadElementContentAsString ());
                        continue;

                    case "entry":
                        if (items == null)
                        {
                            items      = new Collection <SyndicationItem> ();
                            Feed.Items = items;
                        }
                        items.Add(ReadItem(reader, Feed));
                        continue;
                    }
                }
                if (!TryParseElement(reader, Feed, Version))
                {
                    if (PreserveElementExtensions)
                    {
                        // FIXME: what to specify for maxExtensionSize
                        LoadElementExtensions(reader, Feed, int.MaxValue);
                    }
                    else
                    {
                        reader.Skip();
                    }
                }
            }

            reader.ReadEndElement();
        }
Exemplo n.º 26
0
 void ReadCategory(XmlReader reader, SyndicationCategory category)
 {
     bool isEmpty = reader.IsEmptyElement;
     if (reader.HasAttributes)
     {
         while (reader.MoveToNextAttribute())
         {
             string ns = reader.NamespaceURI;
             string name = reader.LocalName;
             if (FeedUtils.IsXmlns(name, ns))
             {
                 continue;
             }
             string val = reader.Value;
             if (name == Rss20Constants.DomainTag && ns == Rss20Constants.Rss20Namespace)
             {
                 category.Scheme = val;
             }
             else if (!TryParseAttribute(name, ns, val, category, this.Version))
             {
                 if (this.preserveAttributeExtensions)
                 {
                     category.AttributeExtensions.Add(new XmlQualifiedName(name, ns), val);
                 }
                 else
                 {
                     TraceSyndicationElementIgnoredOnRead(reader);
                 }
             }
         }
     }
     reader.ReadStartElement(Rss20Constants.CategoryTag, Rss20Constants.Rss20Namespace);
     if (!isEmpty)
     {
         category.Name = reader.ReadString();
         reader.ReadEndElement();
     }
 }
Exemplo n.º 27
0
 void WriteCategory(XmlWriter writer, SyndicationCategory category)
 {
     if (category == null)
     {
         return;
     }
     writer.WriteStartElement(Rss20Constants.CategoryTag, Rss20Constants.Rss20Namespace);
     WriteAttributeExtensions(writer, category, this.Version);
     if (!string.IsNullOrEmpty(category.Scheme) && !category.AttributeExtensions.ContainsKey(Rss20Domain))
     {
         writer.WriteAttributeString(Rss20Constants.DomainTag, Rss20Constants.Rss20Namespace, category.Scheme);
     }
     writer.WriteString(category.Name);
     writer.WriteEndElement();
 }
		void ReadInlineCategoriesContent (InlineCategoriesDocument doc, XmlReader reader)
		{
			var cat = new SyndicationCategory ();
			atom10_formatter.ReadCategory (reader, cat);
			doc.Categories.Add (cat);
		}
 protected static bool TryParseAttribute(string name, string ns, string value, SyndicationCategory category, string version)
 {
     return SyndicationFeedFormatter.TryParseAttribute(name, ns, value, category, version);
 }
 protected static void WriteAttributeExtensions(XmlWriter writer, SyndicationCategory category, string version)
 {
     SyndicationFeedFormatter.WriteAttributeExtensions(writer, category, version);
 }
 internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationCategory category)
 {
     SyndicationFeedFormatter.LoadElementExtensions(buffer, writer, category);
 }
        // read

        void ReadXml(XmlReader reader, bool fromSerializable)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            SetFeed(CreateFeedInstance());

            reader.MoveToContent();

            string ver = reader.GetAttribute("version");

            if (ver != "2.0")
            {
                throw new NotSupportedException(String.Format("RSS Version '{0}' is not supported", ver));
            }

            if (PreserveAttributeExtensions && reader.MoveToFirstAttribute())
            {
                do
                {
                    if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                    {
                        continue;
                    }
                    if (reader.NamespaceURI == String.Empty && reader.LocalName == "version")
                    {
                        continue;
                    }
                    if (!TryParseAttribute(reader.LocalName, reader.NamespaceURI, reader.Value, Feed, Version))
                    {
                        Feed.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                    }
                }while (reader.MoveToNextAttribute());
            }

            reader.ReadStartElement();                        // <rss> => <channel>
            reader.MoveToContent();
            reader.ReadStartElement("channel", String.Empty); // <channel> => *

            Collection <SyndicationItem> items = null;

            for (reader.MoveToContent(); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent())
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    throw new XmlException("Only element node is expected under 'channel' element");
                }
                if (reader.NamespaceURI == String.Empty)
                {
                    switch (reader.LocalName)
                    {
                    case "title":
                        Feed.Title = ReadTextSyndicationContent(reader);
                        continue;

                    case "link":
                        SyndicationLink l = Feed.CreateLink();
                        ReadLink(reader, l);
                        Feed.Links.Add(l);
                        continue;

                    case "description":
                        Feed.Description = ReadTextSyndicationContent(reader);
                        continue;

                    case "language":
                        Feed.Language = reader.ReadElementContentAsString();
                        continue;

                    case "copyright":
                        Feed.Copyright = ReadTextSyndicationContent(reader);
                        continue;

                    case "managingEditor":
                        SyndicationPerson p = Feed.CreatePerson();
                        ReadPerson(reader, p);
                        Feed.Authors.Add(p);
                        continue;

                    case "pubDate":
                        // FIXME: somehow DateTimeOffset causes the runtime crash.
                        reader.ReadElementContentAsString();
                        // Feed.PublishDate = FromRFC822DateString (reader.ReadElementContentAsString ());
                        continue;

                    case "lastBuildDate":
                        // FIXME: somehow DateTimeOffset causes the runtime crash.
                        reader.ReadElementContentAsString();
                        // Feed.LastUpdatedTime = FromRFC822DateString (reader.ReadElementContentAsString ());
                        continue;

                    case "category":
                        SyndicationCategory c = Feed.CreateCategory();
                        ReadCategory(reader, c);
                        Feed.Categories.Add(c);
                        continue;

                    case "generator":
                        Feed.Generator = reader.ReadElementContentAsString();
                        continue;

                    //  "webMaster" "docs" "cloud" "ttl" "image" "rating" "textInput" "skipHours" "skipDays" are not handled.
                    case "item":
                        if (items == null)
                        {
                            items      = new Collection <SyndicationItem> ();
                            Feed.Items = items;
                        }
                        items.Add(ReadItem(reader, Feed));
                        continue;
                    }
                }
                if (!TryParseElement(reader, Feed, Version))
                {
                    if (PreserveElementExtensions)
                    {
                        // FIXME: what to specify for maxExtensionSize
                        LoadElementExtensions(reader, Feed, int.MaxValue);
                    }
                    else
                    {
                        reader.Skip();
                    }
                }
            }

            reader.ReadEndElement(); // </channel>
            reader.ReadEndElement(); // </rss>
        }
 protected internal static void LoadElementExtensions(System.Xml.XmlReader reader, SyndicationCategory category, int maxExtensionSize)
 {
 }
 protected static void LoadElementExtensions(XmlReader reader, SyndicationCategory category, int maxExtensionSize)
 {
     SyndicationFeedFormatter.LoadElementExtensions(reader, category, maxExtensionSize);
 }
 private void WriteCategory(XmlWriter writer, SyndicationCategory category)
 {
     if (category != null)
     {
         writer.WriteStartElement("category", "");
         SyndicationFeedFormatter.WriteAttributeExtensions(writer, category, this.Version);
         if (!string.IsNullOrEmpty(category.Scheme) && !category.AttributeExtensions.ContainsKey(Rss20Domain))
         {
             writer.WriteAttributeString("domain", "", category.Scheme);
         }
         writer.WriteString(category.Name);
         writer.WriteEndElement();
     }
 }
Exemplo n.º 36
0
    /// <summary>
    /// Builds a dictionary that contains Syndication Category.
    /// </summary>
    /// <param name="c">A <see cref="System.ServiceModel.Syndication.SyndicationCategory"/> representing a category from a syndicated feed.</param>
    /// <returns>A <see cref="System.Collections.Generic.Dictionary{string,object}"/> containing the content of the category.</returns>
    private static Dictionary<string, object> BuildSyndicationCategory( SyndicationCategory c )
    {
        Dictionary<string, object> category = new Dictionary<string, object>();

        if ( c != null )
        {
            category.Add( "AttributeExtensions", c.AttributeExtensions.ToDictionary( a => a.Key.ToString(), a => a.Value ) );
            category.Add( "ElementExtensions", c.ElementExtensions );
            category.Add( "Label", c.Label );
            category.Add( "Name", c.Name );
            category.Add( "Scheme", c.Scheme );
        }

        return category;
    }
Exemplo n.º 37
0
        internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationCategory category)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            CloseBuffer(buffer, writer);
            category.LoadElementExtensions(buffer);
        }
        private static void ReadInlineCategories(XmlReader reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, int maxExtensionSize)
        {
            inlineCategories.BaseUri = baseUri;
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        inlineCategories.BaseUri = FeedUtils.CombineXmlBase(inlineCategories.BaseUri, reader.Value);
                    }
                    else if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs)
                    {
                        inlineCategories.Language = reader.Value;
                    }
                    else if (reader.LocalName == App10Constants.Fixed && reader.NamespaceURI == string.Empty)
                    {
                        inlineCategories.IsFixed = (reader.Value == "yes");
                    }
                    else if (reader.LocalName == Atom10Constants.SchemeTag && reader.NamespaceURI == string.Empty)
                    {
                        inlineCategories.Scheme = reader.Value;
                    }
                    else
                    {
                        string ns   = reader.NamespaceURI;
                        string name = reader.LocalName;
                        if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns))
                        {
                            continue;
                        }

                        string val = reader.Value;
                        if (!TryParseAttribute(name, ns, val, inlineCategories, version))
                        {
                            inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                        }
                    }
                }
            }
            SyndicationFeedFormatter.MoveToStartElement(reader);
            bool isEmptyElement = reader.IsEmptyElement;

            reader.ReadStartElement();
            if (!isEmptyElement)
            {
                XmlBuffer           buffer    = null;
                XmlDictionaryWriter extWriter = null;
                try
                {
                    while (reader.IsStartElement())
                    {
                        if (reader.IsStartElement(Atom10Constants.CategoryTag, Atom10Constants.Atom10Namespace))
                        {
                            SyndicationCategory category = CreateCategory(inlineCategories);
                            Atom10FeedFormatter.ReadCategory(reader, category, version, preserveAttributeExtensions: true, preserveElementExtensions: true, maxExtensionSize);
                            if (category.Scheme == null)
                            {
                                category.Scheme = inlineCategories.Scheme;
                            }
                            inlineCategories.Categories.Add(category);
                        }
                        else if (!TryParseElement(reader, inlineCategories, version))
                        {
                            SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize);
                        }
                    }
                    LoadElementExtensions(buffer, extWriter, inlineCategories);
                }
                finally
                {
                    extWriter?.Close();
                }
                reader.ReadEndElement();
            }
        }
 void ReadCategory(XmlReader reader, SyndicationCategory category)
 {
     ReadCategory(reader, category, this.Version, this.PreserveAttributeExtensions, this.PreserveElementExtensions, this.maxExtensionSize);
 }
        internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationCategory category)
        {
            Debug.Assert(category != null);

            CloseBuffer(buffer, writer);
            category.LoadElementExtensions(buffer);
        }
Exemplo n.º 41
0
		protected internal static bool TryParseElement (XmlReader reader, SyndicationCategory category, string version)
		{
			if (category == null)
				throw new ArgumentNullException ("category");
			return category.TryParseElement (reader, version);
		}
Exemplo n.º 42
0
 protected Task WriteElementExtensionsAsync(XmlWriter writer, SyndicationCategory category, string version)
 {
     return(SyndicationFeedFormatter.WriteElementExtensionsAsync(writer, category, version));
 }
Exemplo n.º 43
0
		protected internal static void LoadElementExtensions (XmlReader reader, SyndicationCategory category, int maxExtensionSize)
		{
			category.ElementExtensions.Add (reader);
		}
 internal static protected bool TryParseAttribute(string name, string ns, string value, SyndicationCategory category, string version)
 {
     if (category == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("category");
     }
     if (FeedUtils.IsXmlns(name, ns))
     {
         return(true);
     }
     return(category.TryParseAttribute(name, ns, value, version));
 }
Exemplo n.º 45
0
 protected static bool TryParseElement(XmlReader reader, SyndicationCategory category, string version)
 {
     return(SyndicationFeedFormatter.TryParseElement(reader, category, version));
 }
 protected static bool TryParseElement(XmlReader reader, SyndicationCategory category, string version)
 {
     return SyndicationFeedFormatter.TryParseElement(reader, category, version);
 }
        protected internal static bool TryParseAttribute(string name, string ns, string value, SyndicationCategory category, string version)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            if (FeedUtils.IsXmlns(name, ns))
            {
                return(true);
            }
            return(category.TryParseAttribute(name, ns, value, version));
        }
Exemplo n.º 48
0
 protected void WriteElementExtensions(XmlWriter writer, SyndicationCategory category, string version)
 {
     SyndicationFeedFormatter.WriteElementExtensions(writer, category, version);
 }
Exemplo n.º 49
0
 protected static async Task WriteAttributeExtensionsAsync(XmlWriter writer, SyndicationCategory category, string version)
 {
     await SyndicationFeedFormatter.WriteAttributeExtensionsAsync(writer, category, version);
 }
Exemplo n.º 50
0
 protected static bool TryParseAttribute(string name, string ns, string value, SyndicationCategory category, string version)
 {
     return(SyndicationFeedFormatter.TryParseAttribute(name, ns, value, category, version));
 }
Exemplo n.º 51
0
 internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationCategory category)
 {
     SyndicationFeedFormatter.LoadElementExtensions(buffer, writer, category);
 }
 protected internal static bool TryParseElement(System.Xml.XmlReader reader, SyndicationCategory category, string version)
 {
   return default(bool);
 }
 internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationCategory category)
 {
     if (category == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("category");
     }
     CloseBuffer(buffer, writer);
     category.LoadElementExtensions(buffer);
 }
 protected void WriteElementExtensions(XmlWriter writer, SyndicationCategory category, string version)
 {
     SyndicationFeedFormatter.WriteElementExtensions(writer, category, version);
 }
Exemplo n.º 55
0
 protected static void WriteAttributeExtensions(XmlWriter writer, SyndicationCategory category, string version)
 {
     SyndicationFeedFormatter.WriteAttributeExtensions(writer, category, version);
 }
        internal void ReadCategory(XmlReader reader, SyndicationCategory category)
        {
            if (reader.MoveToFirstAttribute ()) {
                do {
                    if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                        continue;
                    if (reader.NamespaceURI == String.Empty) {
                        switch (reader.LocalName) {
                        case "term":
                            category.Name = reader.Value;
                            continue;
                        case "scheme":
                            category.Scheme = reader.Value;
                            continue;
                        case "label":
                            category.Label = reader.Value;
                            continue;
                        }
                    }
                    if (!TryParseAttribute (reader.LocalName, reader.NamespaceURI, reader.Value, category, Version) && PreserveAttributeExtensions)
                        category.AttributeExtensions.Add (new XmlQualifiedName (reader.LocalName, reader.NamespaceURI), reader.Value);
                } while (reader.MoveToNextAttribute ());
                reader.MoveToElement ();
            }

            if (!reader.IsEmptyElement) {
                reader.Read ();
                for (reader.MoveToContent (); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ()) {
                    if (!TryParseElement (reader, category, Version)) {
                        if (PreserveElementExtensions)
                            // FIXME: what should be used for maxExtenswionSize
                            LoadElementExtensions (reader, category, int.MaxValue);
                        else
                            reader.Skip ();
                    }
                }
            }
            reader.Read (); // </category> or <category ... />
        }
Exemplo n.º 57
0
 protected static void LoadElementExtensions(XmlReader reader, SyndicationCategory category, int maxExtensionSize)
 {
     SyndicationFeedFormatter.LoadElementExtensions(reader, category, maxExtensionSize);
 }
 internal void WriteCategory(SyndicationCategory category, XmlWriter writer)
 {
     writer.WriteStartElement ("category", AtomNamespace);
     if (category.Name != null)
         writer.WriteAttributeString ("term", category.Name);
     if (category.Label != null)
         writer.WriteAttributeString ("label", category.Label);
     if (category.Scheme != null)
         writer.WriteAttributeString ("scheme", category.Scheme);
     WriteAttributeExtensions (writer, category, Version);
     WriteElementExtensions (writer, category, Version);
     writer.WriteEndElement ();
 }
Exemplo n.º 59
0
 private bool FeedCategoryInNancyCategories(SyndicationCategory category)
 {
     return nancyCategories.Any(x => x.Equals(category.Name, StringComparison.OrdinalIgnoreCase));
 }
 protected internal static bool TryParseAttribute(string name, string ns, string value, SyndicationCategory category, string version)
 {
   return default(bool);
 }