Exemplo n.º 1
0
 public SyndicationFeed GenerateFeeds(int noOfFeeds)
 {
     var feed = new SyndicationFeed
     {
         Title = new TextSyndicationContent("A simple rss feeder."),
         Language = "en-us",
         LastUpdatedTime = DateTime.Now,
         Copyright = new TextSyndicationContent("RRiwaj"),
         Description = new TextSyndicationContent("This is a simple rss feeder created using WCF Syndication class."),
         ImageUrl = new Uri("/Contents/Images/rss.png", UriKind.Relative),
     };
     var itemsRepo = _feedRepository.GetFeedItems(noOfFeeds); // Get Item Feeds from feed repository.
     var feedItems = new List<SyndicationItem>(); // Create new Syndication Item List which will be added to Syndication Feed
     foreach (var proxyItem in itemsRepo)
     {
         var item = new SyndicationItem
         {
             Title = SyndicationContent.CreatePlaintextContent(proxyItem.Title),
             PublishDate = proxyItem.FeedDate,
             Summary = SyndicationContent.CreateHtmlContent(proxyItem.Summary)
         };
         var authInfo = new SyndicationPerson
         {
             Name = proxyItem.AuthorName,
             Email = proxyItem.AuthorEmail
         };
         item.Authors.Add(authInfo);
         item.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(proxyItem.FeedUrl)));
         feedItems.Add(item);
     }
     feed.Items = feedItems;
     return feed;
 }
Exemplo n.º 2
0
        public override void Load()
        {
            Bind<int>().ToConstant(10).Named("PageSize");
            Bind<string>().ToConstant("06-84-B9-E5-98-A9-64-CE-7B-A1-3F-FD-58-0A-12-6E").Named("PasswordHash");
            Bind<string>().ToConstant("宅居").Named("SiteName");
            Bind<string>().ToConstant("*****@*****.**").Named("Email");

            string baseUrl = "http://otakustay.com";
            Bind<string>().ToConstant(baseUrl).Named("BaseUrl");

            SyndicationPerson me =
                new SyndicationPerson("*****@*****.**", "otakustay", "http://otakustay.com");
            Bind<SyndicationPerson>().ToConstant(me);

            Bind<Markdown>().ToMethod(CreateMarkdownTransformer).InTransientScope().Named("Full");
            Bind<Markdown>().ToMethod(CreateSafeMarkdownTransformer).InTransientScope().Named("Safe");

            string connectionString = ConfigurationManager.ConnectionStrings["MySql"].ConnectionString;
            Bind<string>().ToConstant(connectionString).Named("ConnectionString");

            Bind<ISession>().ToMethod(OpenSession).InTransientScope();

            Bind<IndexWriter>().ToMethod(CreateIndexWriter).InTransientScope();
            Bind<IndexSearcher>().ToMethod(CreateIndexSearcher).InTransientScope();

            Bind<CommentProcessor>().ToSelf()
                .InTransientScope()
                .WithConstructorArgument("apiKey", "903d4ade58ed");
        }
Exemplo n.º 3
0
        public SyndicationFeed CreateSyndicationFeed()
        {
            var posts = Post.GetPublishedPosts(_respository);
            var blog = _respository.List<BlogSettings>().Single();

            var myFeed = new SyndicationFeed
            {
                Title = new TextSyndicationContent(blog.Title),
                Description = new TextSyndicationContent(blog.Description),
                Language = CultureInfo.CurrentCulture.Name,
            };

            var feedItems = new List<SyndicationItem>();
            foreach(var p in posts)
            {
                var item = new SyndicationItem(p.Title, p.Body, new Uri(_urlContext.GetPostUrl(p)),p.Id,p.Created);

                var authInfo = new SyndicationPerson { Name = "Bjarte Djuvik Næss" };
                item.Authors.Add(authInfo);

                feedItems.Add(item);
            }
            myFeed.Items = feedItems;

            return myFeed;
        }
