Пример #1
0
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Loads the properties of the RssCoreItem class with the contents of the parent element
        /// </summary>
        /// <param name="el">XElement</param>
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        public void LoadEl(XElement el)
        {
            RssRfc822DateTimeConverter dtConvert = new RssRfc822DateTimeConverter();

            switch (el.Name.LocalName)
            {
            case TAG_TITLE:
                title = xUtil.GetStr(el);
                break;

            case TAG_LINK:
                link = xUtil.GetStr(el);
                break;

            case TAG_DESCRIPTION:
                description = xUtil.GetStr(el);
                break;

            case TAG_AUTHOR:
                author = xUtil.GetStr(el);
                break;

            case TAG_CATEGORY:
                RssCoreItemCategory ctg = new RssCoreItemCategory();
                ctg.Load(el);
                categories.Add(ctg);
                break;

            case TAG_COMMENTS:
                comments = xUtil.GetStr(el);
                break;

            case TAG_ENCLOSURE:
                RssCoreItemEnclosure enc = new RssCoreItemEnclosure();
                enc.Load(el);
                enclosures.Add(enc);
                break;

            case TAG_GUID:
                guid = new RssCoreItemGuid();
                guid.Load(el);
                break;

            case TAG_PUBDATE:
                pubDate = dtConvert.ParseRfc822(xUtil.GetStr(el));
                break;

            case TAG_SOURCE:
                source = new RssCoreItemSource();
                source.Load(el);
                break;
            }   // end switch
        }
Пример #2
0
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Sets the property based upon the tag name of the provided XElement
        /// </summary>
        /// <param name="el">XElement</param>
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        public void LoadEl(XElement el)
        {
            RssRfc822DateTimeConverter dtConvert = new RssRfc822DateTimeConverter();

            if (el.Name.Namespace == XNamespace.None)
            {
                switch (el.Name.LocalName)
                {
                case TAG_TITLE:
                    title = xUtil.GetStr(el);
                    break;

                case TAG_LINK:
                    link = xUtil.GetStr(el);
                    break;

                case TAG_DESCRIPTION:
                    description = xUtil.GetStr(el);
                    break;

                case TAG_LANGUAGE:
                    language = xUtil.GetStr(el);
                    break;

                case TAG_COPYRIGHT:
                    copyright = xUtil.GetStr(el);
                    break;

                case TAG_MANAGINGEDITOR:
                    managingEditor = xUtil.GetStr(el);
                    break;

                case TAG_WEBMASTER:
                    webMaster = xUtil.GetStr(el);
                    break;

                case TAG_PUBDATE:
                    pubDate = dtConvert.ParseRfc822(xUtil.GetStr(el));
                    break;

                case TAG_LASTBUILDDATE:
                    lastBuildDate = dtConvert.ParseRfc822(xUtil.GetStr(el));
                    break;

                case TAG_CATEGORY:
                    RssCoreChannelCategory ctg = new RssCoreChannelCategory();
                    ctg.Load(el);
                    categories.Add(ctg);
                    break;

                case TAG_GENERATOR:
                    generator = xUtil.GetStr(el);
                    break;

                case TAG_DOCS:
                    docs = xUtil.GetStr(el);
                    break;

                case TAG_CLOUD:
                    RssCoreChannelCloud c = new RssCoreChannelCloud();
                    c.Load(el);
                    cloud.Add(c);
                    break;

                case TAG_TTL:
                    ttl = xUtil.GetInt(el);
                    break;

                case TAG_IMAGE:
                    image = new RssCoreChannelImage();
                    image.Load(el);
                    break;

                case TAG_TEXTINPUT:
                    textInput = new RssCoreChannelTextInput();
                    textInput.Load(el);
                    break;

                case TAG_SKIPHOURS:
                    skipHours = new RssCoreChannelSkipHours();
                    skipHours.Load(el);
                    break;

                case TAG_SKIPDAYS:
                    skipDays = new RssCoreChannelSkipDays();
                    skipDays.Load(el);
                    break;
                } // end switch
            }     // end if namespace
        }
