Ejemplo n.º 1
0
        private void miSubscribe_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem    item    = (ToolStripMenuItem)sender;
            FoeClientCatalogItem catItem = (FoeClientCatalogItem)item.Tag;

            // Reverse the check (i.e. change to checked if currently not checked, and vice versa.)
            item.Checked = !item.Checked;

            try
            {
                // Record change to DB
                FoeClientCatalog.SetSubscription(catItem.Code, item.Checked);

                // Update subscription
                SendSubscriptionRequest();

                // Redisplay feed
                DisplayFeeds();
            }
            catch (Exception)
            {
                MessageBox.Show("Error loading catalog. Data file probably corrupted, please reinstall Foe. Program will now close.");
                Close();
            }
        }
Ejemplo n.º 2
0
        private void DisplayFeeds()
        {
            try
            {
                wbFeedDisplay.DocumentText = "";

                string html =
                    "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"></head>" +
                    "<body bgcolor=\"#ffffff\" style=\"font-family:Verdana,Arial;font-size:10px;margin:0px;\">\n";

                List <FoeClientCatalogItem> catalog = FoeClientCatalog.GetAll();
                foreach (FoeClientCatalogItem item in catalog)
                {
                    if (item.IsSubscribed)
                    {
                        // Add a header
                        html += "<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" width=\"100%\" style=\"font-family:Verdana,Arial;font-size:13px;\">\n" +
                                "<tr><td bgcolor=\"#CCCCFF\"><b>" + item.Name + "</b></td></tr>\n";

                        // Check if feed file is available
                        try
                        {
                            TextReader reader = new StreamReader("rss\\" + item.Code + ".rss");
                            string     feed   = reader.ReadToEnd();

                            // Parse RSS
                            XmlDocument doc = new XmlDocument();
                            doc.LoadXml(feed);
                            XmlNodeList news   = doc.GetElementsByTagName("item");
                            bool        isGray = false;
                            foreach (XmlNode newsItem in news)
                            {
                                html += "<tr><td bgcolor=\"" + (isGray ? "#F7F7F7" : "#FFFFFF") + "\">";
                                html += "<a target=\"foe\" href=\"" + newsItem["link"].InnerText + "\" style=\"color:#0000ff;text-decoration:none;\">" + newsItem["title"].InnerText + "</a><br>\n";
                                //html += "<a href=\"#\" onclick=\"window.external.LoadPage('" + newsItem["link"].InnerText + "')\" style=\"color:#0000ff;text-decoration:none;\">" + newsItem["title"].InnerText + "</a><br>\n";
                                html  += "</td></tr>\n";
                                isGray = !isGray;
                            }
                        }
                        catch (Exception)
                        {
                            // RSS file doesn't exist.
                            // Can't do much, probably feed hasn't arrived yet.
                        }

                        html += "</table><br />&nbsp;<br />\n";
                    }
                }

                html += "</body></html>";

                wbFeedDisplay.Document.OpenNew(true);
                wbFeedDisplay.DocumentText = html;
            }
            catch (Exception)
            {
                tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " error displaying feeds.";
            }
        }
Ejemplo n.º 3
0
        private void CheckUpdate()
        {
            Trace.WriteLine("Entered CheckUpdate().");
            LoadCatalog();
            try
            {
                bool hasUpdate = false;
                Trace.WriteLine("  Downloading messages.");
                FoeClientMessage.DownloadMessages();
                Trace.WriteLine("  Downloaded messages.");

                // Check if there is any update that's newer than what are currently displayed
                List <FoeClientCatalogItem> catalog = FoeClientCatalog.GetAll();
                foreach (FoeClientCatalogItem item in catalog)
                {
                    Trace.WriteLine("  Checking updated news.");
                    Trace.WriteLine("  " + item.Code + " updated at " + item.DtLastUpdated.ToString("yyyy-MM-dd HH:mm:ss"));
                    Trace.WriteLine("  _lastUpdated = " + _lastUpdated.ToString("yyyy-MM-dd HH:mm:ss"));

                    if (item.DtLastUpdated > _lastUpdated)
                    {
                        Trace.WriteLine("  Updated news is available.");

                        // Set timer to normal interval
                        timerCheckUpdate.Interval = _checkInterval;

                        // Redisplay feed
                        DisplayFeeds();
                        Trace.WriteLine("  Displayed feed.");

                        // record keeping
                        hasUpdate      = true;
                        tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " updated feeds.";
                        _lastUpdated   = DateTime.Now;
                        Trace.WriteLine("  Updated _lastUpdated.");

                        break;
                    }
                }

                if (!hasUpdate)
                {
                    tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " no new feeds.";
                    Trace.WriteLine("  No update available.");
                }
            }
            catch (Exception except)
            {
                tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " error .";
                Trace.WriteLine("  Error occured:\r\n" + except.ToString());
            }

            Trace.WriteLine("Exiting CheckUpdate().");
        }