Exemplo n.º 4
0
        public static SyndicationFeed GetPostFeed()
        {
            SyndicationFeed postfeed = Feeds.GetFeed();
            postfeed.Title = new TextSyndicationContent("Key Mapper Developer Blog");
            postfeed.Description = new TextSyndicationContent("Post feed for the Key Mapper Developer Blog");

            Collection<Post> posts = Post.GetAllPosts(CommentType.Approved);
            List<SyndicationItem> items = new List<SyndicationItem>();

            foreach (Post p in posts)
            {
                SyndicationItem item = new SyndicationItem();
                item.Id = p.Id.ToString();
                item.Title = new TextSyndicationContent(p.Title);
                item.Content = new TextSyndicationContent(p.Body);

                SyndicationLink itemlink = new SyndicationLink();
                itemlink.Title = "Key Mapper Blog";
                itemlink.Uri = new Uri("http://justkeepswimming.net/keymapper/default.aspx?p="
                    + p.Id.ToString() + ".aspx");
                item.Links.Add(itemlink);

                SyndicationPerson person = new SyndicationPerson();
                person.Name = "Stuart Dunkeld";
                person.Email = "*****@*****.**";
                item.Authors.Add(person);

                items.Add(item);
            }

            postfeed.Items = items;
            return postfeed;
        }
Exemplo n.º 5
0
		protected SyndicationPerson (SyndicationPerson source)
		{
			if (source == null)
				throw new ArgumentNullException ("source");
			email = source.email;
			name = source.name;
			uri = source.uri;
			extensions = source.extensions.Clone ();
		}
 public JsonSyndicationPerson(SyndicationPerson person)
 {
     if (person != null)
     {
         this.Email = person.Email;
         this.Name = person.Name;
         this.Uri = person.Uri;
     }
 }
 protected SyndicationPerson(SyndicationPerson source)
 {
     if (source == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
     }
     this.email = source.email;
     this.name = source.name;
     this.uri = source.uri;
     this.extensions = source.extensions.Clone();
 }
Exemplo n.º 8
0
 public RssFeedSettings(string feedId, string title, string description, SyndicationPerson author, string imageUrl, string language, string copyright, Uri feedHomeUri)
 {
     _author = author;
     _copyright = copyright;
     _feedHomeUri = feedHomeUri;
     _description = description;
     _feedId = feedId;
     _imageUrl = imageUrl;
     _language = language;
     _title = title;
 }
Exemplo n.º 9
0
        private SyndicationFeed GetFeed()
        {
            //get website urls
            string feedUrl = Request.Url.AbsoluteUri;
            string siteUrl = Request.Url.GetLeftPart(UriPartial.Authority);

            //get posts & tags
            var posts = _db.Posts.Include(p => p.Tags).OrderByDescending(p => p.Updated);

            //populate feed
            var lastUpdate = posts.Take(1).SingleOrDefault().Updated;
            var feed = new SyndicationFeed("Simon & Helen Wedding News", "Keeping you up to date with news and information regarding Simon & Helen's wedding.", new Uri(feedUrl), "FeedID", lastUpdate);

            var items = posts.ToList().Select(p => new SyndicationItem(
                                    p.Title,
                                    new TextSyndicationContent(p.PostContent),
                                    new Uri(siteUrl + "/News/" + "/" + p.PostId),
                                    p.PostId.ToString(),
                                    p.Updated
                                    )).ToDictionary(p => p.Id);

            foreach (var postWithTags in posts.Where(p => p.Tags.Count > 0))
            {
                var item = items[postWithTags.PostId.ToString()];
                foreach (var tag in postWithTags.Tags)
                    item.Categories.Add(new SyndicationCategory(tag.Name));
            }

            feed.Items = items.Values.ToList<SyndicationItem>();

            //Set other feed properties
            feed.Id = "C27D9B11-1039-4209-9333-4A853CAFD306";
            feed.Language = "en-gb";
            feed.Generator = "Needham Blog Engine 1.0";
            feed.ImageUrl = new Uri(siteUrl + "/images/apple-touch-icon-114x114.png");

            SyndicationPerson sp = new SyndicationPerson("*****@*****.**", "Simon & Helen", siteUrl);

            feed.Authors.Add(sp);
            feed.Contributors.Add(sp);

            feed.Copyright = new TextSyndicationContent("Copyright (c) Simon Needham & Helen Tweedle 2012");
            feed.Description = new TextSyndicationContent("Keeping you up to date with news and information regarding Simon & Helen's wedding.");

            return feed;
        }
Exemplo n.º 10
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.º 11
0
 internal static protected Task WriteAttributeExtensionsAsync(XmlWriter writer, SyndicationPerson person, string version)
 {
     if (person == null)
     {
         throw new ArgumentNullException(nameof(person));
     }
     return(person.WriteAttributeExtensionsAsync(writer, version));
 }
 private void WritePerson(XmlWriter writer, string elementTag, SyndicationPerson person)
 {
     writer.WriteStartElement(elementTag, "");
     SyndicationFeedFormatter.WriteAttributeExtensions(writer, person, this.Version);
     writer.WriteString(person.Email);
     writer.WriteEndElement();
 }
 protected internal static void WriteElementExtensions(System.Xml.XmlWriter writer, SyndicationPerson person, string version)
 {
 }
 protected internal static bool TryParseAttribute(string name, string ns, string value, SyndicationPerson person, string version)
 {
   return default(bool);
 }
