예제 #1
0
        /// <summary>
        /// Adds the or replace the optional feed reference element.
        /// </summary>
        /// <param name="newsItem">The news item.</param>
        /// <param name="feedUrl">The feed URL.</param>
        /// <param name="sourceID">The source ID.</param>
        /// <returns></returns>
        public static XmlElement AddOrReplaceOriginalFeedReference(INewsItem newsItem, string feedUrl, int sourceID)
        {
            if (newsItem == null)
            {
                throw new ArgumentNullException("newsItem");
            }

            XmlQualifiedName key     = AdditionalElements.GetQualifiedName(OriginalFeedRef);
            XmlQualifiedName attrKey = AdditionalElements.GetQualifiedName(OriginalSourceID);

            if (newsItem.OptionalElements == null)
            {
                newsItem.OptionalElements = new Dictionary <XmlQualifiedName, string>(2);
            }

            if (newsItem.OptionalElements.ContainsKey(key))
            {
                newsItem.OptionalElements.Remove(key);
            }

            XmlElement element = RssHelper.CreateXmlElement(Prefix, key, feedUrl);

            element.Attributes.Append(RssHelper.CreateXmlAttribute(String.Empty, attrKey, sourceID.ToString()));
            newsItem.OptionalElements.Add(key, element.OuterXml);

            return(element);
        }
예제 #2
0
        /// <summary>
        /// Returns the feed URL and source ID of the optional feed reference element for this <paramref name="newsItem"/>.
        /// </summary>
        /// <param name="newsFeed">The news feed.</param>
        /// <param name="sourceID">out: The source ID. -1 in case no source ID is available</param>
        /// <returns>
        /// The feed URL of the source feed if a pointer to it exists and NULL otherwise.
        /// </returns>
        public static string GetOriginalFeedReference(INewsFeed newsFeed, out int sourceID)
        {
            if (newsFeed == null)
            {
                throw new ArgumentNullException("newsFeed");
            }

            sourceID = -1;
            string           feedUrl = null;
            XmlQualifiedName key     = AdditionalElements.GetQualifiedName(OriginalFeedRef);
            XmlQualifiedName attrKey = AdditionalElements.GetQualifiedName(OriginalSourceID);

            if (key != null && newsFeed.Any != null && newsFeed.Any.Length > 0)
            {
                XmlElement origin = newsFeed.Any[0];
                feedUrl = origin.InnerText;

                if (origin.Attributes.Count > 0)
                {
                    XmlNode a = origin.Attributes.GetNamedItem(attrKey.Name, attrKey.Namespace);
                    if (a != null)
                    {
                        string fs = a.InnerText;
                        if (!String.IsNullOrEmpty(fs))
                        {
                            Int32.TryParse(fs, out sourceID);
                        }
                    }
                }
            }

            return(feedUrl);
        }
예제 #3
0
        /// <summary>
        /// Returns the feed URL and source ID of the optional feed reference element for this <paramref name="newsItem"/>.
        /// </summary>
        /// <param name="newsItem">The news item.</param>
        /// <param name="sourceID">out: The source ID. -1 in case no source ID is available</param>
        /// <returns>
        /// The feed URL of the source feed if a pointer to it exists and NULL otherwise.
        /// </returns>
        public static string GetOriginalFeedReference(INewsItem newsItem, out int sourceID)
        {
            if (newsItem == null)
            {
                throw new ArgumentNullException("newsItem");
            }

            sourceID = -1;
            string           feedUrl = null;
            XmlQualifiedName key     = AdditionalElements.GetQualifiedName(OriginalFeedRef);

            if (key != null && newsItem.OptionalElements.ContainsKey(key))
            {
                string str = newsItem.OptionalElements[key];

                int startIndex = str.IndexOf(">") + 1;
                int endIndex   = str.LastIndexOf("<");
                feedUrl = str.Substring(startIndex, endIndex - startIndex);

                endIndex   = startIndex;
                startIndex = str.IndexOf(OriginalSourceID + "=", 0, endIndex);
                if (startIndex > 0)
                {
                    startIndex = startIndex + (OriginalSourceID + "=").Length + 1;
                    endIndex   = str.IndexOf("\"", startIndex);
                    string fs = str.Substring(startIndex, endIndex - startIndex);
                    if (!String.IsNullOrEmpty(fs))
                    {
                        Int32.TryParse(fs, out sourceID);
                    }
                }
            }

            return(feedUrl);
        }
예제 #4
0
        /// <summary>
        /// Removes the optional feed reference element from <paramref name="newsItem"/>'s optional elements.
        /// </summary>
        /// <param name="newsItem">The news item.</param>
        public static void RemoveOriginalFeedReference(INewsItem newsItem)
        {
            if (newsItem == null)
            {
                throw new ArgumentNullException("newsItem");
            }

            XmlQualifiedName key = AdditionalElements.GetQualifiedName(OriginalFeedRef);

            if (key != null && newsItem.OptionalElements.ContainsKey(key))
            {
                newsItem.OptionalElements.Remove(key);
            }
        }