Esempio n. 1
0
        public FeedReadResult Read(FeedCenterEntities database, bool forceRead = false)
        {
            Tracer.WriteLine("Reading feed: {0}", Source);
            Tracer.IncrementIndentLevel();

            var result = ReadFeed(database, forceRead);

            // Handle the result
            switch (result)
            {
            case FeedReadResult.NotDue:
            case FeedReadResult.NotEnabled:
            case FeedReadResult.NotModified:

                // Ignore
                break;

            default:
                // Save as last result
                LastReadResult = result;

                break;
            }

            // If the feed was successfully read and we have no last update timestamp - set the last update timestamp to now
            if (result == FeedReadResult.Success && LastUpdated == Extensions.SqlDateTimeZero.Value)
            {
                LastUpdated = DateTime.Now;
            }

            Tracer.DecrementIndentLevel();
            Tracer.WriteLine("Done reading feed: {0}", result);

            return(result);
        }
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
        public bool?Display(Window owner)
        {
            _database = new FeedCenterEntities();

            // Create a view and sort it by name
            _collectionViewSource = new CollectionViewSource {
                Source = _database.AllFeeds
            };
            _collectionViewSource.Filter += HandleCollectionViewSourceFilter;
            _collectionViewSource.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

            // Bind to the list
            FeedDataGrid.ItemsSource   = _collectionViewSource.View;
            FeedDataGrid.SelectedIndex = 0;

            // Set the window owner
            Owner = owner;

            // Show the dialog and result the result
            return(ShowDialog());
        }
Esempio n. 4
0
        private void ResetDatabase()
        {
            // Get the ID of the current feed
            var currentId = _currentFeed?.ID ?? Guid.Empty;

            // Create a new database object
            _database = new FeedCenterEntities();

            _feedList = _currentCategory == null ? _database.Feeds : _database.Feeds.Where(feed => feed.Category.ID == _currentCategory.ID);

            UpdateToolbarButtonState();

            // Get a list of feeds ordered by name
            var feedList = _feedList.OrderBy(f => f.Name).ToList();

            // First try to find the current feed by ID to see if it is still there
            var newIndex = feedList.FindIndex(f => f.ID == currentId);

            if (newIndex == -1)
            {
                // The current feed isn't there anymore so see if we can find a feed at the old index
                if (feedList.ElementAtOrDefault(_feedIndex) != null)
                {
                    newIndex = _feedIndex;
                }

                // If there is no feed at the old location then give up and go back to the start
                if (newIndex == -1 && feedList.Count > 0)
                {
                    newIndex = 0;
                }
            }

            // Set the current index to the new index
            _feedIndex = newIndex;

            // Re-get the current feed
            _currentFeed = (_feedIndex == -1 ? null : _feedList.OrderBy(feed => feed.Name).AsEnumerable().ElementAt(_feedIndex));
        }
Esempio n. 5
0
 public static Feed Create(FeedCenterEntities database)
 {
     return(new Feed {
         ID = Guid.NewGuid(), CategoryID = database.DefaultCategory.ID
     });
 }
Esempio n. 6
0
        private FeedReadResult ReadFeed(FeedCenterEntities database, bool forceRead)
        {
            try
            {
                // If not enabled then do nothing
                if (!Enabled)
                {
                    return(FeedReadResult.NotEnabled);
                }

                // Check if we're forcing a read
                if (!forceRead)
                {
                    // Figure out how long since we last checked
                    var timeSpan = DateTime.Now - LastChecked;

                    // Check if we are due to read the feed
                    if (timeSpan.TotalMinutes < CheckInterval)
                    {
                        return(FeedReadResult.NotDue);
                    }
                }

                // We're checking it now so update the time
                LastChecked = DateTime.Now;

                // Read the feed text
                var retrieveResult = RetrieveFeed();

                // Get the information out of the async result
                var result   = retrieveResult.Item1;
                var feedText = retrieveResult.Item2;

                // If we didn't successfully retrieve the feed then stop
                if (result != FeedReadResult.Success)
                {
                    return(result);
                }

                // Create a new RSS parser
                var feedParser = FeedParserBase.CreateFeedParser(this, feedText);

                // Parse the feed
                result = feedParser.ParseFeed(feedText);

                // If we didn't successfully parse the feed then stop
                if (result != FeedReadResult.Success)
                {
                    return(result);
                }

                // Create the removed items list - if an item wasn't seen during this check then remove it
                var removedItems = Items.Where(testItem => testItem.LastFound != LastChecked).ToList();

                // If items were removed the feed was updated
                if (removedItems.Count > 0)
                {
                    LastUpdated = DateTime.Now;
                }

                // Loop over the items to be removed
                foreach (var itemToRemove in removedItems)
                {
                    // Delete the item from the database
                    database.FeedItems.Remove(itemToRemove);

                    // Remove the item from the list
                    Items.Remove(itemToRemove);
                }

                // Process actions on this feed
                ProcessActions();

                return(FeedReadResult.Success);
            }
            catch (InvalidFeedFormatException exception)
            {
                Tracer.WriteException(exception.InnerException);

                return(FeedReadResult.InvalidXml);
            }
            catch (Exception exception)
            {
                Tracer.WriteLine(exception.Message);

                return(FeedReadResult.UnknownError);
            }
        }
Esempio n. 7
0
 public async Task <FeedReadResult> ReadAsync(FeedCenterEntities database, bool forceRead = false)
 {
     return(await Task.Run(() => Read(database, forceRead)));
 }
Esempio n. 8
0
        public static object OpenDataStore()
        {
            var entities = new FeedCenterEntities();

            return(entities.Database.Exists() ? entities : null);
        }
Esempio n. 9
0
        private static void HandleFeedReadWorkerStart(object sender, DoWorkEventArgs e)
        {
            // Create a new database instance for just this thread
            var database = new FeedCenterEntities();

            // Get the worker
            var worker = (BackgroundWorker)sender;

            // Get the input information
            var workerInput = (FeedReadWorkerInput)e.Argument;

            // Setup for progress
            var currentProgress = 0;

            // Create the list of feeds to read
            var feedsToRead = new List <Feed>();

            // If we have a single feed then add it to the list - otherwise add them all
            if (workerInput.Feed != null)
            {
                feedsToRead.Add(database.Feeds.First(feed => feed.ID == workerInput.Feed.ID));
            }
            else
            {
                feedsToRead.AddRange(database.Feeds);
            }

            // Loop over each feed and read it
            foreach (var feed in feedsToRead)
            {
                // Read the feed
                feed.Read(database, workerInput.ForceRead);

                // Increment progress
                currentProgress += 1;

                // Report progress
                worker.ReportProgress(currentProgress);
            }

            // Save the changes
            database.SaveChanges();

            // Increment progress
            currentProgress += 1;

            // Report progress
            worker.ReportProgress(currentProgress);

            // See if we're due for a version check
            if (DateTime.Now - Settings.Default.LastVersionCheck >= Settings.Default.VersionCheckInterval)
            {
                // Get the update information
                UpdateCheck.CheckForUpdate();

                // Update the last check time
                Settings.Default.LastVersionCheck = DateTime.Now;
            }

            // Increment progress
            currentProgress += 1;

            // Report progress
            worker.ReportProgress(currentProgress);

            // Sleep for a little bit so the user can see the update
            Thread.Sleep(Settings.Default.ProgressSleepInterval * 3);
        }