Exemplo n.º 15
0
 protected static async Task WriteAttributeExtensionsAsync(XmlWriter writer, SyndicationPerson person, string version)
 {
     await SyndicationFeedFormatter.WriteAttributeExtensionsAsync(writer, person, version);
 }
Exemplo n.º 16
0
 protected internal static bool TryParseAttribute(string name, string ns, string value, SyndicationPerson person, string version)
 {
     if (person == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("person");
     }
     return(FeedUtils.IsXmlns(name, ns) || person.TryParseAttribute(name, ns, value, version));
 }
 protected static void LoadElementExtensions(System.Xml.XmlReader reader, SyndicationPerson person, int maxExtensionSize)
 {
 }
 protected void WriteElementExtensions(System.Xml.XmlWriter writer, SyndicationPerson person, string version)
 {
 }
 protected static void WriteAttributeExtensions(System.Xml.XmlWriter writer, SyndicationPerson person, string version)
 {
 }
 protected static bool TryParseElement(System.Xml.XmlReader reader, SyndicationPerson person, string version)
 {
     return(default(bool));
 }
 protected static void WriteAttributeExtensions(XmlWriter writer, SyndicationPerson person, string version)
 {
     SyndicationFeedFormatter.WriteAttributeExtensions(writer, person, version);
 }
 protected static void LoadElementExtensions(XmlReader reader, SyndicationPerson person, int maxExtensionSize)
 {
     SyndicationFeedFormatter.LoadElementExtensions(reader, person, maxExtensionSize);
 }
Exemplo n.º 23
0
		protected internal static bool TryParseElement (XmlReader reader, SyndicationPerson person, string version)
		{
			if (person == null)
				throw new ArgumentNullException ("person");
			return person.TryParseElement (reader, version);
		}
Exemplo n.º 24
0
		protected internal static void LoadElementExtensions (XmlReader reader, SyndicationPerson person, int maxExtensionSize)
		{
			person.ElementExtensions.Add (reader);
		}
 protected static bool TryParseAttribute(string name, string ns, string value, SyndicationPerson person, string version)
 {
     return(default(bool));
 }
        internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationPerson person)
        {
            Debug.Assert(person != null);

            CloseBuffer(buffer, writer);
            person.LoadElementExtensions(buffer);
        }
Exemplo n.º 27
0
 void WritePerson(XmlWriter writer, string elementTag, SyndicationPerson person)
 {
     writer.WriteStartElement(elementTag, Rss20Constants.Rss20Namespace);
     WriteAttributeExtensions(writer, person, this.Version);
     writer.WriteString(person.Email);
     writer.WriteEndElement();
 }
 internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationPerson person)
 {
     SyndicationFeedFormatter.LoadElementExtensions(buffer, writer, person);
 }
Exemplo n.º 29
0
 void ReadPerson(XmlReader reader, SyndicationPerson person)
 {
     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 (!TryParseAttribute(name, ns, val, person, this.Version))
             {
                 if (this.preserveAttributeExtensions)
                 {
                     person.AttributeExtensions.Add(new XmlQualifiedName(name, ns), val);
                 }
                 else
                 {
                     TraceSyndicationElementIgnoredOnRead(reader);
                 }
             }
         }
     }
     reader.ReadStartElement();
     if (!isEmpty)
     {
         string email = reader.ReadString();
         reader.ReadEndElement();
         person.Email = email;
     }
 }
 protected internal static bool TryParseElement(System.Xml.XmlReader reader, SyndicationPerson person, string version)
 {
   return default(bool);
 }