Ejemplo n.º 4
0
        private void SendSubscriptionRequest()
        {
            try
            {
                // Delete all previous content requests
                FoeClientRequest.DeleteOldRequest(_requestInterval);

                // Create Foe Message
                string catalogs = "";
                List <FoeClientCatalogItem> catalog = FoeClientCatalog.GetAll();
                if (catalog.Count == 0)
                {
                    return;
                }
                foreach (FoeClientCatalogItem item in catalog)
                {
                    if (item.IsSubscribed)
                    {
                        catalogs += item.Code + ",";
                    }
                }
                string requestId = FoeClientRequest.GenerateId();

                FoeClientMessage.SendMessage(
                    FoeClientMessage.GetSmtpServer(),
                    FoeClientRegistry.GetEntry("useremail").Value,
                    FoeClientRegistry.GetEntry("processoremail").Value,
                    SubjectGenerator.RequestSubject(RequestType.Content, requestId, FoeClientRegistry.GetEntry("userid").Value),
                    catalogs);

                // save requestid to DB
                FoeClientRequestItem reqItem = new FoeClientRequestItem();
                reqItem.Id          = requestId;
                reqItem.Type        = "content";
                reqItem.DtRequested = DateTime.Now;
                FoeClientRequest.Add(reqItem);

                // remember when the request was sent
                _lastRequestSent = DateTime.Now;
                // Set status
                tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " requested update.";
            }
            catch (Exception)
            {
                tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " error sending request.";
            }
        }
Ejemplo n.º 5
0
        private void CheckUpdate()
        {
            try
            {
                bool hasUpdate = false;
                FoeClientMessage.DownloadMessages();

                // Check if there is any update that's newer than what are currently displayed
                List <FoeClientCatalogItem> catalog = FoeClientCatalog.GetAll();
                foreach (FoeClientCatalogItem item in catalog)
                {
                    if (item.DtLastUpdated > _lastUpdated)
                    {
                        // Set timer to normal interval
                        timerCheckUpdate.Interval = _checkInterval;

                        // Redisplay feed
                        DisplayFeeds();

                        // record keeping
                        hasUpdate      = true;
                        tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " updated feeds.";
                        _lastUpdated   = DateTime.Now;

                        break;
                    }
                }

                if (!hasUpdate)
                {
                    tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " no new feeds.";
                }
            }
            catch (Exception)
            {
                tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " error .";
            }
        }
Ejemplo n.º 6
0
        private void LoadCatalog()
        {
            try
            {
                // Clear existing catalog in menu
                miSubscribe.DropDownItems.Clear();

                // Load catalog from DB
                List <FoeClientCatalogItem> catalog = FoeClientCatalog.GetAll();
                foreach (FoeClientCatalogItem item in catalog)
                {
                    ToolStripMenuItem newMenu = new ToolStripMenuItem(item.Code);
                    newMenu.Tag     = item;
                    newMenu.Click  += miSubscribe_Click;
                    newMenu.Checked = item.IsSubscribed;
                    miSubscribe.DropDownItems.Add(newMenu);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error loading catalog. Data file probably corrupted, please reinstall Foe. Program will now close.");
                Close();
            }
        }
Ejemplo n.º 7
0
        private void DisplayFeeds()
        {
            //string rssURL = "http://www.ckxx.info/rss/rss.xml";

            //WebClient client = new WebClient();
            ////XmlTextReader client = new XmlTextReader(rssURL);
            //byte[] feedBytes = client.DownloadData(rssURL);
            //// Change feed to base64
            //string feed64 = Convert.ToBase64String(feedBytes);
            //string feed = Encoding.UTF8.GetString(feedBytes);
            //XmlDocument feedRss = new XmlDocument();
            //feedRss.Load(rssURL);
            try
            {
                wbFeedDisplay.DocumentText = "";

                string html =
                    "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"></head>" +
                    "<body bgcolor=\"#ffffff\" style=\"font-family:Verdana,Arial;font-size:10px;margin:0px;\">\n";

                List <FoeClientCatalogItem> catalog = FoeClientCatalog.GetAll();
                foreach (FoeClientCatalogItem item in catalog)
                {
                    if (item.IsSubscribed)
                    {
                        // Add a header
                        html += "<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" width=\"100%\" style=\"font-family:Verdana,Arial;font-size:13px;\">\n" +
                                "<tr><td bgcolor=\"#CCCCFF\"><b>" + item.Code + "</b></td></tr>\n";

                        // Check if feed file is available
                        try
                        {
                            // Parse RSS

                            XmlTextReader rssReader = new XmlTextReader(@"rss\\" + item.Code + ".rss");
                            XmlDocument   rssDoc    = new XmlDocument();
                            // Load the XML content into a XmlDocument
                            rssDoc.Load(rssReader);

                            XmlNodeList news   = rssDoc.GetElementsByTagName("item");
                            bool        isGray = false;
                            foreach (XmlNode newsItem in news)
                            {
                                html += "<tr><td bgcolor=\"" + (isGray ? "#F7F7F7" : "#FFFFFF") + "\">";
                                html += "<a target=\"foe\" href=\"" + newsItem["link"].InnerText + "\" style=\"color:#0000ff;text-decoration:none;\">" + newsItem["title"].InnerText + "</a><br>\n";
                                //html += "<a href=\"#\" onclick=\"window.external.LoadPage('" + newsItem["link"].InnerText + "')\" style=\"color:#0000ff;text-decoration:none;\">" + newsItem["title"].InnerText + "</a><br>\n";
                                html  += "</td></tr>\n";
                                isGray = !isGray;
                            }
                        }
                        catch (Exception)
                        {
                            // RSS file doesn't exist.
                            // Can't do much, probably feed hasn't arrived yet.
                        }

                        html += "</table><br />&nbsp;<br />\n";
                    }
                }

                html += "</body></html>";

                wbFeedDisplay.Document.OpenNew(true);
                wbFeedDisplay.DocumentText = html;
            }
            catch (Exception)
            {
                tssStatus.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " error displaying feeds.";
            }
        }