Esempio n. 1
0
        public RssSubscription(Opml opml) : this()
        {
            Title        = opml.Title;
            DateCreated  = opml.DateCreated;
            DateModified = opml.DateModified;

            var line = 0;

            foreach (var x in opml.Outlines)
            {
                line++;
                var item = new RssSubscriptionItem();
                foreach (var y in x.Attributes)
                {
                    try
                    {
                        if (y.Key == "text")
                        {
                            item.Text = y.Value;
                        }
                        else if (y.Key == "description")
                        {
                            item.Description = y.Value;
                        }
                        else if (y.Key == "title")
                        {
                            item.Title = y.Value;
                        }
                        else if (y.Key == "name")
                        {
                            item.Name = y.Value;
                        }
                        else if (y.Key == "htmlUrl" && !string.IsNullOrWhiteSpace(y.Value))
                        {
                            item.HtmlUri = new Uri(y.Value);
                        }
                        else if (y.Key == "xmlUrl" && !string.IsNullOrWhiteSpace(y.Value))
                        {
                            item.XmlUri = new Uri(y.Value);
                        }
                    }
                    catch (Exception ex)
                    {
                        ParsingErrors.Add("Error at line " + line + " in processing attribute "
                                          + y.Key + " with value " + y.Value + " " + ex.Message);
                    }
                }

                Items.Add(item);
            }
        }
Esempio n. 2
0
File: Opml.cs Progetto: dodyg/Vltava
        public static Result <Opml> Parse(string xml)
        {
            if (string.IsNullOrWhiteSpace(xml))
            {
                throw new ArgumentNullException($"{nameof(xml)} is null");
            }

            var opml = new Opml();
            var res  = opml.LoadFromXML(xml);

            if (res.IsTrue)
            {
                return(Result <Opml> .True(opml));
            }
            else
            {
                return(Result <Opml> .False(res.ExceptionObject));
            }
        }
Esempio n. 3
0
        public Opml ToOpml()
        {
            var opml = new Opml
            {
                Title        = Title,
                OwnerName    = OwnerName,
                OwnerEmail   = OwnerEmail,
                DateCreated  = DateCreated,
                DateModified = DateModified
            };

            foreach (var i in Items.Select(
                         x =>
            {
                var item = new Outline();
                item.Attributes["text"] = x.Text;
                item.Attributes["type"] = "rss";
                if (!string.IsNullOrWhiteSpace(x.Name))
                {
                    item.Attributes["name"] = x.Name;
                }
                if (!string.IsNullOrWhiteSpace(x.Description))
                {
                    item.Attributes["description"] = x.Description;
                }
                if (x.HtmlUri != null)
                {
                    item.Attributes["htmlUrl"] = x.HtmlUri.ToString();
                }
                if (x.XmlUri != null)
                {
                    item.Attributes["xmlUrl"] = x.XmlUri.ToString();
                }

                return(item);
            }))
            {
                opml.Outlines.Add(i);
            }

            return(opml);
        }