Exemplo n.º 31
0
        // read

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

            SetItem(CreateItemInstance());

            reader.MoveToContent();

            if (PreserveAttributeExtensions && reader.MoveToFirstAttribute())
            {
                do
                {
                    if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                    {
                        continue;
                    }
                    if (!TryParseAttribute(reader.LocalName, reader.NamespaceURI, reader.Value, Item, Version))
                    {
                        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 'item' element");
                }
                if (reader.NamespaceURI == String.Empty)
                {
                    switch (reader.LocalName)
                    {
                    case "title":
                        Item.Title = ReadTextSyndicationContent(reader);
                        continue;

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

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

                    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 "comments": // treated as extension ...
                    case "enclosure":
                        l = Item.CreateLink();
                        ReadEnclosure(reader, l);
                        Item.Links.Add(l);
                        continue;

                    case "guid":
                        Item.AddPermalink(CreateUri(reader.ReadElementContentAsString()));
                        continue;

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

                    case "source":
                        Item.SourceFeed = new SyndicationFeed();
                        ReadSourceFeed(reader, Item.SourceFeed);
                        continue;
                    }
                }
                else if (SerializeExtensionsAsAtom && reader.NamespaceURI == AtomNamespace)
                {
                    switch (reader.LocalName)
                    {
                    case "contributor":
                        SyndicationPerson p = Item.CreatePerson();
                        ReadPersonAtom10(reader, p);
                        Item.Contributors.Add(p);
                        continue;

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

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

                    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>
        }
 protected internal static void LoadElementExtensions(System.Xml.XmlReader reader, SyndicationPerson person, int maxExtensionSize)
 {
 }
Exemplo n.º 33
0
 protected internal static bool TryParseAttribute(string name, string ns, string value, SyndicationPerson person, string version)
 {
     if (person == null)
     {
         throw new ArgumentNullException("person");
     }
     return(person.TryParseAttribute(name, ns, value, version));
 }
 private void ReadPerson(XmlReader reader, SyndicationPerson person)
 {
     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 (!SyndicationFeedFormatter.TryParseAttribute(localName, namespaceURI, str3, person, this.Version))
                 {
                     if (this.preserveAttributeExtensions)
                     {
                         person.AttributeExtensions.Add(new XmlQualifiedName(localName, namespaceURI), str3);
                     }
                     else
                     {
                         SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                     }
                 }
             }
         }
     }
     reader.ReadStartElement();
     if (!isEmptyElement)
     {
         string str4 = reader.ReadString();
         reader.ReadEndElement();
         person.Email = str4;
     }
 }
Exemplo n.º 35
0
 protected internal static void LoadElementExtensions(XmlReader reader, SyndicationPerson person, int maxExtensionSize)
 {
     person.ElementExtensions.Add(reader);
 }
Exemplo n.º 36
0
        internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationPerson person)
        {
            if (person == null)
            {
                throw new ArgumentNullException(nameof(person));
            }

            CloseBuffer(buffer, writer);
            person.LoadElementExtensions(buffer);
        }
Exemplo n.º 37
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.º 38
0
		protected internal static bool TryParseAttribute (string name, string ns, string value, SyndicationPerson person, string version)
		{
			if (person == null)
				throw new ArgumentNullException ("person");
			return person.TryParseAttribute (name, ns, value, version);
		}
        private static void SetItemValues(IRow row, ref SyndicationItem item, KeyValuePair<string, GeoRSSExportItem> itemConfig, GeoRSSExportItem itemExportProperty)
        {
            try
            {
                //Title
                if (itemConfig.Key == "Title")
                    item.Title = new TextSyndicationContent(GetItemContent(row, itemExportProperty));

                //Content
                if (itemConfig.Key == "Content")
                    item.Content = new TextSyndicationContent(GetItemContent(row, itemExportProperty));

                //Author
                //todo  - we only currently support author as a single string, assume to be name - better to support all author properties i.e.
                //authorName
                //authorEmail
                //authorUri
                if (itemConfig.Key == "Author")
                {

                    SyndicationPerson author = new SyndicationPerson();
                    author.Name = GetItemContent(row, itemExportProperty);
                    item.Authors.Add(author);
                }

                //Contributors
                //todo  - we only currently support author as a single string, assume to be name - better to support all author properties i.e.
                //controbutorName
                //controbutorEmail
                //controbutorNameUri
                if (itemConfig.Key == "Contributors")
                {
                    SyndicationPerson author = new SyndicationPerson();
                    author.Name = GetItemContent(row, itemExportProperty);
                    item.Contributors.Add(author);

                }

                //Copyright
                if (itemConfig.Key == "Copyright")
                    item.Copyright = new TextSyndicationContent(GetItemContent(row, itemExportProperty));

                //Id
                if (itemConfig.Key == "Id")
                {

                    if (itemExportProperty.AutoGenerate)
                        item.Id = Guid.NewGuid().ToString();
                    else
                        item.Id = GetItemContent(row, itemExportProperty);

                }

                //PublishDate
                if (itemConfig.Key == "PublishDate")
                {

                    if (itemExportProperty.AutoGenerate)
                        item.PublishDate = DateTime.Now;
                    else
                        item.PublishDate = Convert.ToDateTime(GetItemContent(row, itemExportProperty));

                }

                //LastUpdatedTime
                if (itemConfig.Key == "LastUpdatedTime")
                {

                    if (itemExportProperty.AutoGenerate)
                        item.LastUpdatedTime = DateTime.Now;
                    else
                        item.LastUpdatedTime = Convert.ToDateTime(GetItemContent(row, itemExportProperty));

                }

                //Links
                //todo  - we only currently support link as a single string, assume to be uri - better to support all link properties
                if (itemConfig.Key == "Links")
                {
                    SyndicationLink link = new SyndicationLink();
                    link.Uri = new Uri(GetItemContent(row, itemExportProperty));
                    item.Links.Add(link);
                }

                //Summary
                if (itemConfig.Key == "Summary")
                    //item.Summary = new TextSyndicationContent(GetItemContent(row, itemExportProperty));
                    item.Summary = SyndicationContent.CreateHtmlContent(GetItemContent(row, itemExportProperty));
            }
            catch (Exception ex)
            {
                Exporter.logger.LogMessage(ESRI.ArcGIS.SOESupport.ServerLogger.msgType.error,
                    "SetItenValues",
                    999999,
                    "Item Config Key:" + itemConfig.Key +
                    "Error Message: " + ex.Message.ToString());
            }
            finally
            {

            }
        }
