Example #1
0
        public async Task LoadFeed()
        {
            XmlTextReader xmlReader;
            WebClient     wc = new WebClient();

            System.IO.Stream stream = null;
            if (Properties.Settings.Default.ProxySwitch)
            {
                WebProxy wp        = new WebProxy(Properties.Settings.Default.ProxyURL, Properties.Settings.Default.ProxyPort);
                byte[]   barr_pass = Convert.FromBase64String(Properties.Settings.Default.ProxyPass);
                string   pass      = Encoding.UTF8.GetString(barr_pass);
                wp.Credentials = new NetworkCredential(Properties.Settings.Default.ProxyName, pass);
                wc.Proxy       = wp;
                pass           = null;
            }

            stream = await wc.OpenReadTaskAsync(URL);

            if (stream == null)
            {
                return;
            }

            xmlReader = new XmlTextReader(stream);

            XmlDocument xmlDocument = new XmlDocument();

            Items = new ItemsRSS();
            try
            {
                xmlDocument.Load(xmlReader);
                xmlReader.Close();
                XmlNode channelXmlNode = xmlDocument.GetElementsByTagName("channel")[0];
                // LastPubDate = xmlDocument.GetElementsByTagName("pubDate")[0].InnerText;
                if (channelXmlNode != null)
                {
                    bool firstElement = true;
                    foreach (XmlNode channelNode in channelXmlNode.ChildNodes)
                    {
                        switch (channelNode.Name)
                        {
                        case "title":
                            Title = channelNode.InnerText;
                            break;

                        case "description":
                            Description = channelNode.InnerText;
                            break;

                        case "link":
                            Link = channelNode.InnerText;
                            break;

                        case "item":

                            ItemRSS chanItem = new ItemRSS(channelNode);
                            if (firstElement)
                            {
                                LastPubDate  = chanItem.PubDate;
                                firstElement = false;
                            }
                            Items.Add(chanItem);
                            break;
                        }
                    }
                    Loaded?.Invoke(this, new EventArgs());
                }
                else
                {
                    throw new Exception("RSS not found");
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #2
0
        public async Task UpdateFeed()
        {
            System.IO.Stream stream = null;
            XmlTextReader    xmlReader;

            WebClient wc = new WebClient();

            if (Properties.Settings.Default.ProxySwitch)
            {
                WebProxy wp        = new WebProxy(Properties.Settings.Default.ProxyURL, Properties.Settings.Default.ProxyPort);
                byte[]   barr_pass = Convert.FromBase64String(Properties.Settings.Default.ProxyPass);
                string   pass      = Encoding.UTF8.GetString(barr_pass);
                wp.Credentials = new NetworkCredential(Properties.Settings.Default.ProxyName, pass);
                wc.Proxy       = wp;
                pass           = null;
            }

            stream = await wc.OpenReadTaskAsync(URL);

            if (stream == null)
            {
                return;
            }
            xmlReader = new XmlTextReader(stream);

            XmlDocument xmlDocument = new XmlDocument();

            try
            {
                xmlDocument.Load(xmlReader);
                xmlReader.Close();
                XmlNode channelXmlNode = xmlDocument.GetElementsByTagName("channel")[0];


                if (channelXmlNode != null)
                {
                    bool firstElement = true;
                    foreach (XmlNode channelNode in channelXmlNode.ChildNodes)
                    {
                        switch (channelNode.Name)
                        {
                        case "item":
                            ItemRSS chanItem = new ItemRSS(channelNode);

                            if (firstElement)
                            {
                                //    Console.WriteLine("FIRST ELEMENT");
                                if (chanItem.PubDate.Equals(LastPubDate))
                                {
                                    //        Console.WriteLine("NO UPDATES");
                                    return;
                                }
                                else
                                {
                                    Items = new ItemsRSS();
                                    Items.Add(chanItem);
                                    LastPubDate = chanItem.PubDate;
                                }
                                firstElement = false;
                            }
                            else
                            {
                                //    Console.WriteLine("NEXT ELEMENT");
                                Items.Add(chanItem);
                            }
                            break;
                        }
                    }
                    Update?.Invoke(this, new EventArgs());
                }
                else
                {
                    throw new Exception("RSS not found");
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }