Start modernization

This commit is contained in:
2023-03-10 12:18:03 -05:00
parent a0214b98f1
commit f480a6c373
57 changed files with 661 additions and 2921 deletions

View File

@@ -6,7 +6,7 @@ using FeedCenter.Properties;
namespace FeedCenter
{
public partial class MainWindow
public partial class MainWindow : IDisposable
{
private void DisplayCategory()
{
@@ -44,7 +44,7 @@ namespace FeedCenter
Tag = category,
// Set the current item to bold
FontWeight = category.ID == _currentCategory?.ID ? FontWeights.Bold : FontWeights.Normal
FontWeight = category.Id == _currentCategory?.Id ? FontWeights.Bold : FontWeights.Normal
};
// Handle the click
@@ -70,7 +70,7 @@ namespace FeedCenter
var category = (Category) menuItem.Tag;
// If the category changed then reset the current feed to the first in the category
if (_currentCategory?.ID != category?.ID)
if (_currentCategory?.Id != category?.Id)
{
_currentFeed = category == null ? _database.Feeds.FirstOrDefault() : category.Feeds.FirstOrDefault();
}
@@ -79,9 +79,9 @@ namespace FeedCenter
_currentCategory = category;
// Get the current feed list to match the category
_feedList = _currentCategory == null ? _database.Feeds : _database.Feeds.Where(feed => feed.Category.ID == _currentCategory.ID);
_feedList = _currentCategory == null ? _database.Feeds : _database.Feeds.Where(feed => feed.Category.Id == _currentCategory.Id);
// Reset the feed index
// Refresh the feed index
_feedIndex = -1;
// Get the first feed
@@ -94,7 +94,14 @@ namespace FeedCenter
DisplayCategory();
DisplayFeed();
Settings.Default.LastCategoryID = _currentCategory?.ID.ToString() ?? string.Empty;
Settings.Default.LastCategoryID = _currentCategory?.Id.ToString() ?? string.Empty;
}
public void Dispose()
{
_mainTimer?.Dispose();
_feedReadWorker?.Dispose();
_commandLineListener?.Dispose();
}
}
}

View File

@@ -35,13 +35,16 @@ namespace FeedCenter
// Get the data as a string
var data = (string) e.Data.GetData(DataFormats.Text);
if (string.IsNullOrEmpty(data))
return;
// Check to see if the data starts with any known Chrome extension
var chromeExtension = _chromeExtensions.FirstOrDefault(c => data.StartsWith(c));
var chromeExtension = _chromeExtensions.FirstOrDefault(data.StartsWith);
// Remove the Chrome extension URL and decode the URL
if (chromeExtension != null)
{
data = data.Substring(chromeExtension.Length);
data = data[chromeExtension.Length..];
data = WebUtility.UrlDecode(data);
}

View File