Exemplo n.º 40
0
		protected internal void WriteElementExtensions (XmlWriter writer, SyndicationPerson person, string version)
		{
			if (person == null)
				throw new ArgumentNullException ("person");
			person.WriteElementExtensions (writer, version);
		}
        // 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>
        }
        public void Write()
        {
            DateTimeOffset offset = DateTimeOffset.UtcNow;

            string expectedBody = String.Format("<rss xmlns:a10=\"http://www.w3.org/2005/Atom\" version=\"2.0\"><channel><title>Test Feed</title><link>http://www.springframework.net/Feed</link><description>This is a test feed</description><copyright>Copyright 2010</copyright><managingEditor>[email protected]</managingEditor><lastBuildDate>{0}</lastBuildDate><a10:id>Atom10FeedHttpMessageConverterTests.Write</a10:id></channel></rss>", 
                offset.ToString("ddd, dd MMM yyyy HH:mm:ss Z", CultureInfo.InvariantCulture));
            
            SyndicationFeed body = new SyndicationFeed("Test Feed", "This is a test feed", new Uri("http://www.springframework.net/Feed"), "Atom10FeedHttpMessageConverterTests.Write", offset);
            SyndicationPerson sp = new SyndicationPerson("*****@*****.**", "Bruno Baïa", "http://www.springframework.net/bbaia");
            body.Authors.Add(sp);
            body.Copyright = new TextSyndicationContent("Copyright 2010");

            MockHttpOutputMessage message = new MockHttpOutputMessage();

            converter.Write(body, null, message);

            Assert.AreEqual(expectedBody, message.GetBodyAsString(Encoding.UTF8), "Invalid result");
            Assert.AreEqual(new MediaType("application", "rss+xml"), message.Headers.ContentType, "Invalid content-type");
            //Assert.IsTrue(message.Headers.ContentLength > -1, "Invalid content-length");
        }
 internal static protected bool TryParseAttribute(string name, string ns, string value, SyndicationPerson person, string version)
 {
     if (person == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("person");
     }
     if (FeedUtils.IsXmlns(name, ns))
     {
         return(true);
     }
     return(person.TryParseAttribute(name, ns, value, version));
 }
        protected internal static bool TryParseAttribute(string name, string ns, string value, SyndicationPerson person, string version)
        {
            if (person == null)
            {
                throw new ArgumentNullException(nameof(person));
            }

            if (FeedUtils.IsXmlns(name, ns))
            {
                return(true);
            }
            return(person.TryParseAttribute(name, ns, value, version));
        }
Exemplo n.º 45
0
 protected SyndicationPerson(SyndicationPerson source !!)
 {
Exemplo n.º 46
0
 internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationPerson person)
 {
     SyndicationFeedFormatter.LoadElementExtensions(buffer, writer, person);
 }
