Ejemplo n.º 1
0
        public override void Parse()
        {
            base.Parse();

            while (XmlReader.Read())
            {
                if (XmlReader.Depth == 1)
                {
                    if (XmlReader.NodeType == XmlNodeType.Element)
                    {
                        switch (XmlReader.Name)
                        {
                            case "title":
                                XmlReader.MoveToContent();
                                Feed.Title = XmlReader.ReadString();
                                break;
                            case "description":
                                XmlReader.MoveToContent();
                                Feed.Description = XmlReader.ReadString();
                                break;
                            case "link":
                                XmlReader.MoveToContent();
                                Feed.WebUri = new FeedUri(XmlReader.ReadString());
                                break;
                            case "language":
                                XmlReader.MoveToContent();
                                Feed.Language = XmlReader.ReadString();
                                break;
                            case "copyright":
                                XmlReader.MoveToContent();
                                Feed.Copyright = XmlReader.ReadString();
                                break;
                            case "managingEditor":
                                XmlReader.MoveToContent();
                                Feed.Authors.Add(readPerson(XmlReader.ReadString()));
                                break;
                            case "webMaster":
                                XmlReader.MoveToContent();
                                Feed.WebMaster = readPerson(XmlReader.ReadString());
                                break;
                            case "pubDate":
                                XmlReader.MoveToContent();
                                Feed.Published = DTHelper.ParseDateTime(XmlReader.ReadString());
                                break;
                            case "lastBuildDate":
                                XmlReader.MoveToContent();
                                Feed.Updated = DTHelper.ParseDateTime(XmlReader.ReadString());
                                break;
                            case "category":
                                Category category = new Category();
                                while (XmlReader.MoveToNextAttribute())
                                {
                                    if (XmlReader.Name == "domain")
                                        category.Scheme = XmlReader.Value;
                                }
                                XmlReader.MoveToContent();
                                category.Label = category.Term = XmlReader.ReadString();
                                Feed.Categories.Add(category);
                                break;
                            case "generator":
                                Generator generator = new Generator();
                                XmlReader.MoveToContent();
                                generator.Name = XmlReader.ReadString();
                                if (Uri.IsWellFormedUriString(generator.Name, UriKind.Absolute))
                                    generator.Uri = generator.Name;
                                Feed.Generator = generator;
                                break;
                            case "docs":
                                XmlReader.MoveToContent();
                                Feed.RssDocumentation = XmlReader.ReadString();
                                break;
                            case "cloud":
                                Cloud cloud = new Cloud();
                                int port = 0;
                                while (XmlReader.MoveToNextAttribute())
                                {
                                    switch (XmlReader.Name)
                                    {
                                        case "domain": cloud.Domain = XmlReader.Value; break;
                                        case "path": cloud.Path = XmlReader.Value; break;
                                        case "port":
                                            Int32.TryParse(XmlReader.Value, out port);
                                            cloud.Port = port;
                                            break;
                                        case "protocol": cloud.Protocol = XmlReader.Value; break;
                                        case "registerProcedure": cloud.RegisterProcedure = XmlReader.Value; break;
                                    }
                                }
                                Feed.Cloud = cloud;
                                break;
                            case "ttl":
                                int ttl = 0;
                                XmlReader.MoveToContent();
                                Int32.TryParse(XmlReader.ReadString(), out ttl);
                                Feed.Ttl = ttl;
                                break;
                            case "image":
                                XmlReader.MoveToContent();
                                Feed.Image = readImage(XmlReader.ReadSubtree());
                                break;
                            case "rating": break; // PICS is not yet implemented
                            case "textInput": break; // The purpose of the <textInput> element is something of a mystery
                            case "skipHours":
                                XmlReader.MoveToContent();
                                short hour = 0;
                                if (Int16.TryParse(XmlReader.ReadString(), out hour))
                                    Feed.SkipHours.Add(hour);
                                break;
                            case "skipDays":
                                XmlReader.MoveToContent();
                                switch (XmlReader.ReadString())
                                {
                                    case "Monday": Feed.SkipDays.Add(Days.Monday); break;
                                    case "Tuesday": Feed.SkipDays.Add(Days.Tuesday); break;
                                    case "Wednesday": Feed.SkipDays.Add(Days.Wednesday); break;
                                    case "Thursday": Feed.SkipDays.Add(Days.Thursday); break;
                                    case "Friday": Feed.SkipDays.Add(Days.Friday); break;
                                    case "Saturday": Feed.SkipDays.Add(Days.Saturday); break;
                                    case "Sunday": Feed.SkipDays.Add(Days.Sunday); break;
                                }
                                break;
                            case "item":
                                XmlReader.MoveToContent();
                                readItem(XmlReader.ReadSubtree());
                                break;
                            default:
                                if (readModules && XmlReader.Prefix != String.Empty)
                                {
                                    IModule module = Feed.GetModule(XmlReader.Prefix);
                                    if (module != null)
                                        module.Parse(XmlReader.ReadSubtree());
                                }
                                break;
                        }
                    }
                }
            }

            Complete();
        }
Ejemplo n.º 2
0
 public Feed(Feed feed)
 {
     this.authors = feed.authors;
     this.categories = feed.categories;
     this.cloud = feed.cloud;
     this.contributors = feed.contributors;
     this.copyright = feed.copyright;
     this.description = feed.description;
     this.generator = feed.generator;
     this.icon = feed.icon;
     this.id = feed.id;
     this.image = feed.image;
     this.items = feed.items;
     this.language = feed.language;
     this.modules = feed.modules;
     this.published = feed.published;
     this.rssDocumentation = feed.rssDocumentation;
     this.skipDays = feed.skipDays;
     this.skipHours = feed.skipHours;
     this.title = feed.title;
     this.ttl = feed.ttl;
     this.updated = feed.updated;
     this.version = feed.version;
     this.webMaster = feed.webMaster;
     this.webUri = feed.webUri;
     this.xmlUri = feed.xmlUri;
 }