@@ -64,10 +64,7 @@ namespace FeedCenter
feed.Name = feed.Title;
// Add the feed to the feed table
_database.Feeds.Add(feed);
// Save the changes
_database.SaveChanges();
_database.SaveChanges(() => _database.Feeds.Add(feed));
// Show a tip
NotificationIcon.ShowBalloonTip(string.Format(Properties.Resources.FeedAddedNotification, feed.Name), System.Windows.Forms.ToolTipIcon.Info);
@@ -77,7 +74,7 @@ namespace FeedCenter
}
else
{
// Feed read failed - ceate a new feed window
// Feed read failed - create a new feed window
var feedForm = new FeedWindow();
var dialogResult = feedForm.Display(_database, feed, this);
@@ -86,10 +83,7 @@ namespace FeedCenter
if (dialogResult.HasValue && dialogResult.Value)
{
// Add the feed to the feed table
_database.Feeds.Add(feed);
// Save the changes
_database.SaveChanges();
_database.SaveChanges(() => _database.Feeds.Add(feed));
// Re-initialize the feed display
DisplayFeed();

View File

@@ -34,15 +34,14 @@ namespace FeedCenter
var feedItem = (FeedItem) ((ListBoxItem) sender).DataContext;
// The feed item has been read and is no longer new
feedItem.BeenRead = true;
feedItem.New = false;
_database.SaveChanges(() =>
{
feedItem.BeenRead = true;
feedItem.New = false;
});
// Remove the item from the list
LinkTextList.Items.Remove(feedItem);
// Save the changes
_database.SaveChanges();
}
private void HandleItemMouseDoubleClick(object sender, MouseButtonEventArgs e)
@@ -54,14 +53,14 @@ namespace FeedCenter
if (BrowserCommon.OpenLink(feedItem.Link))
{
// The feed item has been read and is no longer new
feedItem.BeenRead = true;
feedItem.New = false;
_database.SaveChanges(() =>
{
feedItem.BeenRead = true;
feedItem.New = false;
});
// Remove the item from the list
LinkTextList.Items.Remove(feedItem);
// Save the changes
_database.SaveChanges();
}
}
@@ -83,10 +82,9 @@ namespace FeedCenter
Tag = feed,
// Set the current item to bold
FontWeight = feed == _currentFeed ? FontWeights.Bold : FontWeights.Normal
FontWeight = feed.Id == _currentFeed.Id ? FontWeights.Bold : FontWeights.Normal
};
// Handle the click
menuItem.Click += HandleFeedMenuItemClick;
@@ -113,7 +111,7 @@ namespace FeedCenter
var feedIndex = 0;
foreach (var loopFeed in _feedList.OrderBy(loopFeed => loopFeed.Name))
{
if (loopFeed == feed)
if (loopFeed.Id == feed.Id)
{
_feedIndex = feedIndex;
break;

View File

@@ -21,7 +21,7 @@ namespace FeedCenter
private void SetProgressMode(bool value, int feedCount)
{
// Reset the progress bar if we need it
// Refresh the progress bar if we need it
if (value)
{
FeedReadProgress.Value = 0;
@@ -65,7 +65,7 @@ namespace FeedCenter
return;
// Switch to progress mode
SetProgressMode(true, _database.Feeds.Count());
SetProgressMode(true, _database.Feeds.Count);
// Create the input class
var workerInput = new FeedReadWorkerInput { ForceRead = forceRead, Feed = null };
@@ -82,7 +82,7 @@ namespace FeedCenter
private void HandleFeedReadWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// Reset the database to current settings
// Refresh the database to current settings
ResetDatabase();
// Save settings
@@ -123,10 +123,10 @@ namespace FeedCenter
var database = new FeedCenterEntities();
// Get the worker
var worker = (BackgroundWorker) sender;
var worker = (BackgroundWorker)sender;
// Get the input information
var workerInput = (FeedReadWorkerInput) e.Argument;
var workerInput = (FeedReadWorkerInput)e.Argument ?? new FeedReadWorkerInput { Feed = null, ForceRead = false };
// Setup for progress
var currentProgress = 0;
@@ -136,7 +136,7 @@ namespace FeedCenter
// 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));
feedsToRead.Add(database.Feeds.First(feed => feed.Id == workerInput.Feed.Id));
else
feedsToRead.AddRange(database.Feeds);
@@ -144,7 +144,7 @@ namespace FeedCenter
foreach (var feed in feedsToRead)
{
// Read the feed
feed.Read(database, workerInput.ForceRead);
database.SaveChanges(() => feed.Read(database, workerInput.ForceRead));
// Increment progress
currentProgress += 1;
@@ -153,9 +153,6 @@ namespace FeedCenter
worker.ReportProgress(currentProgress);
}
// Save the changes
database.SaveChanges();
// Increment progress
currentProgress += 1;
@@ -166,7 +163,7 @@ namespace FeedCenter
if (DateTime.Now - Settings.Default.LastVersionCheck >= Settings.Default.VersionCheckInterval)
{
// Get the update information
UpdateCheck.CheckForUpdate();
UpdateCheck.CheckForUpdate().Wait();
// Update the last check time
Settings.Default.LastVersionCheck = DateTime.Now;

View File

@@ -2,8 +2,10 @@
using Common.Helpers;
using Common.IO;
using Common.Update;
using FeedCenter.Data;
using FeedCenter.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
@@ -18,7 +20,7 @@ namespace FeedCenter
private int _feedIndex;
private Category _currentCategory;
private IQueryable<Feed> _feedList;
private IEnumerable<Feed> _feedList;
private Feed _currentFeed;
public MainWindow()
@@ -26,7 +28,7 @@ namespace FeedCenter
InitializeComponent();
}
public void Initialize()
public async void Initialize()
{
// Setup the update handler
InitializeUpdate();
@@ -48,7 +50,7 @@ namespace FeedCenter
_feedReadWorker.RunWorkerCompleted += HandleFeedReadWorkerCompleted;
// Setup the database
_database = new FeedCenterEntities();
_database = Database.Entities;
// Initialize the command line listener
_commandLineListener = new InterprocessMessageListener(Properties.Resources.ApplicationName);
@@ -65,7 +67,7 @@ namespace FeedCenter
// Check for update
if (Settings.Default.CheckVersionAtStartup)
UpdateCheck.CheckForUpdate();
await UpdateCheck.CheckForUpdate();
// Show the link if updates are available
if (UpdateCheck.UpdateAvailable)
@@ -136,18 +138,18 @@ namespace FeedCenter
private void InitializeDisplay()
{
// Get the last category (defaulting to none)
_currentCategory = _database.Categories.FirstOrDefault(category => category.ID.ToString() == Settings.Default.LastCategoryID);
_currentCategory = _database.Categories.FirstOrDefault(category => category.Id.ToString() == Settings.Default.LastCategoryID);
DisplayCategory();
// Get the current feed list to match the category
_feedList = _currentCategory == null ? _database.Feeds : _database.Feeds.Where(feed => feed.Category.ID == _currentCategory.ID);
_feedList = _currentCategory == null ? _database.Feeds : _database.Feeds.Where(feed => feed.Category.Id == _currentCategory.Id);
UpdateToolbarButtonState();
// Clear the link list
LinkTextList.Items.Clear();
// Reset the feed index
// Refresh the feed index
_feedIndex = -1;
// Start the timer
@@ -341,11 +343,11 @@ namespace FeedCenter
private void MarkAllItemsAsRead()
{
// Loop over all items and mark them as read
foreach (FeedItem feedItem in LinkTextList.Items)
feedItem.BeenRead = true;
// Save the changes
_database.SaveChanges();
_database.SaveChanges(() =>
{
foreach (FeedItem feedItem in LinkTextList.Items)
feedItem.BeenRead = true;
});
// Clear the list
LinkTextList.Items.Clear();
@@ -358,12 +360,12 @@ namespace FeedCenter
private void ResetDatabase()
{
// Get the ID of the current feed
var currentId = _currentFeed?.ID ?? Guid.Empty;
var currentId = _currentFeed?.Id ?? Guid.Empty;
// Create a new database object
_database = new FeedCenterEntities();
_database.Refresh();
_feedList = _currentCategory == null ? _database.Feeds : _database.Feeds.Where(feed => feed.Category.ID == _currentCategory.ID);
_feedList = _currentCategory == null ? _database.Feeds : _database.Feeds.Where(feed => feed.Category.Id == _currentCategory.Id);
UpdateToolbarButtonState();
@@ -371,7 +373,7 @@ namespace FeedCenter
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);
var newIndex = feedList.FindIndex(f => f.Id == currentId);
if (newIndex == -1)
{

View File

@@ -42,7 +42,7 @@ namespace FeedCenter
if (BrowserCommon.OpenLink(browser, feedItem.Link))
{
// Mark the feed as read
feedItem.BeenRead = true;
_database.SaveChanges(() => feedItem.BeenRead = true);
// Remove the item
LinkTextList.Items.Remove(feedItem);
@@ -54,9 +54,6 @@ namespace FeedCenter
// Switch to the normal sleep interval
sleepInterval = settings.OpenAllSleepInterval;
}
// Save the changes
_database.SaveChanges();
}
private void HandleOptionsToolbarButtonClick(object sender, RoutedEventArgs e)
@@ -70,7 +67,7 @@ namespace FeedCenter
// If okay was selected
if (result.HasValue && result.Value)
{
// Reset the database to current settings
// Refresh the database to current settings
ResetDatabase();
// Re-initialize the feed display
@@ -94,7 +91,7 @@ namespace FeedCenter
// If okay was selected
if (result.GetValueOrDefault())
{
// Reset the database to current settings
// Refresh the database to current settings
ResetDatabase();
// Re-initialize the feed display
@@ -156,7 +153,7 @@ namespace FeedCenter
if (result.HasValue && result.Value)
{
// Save
_database.SaveChanges();
_database.SaveChanges(() => { });
// Update feed
DisplayFeed();
@@ -175,15 +172,8 @@ namespace FeedCenter
// Move to the next feed
NextFeed();
// Delete all items
foreach (var item in feedToDelete.Items.ToList())
_database.FeedItems.Remove(item);
// Delete the feed
_database.Feeds.Remove(feedToDelete);
// Save
_database.SaveChanges();
_database.SaveChanges(() => _database.Feeds.Remove(feedToDelete));
}
private void OpenAllFeedItemsOnSinglePage()

View File

@@ -90,10 +90,7 @@ namespace FeedCenter
SaveWindowSettings();
// Save settings
Settings.Default.Save();
// Save options
_database.SaveChanges();
_database.SaveChanges(() => Settings.Default.Save());
// Get rid of the notification icon
NotificationIcon.Dispose();
@@ -102,16 +99,14 @@ namespace FeedCenter
private DelayedMethod _windowStateDelay;
private void HandleWindowSizeChanged(object sender, SizeChangedEventArgs e)
{
if (_windowStateDelay == null)
_windowStateDelay = new DelayedMethod(500, UpdateWindowSettings);
_windowStateDelay ??= new DelayedMethod(500, UpdateWindowSettings);
_windowStateDelay.Reset();
}
private void HandleWindowLocationChanged(object sender, EventArgs e)
{
if (_windowStateDelay == null)
_windowStateDelay = new DelayedMethod(500, UpdateWindowSettings);
_windowStateDelay ??= new DelayedMethod(500, UpdateWindowSettings);
_windowStateDelay.Reset();
}