Exemplo n.º 47
0
 protected void WriteElementExtensions(XmlWriter writer, SyndicationPerson person, string version)
 {
     SyndicationFeedFormatter.WriteElementExtensions(writer, person, version);
 }
Exemplo n.º 48
0
 protected Task WriteElementExtensionsAsync(XmlWriter writer, SyndicationPerson person, string version)
 {
     return(SyndicationFeedFormatter.WriteElementExtensionsAsync(writer, person, version));
 }
 protected void WriteElementExtensions(XmlWriter writer, SyndicationPerson person, string version)
 {
     SyndicationFeedFormatter.WriteElementExtensions(writer, person, version);
 }
 internal static void LoadElementExtensions(XmlBuffer buffer, XmlDictionaryWriter writer, SyndicationPerson person)
 {
     if (person == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("person");
     }
     CloseBuffer(buffer, writer);
     person.LoadElementExtensions(buffer);
 }
Exemplo n.º 51
0
 protected static bool TryParseElement(XmlReader reader, SyndicationPerson person, string version)
 {
     return(SyndicationFeedFormatter.TryParseElement(reader, person, version));
 }
Exemplo n.º 52
0
 protected static bool TryParseAttribute(string name, string ns, string value, SyndicationPerson person, string version)
 {
     return(SyndicationFeedFormatter.TryParseAttribute(name, ns, value, person, version));
 }
 /// <summary>
 /// Creates a new author syndication specific object
 /// </summary>
 /// <param name="createNull">Whether to create a null author or a non-null author</param>
 private void CreateAuthor(bool createNull)
 {
     if (!this.authorInfoPresent)
     {
         this.author = createNull ? new SyndicationPerson(null, String.Empty, null) : new SyndicationPerson();
         this.authorInfoPresent = true;
     }
 }
Exemplo n.º 54
0
 protected static void WriteAttributeExtensions(XmlWriter writer, SyndicationPerson person, string version)
 {
     SyndicationFeedFormatter.WriteAttributeExtensions(writer, person, version);
 }
Exemplo n.º 55
0
    /// <summary>
    /// Builds a dictionary based on a provided <see cref="System.ServiceModel.Syndication.SyndicationPerson"/>
    /// </summary>
    /// <param name="a">The <see cref="System.ServiceModel.Syndication.SyndicationPerson"/> to be converted to a dictionary.</param>
    /// <returns>A <see cref="System.Collections.Generic.Dictionary{string,object}"/> representation of the provided syndication person.</returns>
    private static Dictionary<string, object> BuildSyndicationPerson( SyndicationPerson a )
    {
        Dictionary<string, object> personDictionary = new Dictionary<string, object>();

        if ( a != null )
        {
            personDictionary.Add( "AttributeExtensions", a.AttributeExtensions.ToDictionary( ae => ae.Key.ToString(), ae => ae.Value ) );
            personDictionary.Add( "ElementExtensions", a.ElementExtensions );
            personDictionary.Add( "Email", a.Email );
            personDictionary.Add( "Name", a.Name );
            personDictionary.Add( "Uri", a.Uri == null ? null : a.Uri.ToString() );

        }

        return personDictionary;
    }
Exemplo n.º 56
0
 protected static void LoadElementExtensions(XmlReader reader, SyndicationPerson person, int maxExtensionSize)
 {
     SyndicationFeedFormatter.LoadElementExtensions(reader, person, maxExtensionSize);
 }
        void ReadPerson(XmlReader reader, SyndicationPerson person)
        {
            if (reader.MoveToFirstAttribute ()) {
                do {
                    if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                        continue;
                    if (!TryParseAttribute (reader.LocalName, reader.NamespaceURI, reader.Value, person, Version) && PreserveAttributeExtensions)
                        person.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 (reader.NodeType == XmlNodeType.Element && reader.NamespaceURI == AtomNamespace) {
                        switch (reader.LocalName) {
                        case "name":
                            person.Name = reader.ReadElementContentAsString ();
                            continue;
                        case "uri":
                            person.Uri = reader.ReadElementContentAsString ();
                            continue;
                        case "email":
                            person.Email = reader.ReadElementContentAsString ();
                            continue;
                        }
                    }
                    if (!TryParseElement (reader, person, Version)) {
                        if (PreserveElementExtensions)
                            // FIXME: what should be used for maxExtenswionSize
                            LoadElementExtensions (reader, person, int.MaxValue);
                        else
                            reader.Skip ();
                    }
                }
            }
            reader.Read (); // end element or empty element
        }