Esempio n. 1
0
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            // Ditch the worker
            if (_feedReadWorker != null)
            {
                _feedReadWorker.CancelAsync();
                _feedReadWorker.Dispose();
            }

            // Get rid of the timer
            TerminateTimer();

            // Save current window settings
            SaveWindowSettings();

            // Save settings
            Settings.Default.Save();

            // Save options
            _database.SaveChanges();

            // Get rid of the notification icon
            NotificationIcon.Dispose();
        }
Esempio n. 2
0
        public void Initialize()
        {
            // Setup the update handler
            InitializeUpdate();

            // Show the notification icon
            NotificationIcon.Initialize(this);

            // Load window settings
            LoadWindowSettings();

            // Set the foreground color to something that can be seen
            LinkTextList.Foreground = (System.Drawing.SystemColors.Desktop.GetBrightness() < 0.5) ? Brushes.White : Brushes.Black;
            HeaderLabel.Foreground  = LinkTextList.Foreground;

            // Create the background worker that does the actual reading
            _feedReadWorker = new BackgroundWorker {
                WorkerReportsProgress = true, WorkerSupportsCancellation = true
            };
            _feedReadWorker.DoWork             += HandleFeedReadWorkerStart;
            _feedReadWorker.ProgressChanged    += HandleFeedReadWorkerProgressChanged;
            _feedReadWorker.RunWorkerCompleted += HandleFeedReadWorkerCompleted;

            // Setup the database
            _database = new FeedCenterEntities();

            // Initialize the command line listener
            _commandLineListener = new InterprocessMessageListener(Properties.Resources.ApplicationName);
            _commandLineListener.MessageReceived += HandleCommandLine;

            // Handle any command line we were started with
            HandleCommandLine(null, new InterprocessMessageListener.InterprocessMessageEventArgs(Environment.CommandLine));

            // Create a timer to keep track of things we need to do
            InitializeTimer();

            // Initialize the feed display
            InitializeDisplay();

            // Check for update
            if (Settings.Default.CheckVersionAtStartup)
            {
                UpdateCheck.CheckForUpdate();
            }

            // Show the link if updates are available
            if (UpdateCheck.UpdateAvailable)
            {
                NewVersionLink.Visibility = Visibility.Visible;
            }

            Tracer.WriteLine("MainForm creation finished");
        }
Esempio n. 3
0
        private void HandleNewFeed(string feedUrl)
        {
            // Create and configure the new feed
            var feed = Feed.Create(_database);

            feed.Source   = feedUrl;
            feed.Category = _database.DefaultCategory;

            // Try to detect the feed type
            var feedTypeResult = feed.DetectFeedType();

            // If we can't figure it out it could be an HTML page
            if (feedTypeResult.Item1 == FeedType.Unknown)
            {
                // Only check if the feed was able to be read - otherwise fall through and show the dialog
                if (feedTypeResult.Item2.Length > 0)
                {
                    // Create and load an HTML document with the text
                    var htmlDocument = new HtmlAgilityPack.HtmlDocument();
                    htmlDocument.LoadHtml(feedTypeResult.Item2);

                    // Look for all RSS or atom links in the document
                    var rssLinks = htmlDocument.DocumentNode.Descendants("link")
                                   .Where(n => n.Attributes["type"] != null && (n.Attributes["type"].Value == "application/rss+xml" || n.Attributes["type"].Value == "application/atom+xml"))
                                   .Select(n => new Tuple <string, string>(UrlHelper.GetAbsoluteUrlString(feed.Source, n.Attributes["href"].Value), WebUtility.HtmlDecode(n.Attributes["title"]?.Value ?? feedUrl)))
                                   .Distinct()
                                   .ToList();

                    // If there was only one link found then switch to feed to it
                    if (rssLinks.Count == 1)
                    {
                        feed.Source = rssLinks[0].Item1;
                    }
                    else
                    {
                        var feedChooserWindow = new FeedChooserWindow();
                        var feedLink          = feedChooserWindow.Display(this, rssLinks);

                        if (string.IsNullOrEmpty(feedLink))
                        {
                            return;
                        }

                        feed.Source = feedLink;
                    }
                }
            }

            // Read the feed for the first time
            var feedReadResult = feed.Read(_database);

            // See if we read the feed okay
            if (feedReadResult == FeedReadResult.Success)
            {
                // Update the feed name to be the title
                feed.Name = feed.Title;

                // Add the feed to the feed table
                _database.Feeds.Add(feed);

                // Save the changes
                _database.SaveChanges();

                // Show a tip
                NotificationIcon.ShowBalloonTip(string.Format(Properties.Resources.FeedAddedNotification, feed.Name), System.Windows.Forms.ToolTipIcon.Info);

                // Re-initialize the feed display
                DisplayFeed();
            }
            else
            {
                // Feed read failed - ceate a new feed window
                var feedForm = new FeedWindow();

                var dialogResult = feedForm.Display(_database, feed, this);

                // Display the new feed form
                if (dialogResult.HasValue && dialogResult.Value)
                {
                    // Add the feed to the feed table
                    _database.Feeds.Add(feed);

                    // Save the changes
                    _database.SaveChanges();

                    // Re-initialize the feed display
                    DisplayFeed();
                }
            }
        }