Example #1
0
        /// <summary>
        /// Converts the atom to RSS.
        /// </summary>
        /// <param name="documentType">Rss Document Type</param>
        /// <param name="inputXml">The input XML.</param>
        /// <returns>string</returns>
        public static string ConvertRssTo(DocumentType ouputType, string rssXml)
        {
            if (string.IsNullOrEmpty(rssXml))
            {
                return(null);
            }

            switch (ouputType)
            {
            case DocumentType.Rss:
                return(rssXml);

            case DocumentType.Atom:
                using (Stream stream = GetStreamFromResource(Constants.RssToAtomXsl))
                {
                    return(RssXmlHelper.DoXslTransform(rssXml, stream));
                }

            case DocumentType.Rdf:
                using (Stream stream = GetStreamFromResource(Constants.RssToRdfXsl))
                {
                    return(RssXmlHelper.DoXslTransform(rssXml, stream));
                }

            case DocumentType.Opml:
                using (Stream stream = GetStreamFromResource(Constants.RssToOpmlXsl))
                {
                    return(RssXmlHelper.DoXslTransform(rssXml, stream));
                }

            default:
                return(null);
            }
        }
Example #2
0
        private void GetRssFeeds(object state)
        {
            OutlineInfo outline = null;

            try
            {
                outline = (OutlineInfo)state;
                string xmlString = string.Empty;

                using (Stream rssStream = DownloadManager.GetFeed(outline.Outline.XmlUrl))
                {
                    using (XmlTextReader reader = new XmlTextReader(rssStream))
                    {
                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                xmlString = reader.ReadOuterXml();
                                break;
                            }
                        }
                    }
                }

                ////convert to rss
                xmlString = RssXmlHelper.ConvertToRssXml(xmlString);

                if (!string.IsNullOrEmpty(xmlString))
                {
                    RssXmlSchemaValidator validator = new RssXmlSchemaValidator();
                    Assembly assembly = Assembly.GetExecutingAssembly();
                    using (Stream stream = assembly.GetManifestResourceStream(Constants.Rss20Xsd))
                    {
                        lock (aggregateRss)
                        {
                            validator.ValidXmlDoc(xmlString, new XmlTextReader(stream));

                            if (validator.IsValidXml)
                            {
                                aggregateRss.Add(xmlString);
                            }
                        }

                        if (!validator.IsValidXml)
                        {
                            NotifySubscribers(null, "Rss not valid in OPML for - " + outline.Outline.XmlUrl, RssSeverityType.Warning);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                NotifySubscribers(ex, ex.Message, RssSeverityType.Error);
            }
            finally
            {
                rssEvents[outline.Index].Set();
            }
        }
Example #3
0
        private static T LoadFromRssXml <T>(string rssXml) where T : RssDocumentBase
        {
            if (string.IsNullOrEmpty(rssXml))
            {
                throw new ArgumentException("xml");
            }

            T rss = RssXmlHelper.DeserializeFromXmlUsingStringReader <T>(rssXml);

            return(rss);
        }
Example #4
0
        private static T LoadFromRssXml <T>(string rssXml) where T : RssDocumentBase
        {
            if (string.IsNullOrEmpty(rssXml))
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The argument '{0}' is Null or Empty", "xml"));
            }

            T rss = RssXmlHelper.DeserializeFromXmlUsingStringReader <T>(rssXml);

            return(rss);
        }
Example #5
0
        private static T LoadFromRssXml <T>(string rssXml) where T : RssDocumentBase
        {
            if (string.IsNullOrEmpty(rssXml))
            {
                throw new ArgumentException(string.Format(Resources.RssToolkit.Culture, Resources.RssToolkit.ArgmentException, "xml"));
            }

            T rss = RssXmlHelper.DeserializeFromXmlUsingStringReader <T>(rssXml);

            return(rss);
        }
Example #6
0
        protected static T Load <T>(XmlReader reader) where T : RssDocumentBase
        {
            T      rss    = null;
            string rssXml = RssXmlHelper.ConvertToRssXml(reader);

            if (!string.IsNullOrEmpty(rssXml))
            {
                rss = LoadFromRssXml <T>(rssXml);
            }

            return(rss);
        }
Example #7
0
        /// <summary>
        /// Converts to RSS XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Xml string in Rss Format</returns>
        public static string ConvertToRssXml(XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            string rssXml = string.Empty;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    DocumentType feedType = RssXmlHelper.GetDocumentType(reader.LocalName);
                    string       outerXml = reader.ReadOuterXml();
                    switch (feedType)
                    {
                    case DocumentType.Rss:
                        rssXml = outerXml;
                        break;

                    case DocumentType.Opml:
                        RssAggregator aggregator = new RssAggregator();
                        aggregator.Load(outerXml);
                        rssXml = aggregator.RssXml;
                        break;

                    case DocumentType.Atom:
                        rssXml = DoXslTransform(outerXml, GetStreamFromResource(Constants.AtomToRssXsl));
                        break;

                    case DocumentType.Rdf:
                        rssXml = DoXslTransform(outerXml, GetStreamFromResource(Constants.RdfToRssXsl));
                        break;
                    }

                    break;
                }
            }

            // fix namespaces
            if (reader.NameTable.Get("http://search.yahoo.com/mrss") != null)
            {
                rssXml = rssXml.Replace("http://search.yahoo.com/mrss", "http://search.yahoo.com/mrss/");
            }

            return(rssXml);
        }
