Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            foreach (var rssUrl in rssUrls)
            {
                // analyze
                var content = await _httpClient.GetStringAsync(rssUrl);

                Rss newRss = null;
                try
                {
                    newRss = XmlConvertExtension.DeserializeObject <Rss>(content);
                }
                catch
                {
                    Console.WriteLine($"{rssUrl} RSS订阅发生异常,请查看RSS源是否能正常访问!");
                }
                // find exsited rss
                var existRss = await FindRssAsync(Path.Combine(root, "edi.wang.xml"));

                // compare rss
                if (newRss.Channel.Items.Count == existRss.Channel.Items.Count)
                {
                    Console.WriteLine($"{rssUrl} 暂无更新!");
                }
                else
                {
                    Console.WriteLine($"请注意! {rssUrl} 有更新:" + newRss.Channel.Items[0].Title + " 发布时间:" + newRss.Channel.Items[0].PubDateString);
                }
            }
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static async Task <Rss> FindRssAsync(string url)
        {
            using var fileStream = new FileStream(url, FileMode.Open);
            var buffer = new byte[fileStream.Length];
            await fileStream.ReadAsync(buffer, 0, buffer.Length);

            var xml = Encoding.UTF8.GetString(buffer);

            // deserialize
            return(XmlConvertExtension.DeserializeObject <Rss>(xml));
        }