Пример #3
0
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Builds the xml fragment representing the properties of the RssCoreItem class
        /// </summary>
        /// <param name="parEl"></param>
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        public void SetEl(XElement parEl)
        {
            RssRfc822DateTimeConverter dtConvert = new RssRfc822DateTimeConverter();

            if (title.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_TITLE, title);
            }
            if (link.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_LINK, link);
            }
            if (description.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_DESCRIPTION, WebUtility.HtmlEncode(description));
            }
            if (author.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_AUTHOR, author);
            }


            if (categories.Count > 0)
            {
                for (int i = 0; i < categories.Count; i++)
                {
                    XElement ctgEl = categories[i].GetEl();
                    parEl.Add(ctgEl);
                }
            }


            if (comments.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_COMMENTS, WebUtility.HtmlEncode(comments));
            }

            if (enclosures.Count > 0)
            {
                for (int i = 0; i < enclosures.Count; i++)
                {
                    XElement enclosureEl = enclosures[i].GetEl();
                    parEl.Add(enclosureEl);
                }
            }

            if (guid != null)
            {
                XElement guidEl = guid.GetEl();
                parEl.Add(guidEl);
            }


            if (pubDate != DateTime.MinValue)
            {
                xUtil.AddEl(parEl, TAG_PUBDATE, dtConvert.FormatDateTime(pubDate));
            }


            if (source != null)
            {
                XElement sourceEl = source.GetEl();
                parEl.Add(sourceEl);
            }
        }
Пример #4
0
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Sets the element with the descendents of the parent XElement
        /// </summary>
        /// <param name="parEl"></param>
        /// <returns></returns>
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        public void SetEl(XElement parEl)
        {
            RssRfc822DateTimeConverter dtConvert = new RssRfc822DateTimeConverter();

            // channel title
            xUtil.AddEl(parEl, TAG_TITLE, title);

            // link to channel
            xUtil.AddEl(parEl, TAG_LINK, link);

            // channel description
            xUtil.AddEl(parEl, TAG_DESCRIPTION, WebUtility.HtmlEncode(description));

            // optional elements are only included if they are not null or have string length
            // greater than zero or in the case of dates, greater that datetime.minvalue

            // language
            if (language.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_LANGUAGE, language);
            }

            // copyright
            if (copyright.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_COPYRIGHT, copyright);
            }

            // managing editor
            if (managingEditor.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_MANAGINGEDITOR, managingEditor);
            }

            // webmaster
            if (webMaster.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_WEBMASTER, webMaster);
            }

            if (pubDate != DateTime.MinValue)
            {
                xUtil.AddEl(parEl, TAG_PUBDATE, dtConvert.FormatDateTime(pubDate));
            }

            if (lastBuildDate != DateTime.MinValue)
            {
                xUtil.AddEl(parEl, TAG_LASTBUILDDATE, dtConvert.FormatDateTime(lastBuildDate));
            }


            // applicable categories
            if (categories.Count > 0)
            {
                for (int i = 0; i < categories.Count; i++)
                {
                    XElement el = categories[i].GetEl();
                    parEl.Add(el);
                }
            }


            // arrogance
            if (generator.Length == 0)
            {
                generator = RSS.GENERATOR;
            }


            // generator
            if (generator.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_GENERATOR, generator);
            }

            if (docs.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_DOCS, docs);
            }

            // multiple cloud interfaces allowed here
            if (cloud.Count > 0)
            {
                for (int i = 0; i < cloud.Count; i++)
                {
                    XElement cloudEl = cloud[i].GetEl();
                    parEl.Add(cloudEl);
                }
            }

            if (ttl > 0)
            {
                xUtil.AddEl(parEl, TAG_TTL, ttl);
            }

            if (image != null)
            {
                XElement imageEl = image.GetEl();
                parEl.Add(imageEl);
            }

            if (textInput != null)
            {
                XElement textInputEl = textInput.GetEl();
                parEl.Add(textInputEl);
            }

            if (skipHours != null)
            {
                if (skipHours.Hours.Count > 0)
                {
                    XElement skipHoursEl = skipHours.GetEl();
                    parEl.Add(skipHoursEl);
                }
            }

            if (skipDays != null)
            {
                if (skipDays.Days.Count > 0)
                {
                    XElement skipDaysEl = skipDays.GetEl();
                    parEl.Add(skipDaysEl);
                }
            }
        }