Example #8
0
        public static T LoadRssFromOpmlUrl <T>(string url) where T : RssDocumentBase
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The argument '{0}' is Null or Empty", "url"));
            }

            // resolve app-relative URLs
            url = RssXmlHelper.ResolveAppRelativeLinkToUrl(url);

            RssAggregator aggregator = new RssAggregator();

            aggregator.Load(new System.Uri(url));
            string rssXml = aggregator.RssXml;

            return(RssXmlHelper.DeserializeFromXmlUsingStringReader <T>(rssXml));
        }
Example #9
0
        /// <summary>
        /// Converts to RSS XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Xml string in Rss Format</returns>
        public static string ConvertToRssXml(XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            string rssXml = string.Empty;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    DocumentType feedType = RssXmlHelper.GetDocumentType(reader.LocalName);
                    string       outerXml = reader.ReadOuterXml();
                    switch (feedType)
                    {
                    case DocumentType.Rss:
                        rssXml = outerXml;
                        break;

                    case DocumentType.Opml:
                        throw new NotImplementedException();

                    //RssAggregator aggregator = new RssAggregator();
                    //aggregator.Load(outerXml);
                    //rssXml = aggregator.RssXml;
                    //break;
                    case DocumentType.Atom:
                        //rssXml = DoXslTransform(outerXml, GetStreamFromResource(Constants.AtomToRssXsl));
                        break;

                    case DocumentType.Rdf:
                        //rssXml = DoXslTransform(outerXml, GetStreamFromResource(Constants.RdfToRssXsl));
                        break;
                    }

                    break;
                }
            }

            return(rssXml);
        }
Example #10
0
        protected static T Load <T>(System.Uri url) where T : RssDocumentBase
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            // resolve app-relative URLs
            string rssUrl = RssXmlHelper.ResolveAppRelativeLinkToUrl(url.ToString());

            // download the feed
            using (Stream cachedXml = DownloadManager.GetFeed(rssUrl))
            {
                using (XmlTextReader reader = new XmlTextReader(cachedXml))
                {
                    T rss = Load <T>(reader);

                    //// remember the url
                    rss.Url = rssUrl;

                    return(rss);
                }
            }
        }
Example #11
0
 /// <summary>
 /// Coverts to DataSet
 /// </summary>
 /// <returns>DataSet</returns>
 public DataSet ToDataSet()
 {
     return(RssXmlHelper.ToDataSet(ToXml(DocumentType.Rss)));
 }
Example #12
0
        private void MergeRss(string title)
        {
            string emptyXml = string.Format(
                CultureInfo.InvariantCulture,
                @"<?xml version=""1.0"" encoding=""utf-8""?><rss version=""2.0""><channel>{0}</channel></rss>",
                string.IsNullOrEmpty(title) ? string.Empty : "<title>" + title + "</title>");

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(emptyXml);
            try
            {
                foreach (string inputXml in aggregateRss)
                {
                    XmlNodeList nodes;
                    XmlDocument rssDocument = new XmlDocument();
                    XmlNode     channelNode = xmlDocument.SelectSingleNode("rss/channel");

                    if (!string.IsNullOrEmpty(inputXml) && channelNode != null)
                    {
                        rssDocument.LoadXml(inputXml);
                        nodes = rssDocument.SelectNodes("rss/channel/item");
                        SortedList <string, XmlElement> nodesList = new SortedList <string, XmlElement>();
                        foreach (XmlElement node in nodes)
                        {
                            DateTime date = DateTime.MinValue;
                            try
                            {
                                XmlNodeList pubDates = node.GetElementsByTagName("pubDate");
                                if (pubDates.Count > 0)
                                {
                                    XmlNode pubDate = pubDates[0];
                                    date = RssXmlHelper.Parse(pubDate.InnerText);
                                }
                            }
                            catch (Exception ex)
                            {
                                NotifySubscribers(ex, ex.Message, RssSeverityType.Warning);
                            }

                            ////add to list, it will sort by the date
                            try
                            {
                                string key = String.Format(
                                    System.Globalization.CultureInfo.InvariantCulture,
                                    "{0}_{1}",
                                    date.ToString("u", System.Globalization.CultureInfo.InvariantCulture),
                                    node.ChildNodes[0].InnerText);
                                nodesList.Add(key, node);
                            }
                            catch (ArgumentException argumentException)
                            {
                                NotifySubscribers(argumentException, argumentException.Message, RssSeverityType.Warning);
                            }
                        }

                        foreach (string key in nodesList.Keys)
                        {
                            channelNode.AppendChild(xmlDocument.ImportNode(nodesList[key], true));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                NotifySubscribers(ex, ex.Message, RssSeverityType.Error);
            }

            _rssXml = xmlDocument.OuterXml;
        }
Example #13
0
        /// <summary>
        /// string XML representation.
        /// </summary>
        /// <returns>string</returns>
        protected static string ToXml <T>(DocumentType outputType, T rssDocument) where T : RssDocumentBase
        {
            string rssXml = RssXmlHelper.ToRssXml <T>(rssDocument);

            return(RssXmlHelper.ConvertRssTo(outputType, rssXml));
        }