Fixed #33 - Update check window buttons erroneously shut down application

This commit is contained in:
Ben Wallis 2016-09-01 20:26:55 +01:00
parent 43bc1410ae
commit 0b791f5747
5 changed files with 26 additions and 46 deletions

View File

@ -12,6 +12,7 @@ namespace Filtration.ItemFilterPreview.Tests.Services
{
class serializationtest
{
[Ignore("")]
[Test]
public void test_serialization()
{

Binary file not shown.

View File

@ -1,18 +1,16 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Threading;
using AutoMapper;
using Castle.Facilities.TypedFactory;
using Castle.MicroKernel.ModelBuilder.Inspectors;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Castle.Windsor.Installer;
using Filtration.ObjectModel;
using Filtration.ObjectModel.ThemeEditor;
using Filtration.Properties;
using Filtration.Services;
using Filtration.ThemeEditor.ViewModels;
using Filtration.ViewModels;
using Filtration.Views;
@ -71,6 +69,9 @@ namespace Filtration
var mainWindow = _container.Resolve<IMainWindow>();
mainWindow.Show();
var updateCheckService = _container.Resolve<IUpdateCheckService>();
updateCheckService.CheckForUpdates();
}
private static void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)

View File

@ -6,13 +6,15 @@ using System.Windows;
using System.Xml.Serialization;
using Filtration.Models;
using Filtration.Properties;
using Filtration.ViewModels;
using Filtration.Views;
using NLog;
namespace Filtration.Services
{
internal interface IUpdateCheckService
{
UpdateData CheckForUpdates();
void CheckForUpdates();
}
internal class UpdateCheckService : IUpdateCheckService
@ -20,13 +22,16 @@ namespace Filtration.Services
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IHTTPService _httpService;
private readonly IUpdateAvailableViewModel _updateAvailableViewModel;
public UpdateCheckService(IHTTPService httpService)
public UpdateCheckService(IHTTPService httpService,
IUpdateAvailableViewModel updateAvailableViewModel)
{
_httpService = httpService;
_updateAvailableViewModel = updateAvailableViewModel;
}
public UpdateData CheckForUpdates()
public void CheckForUpdates()
{
var assemblyVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
@ -45,7 +50,6 @@ namespace Filtration.Services
Settings.Default.Save();
updateData.UpdateAvailable = true;
return updateData;
}
}
@ -73,8 +77,13 @@ namespace Filtration.Services
}
}
updateData.UpdateAvailable = false;
return updateData;
if (updateData.UpdateAvailable)
{
var updateAvailableView = new UpdateAvailableView { DataContext = _updateAvailableViewModel };
_updateAvailableViewModel.Initialise(updateData);
_updateAvailableViewModel.OnRequestClose += (s, e) => updateAvailableView.Close();
updateAvailableView.ShowDialog();
}
}
catch (Exception e)
{
@ -82,8 +91,6 @@ namespace Filtration.Services
// We don't care if the update check fails, because it could fail for multiple reasons
// including the user blocking Filtration in their firewall.
}
return null;
}
private static bool LatestVersionIsNewerThanSuppressedVersion(UpdateData updateData)

View File

@ -10,13 +10,10 @@ using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Filtration.Common.Services;
using Filtration.Common.ViewModels;
using Filtration.Interface;
using Filtration.Models;
using Filtration.ObjectModel.Enums;
using Filtration.ObjectModel.ThemeEditor;
using Filtration.Parser.Interface.Services;
using Filtration.Properties;
using Filtration.Repositories;
using Filtration.Services;
using Filtration.ThemeEditor.Messages;
@ -50,8 +47,6 @@ namespace Filtration.ViewModels
private readonly IAvalonDockWorkspaceViewModel _avalonDockWorkspaceViewModel;
private readonly IThemeProvider _themeProvider;
private readonly IThemeService _themeService;
private readonly IUpdateCheckService _updateCheckService;
private readonly IUpdateAvailableViewModel _updateAvailableViewModel;
private readonly IMessageBoxService _messageBoxService;
private readonly IClipboardService _clipboardService;
private bool _showLoadingBanner;
@ -63,8 +58,6 @@ namespace Filtration.ViewModels
ISettingsPageViewModel settingsPageViewModel,
IThemeProvider themeProvider,
IThemeService themeService,
IUpdateCheckService updateCheckService,
IUpdateAvailableViewModel updateAvailableViewModel,
IMessageBoxService messageBoxService,
IClipboardService clipboardService)
{
@ -75,8 +68,6 @@ namespace Filtration.ViewModels
SettingsPageViewModel = settingsPageViewModel;
_themeProvider = themeProvider;
_themeService = themeService;
_updateCheckService = updateCheckService;
_updateAvailableViewModel = updateAvailableViewModel;
_messageBoxService = messageBoxService;
_clipboardService = clipboardService;
@ -102,10 +93,8 @@ namespace Filtration.ViewModels
AddBlockCommand = new RelayCommand(OnAddBlockCommand, () => ActiveDocumentIsScript);
AddSectionCommand = new RelayCommand(OnAddSectionCommand, () => ActiveDocumentIsScript);
DeleteBlockCommand = new RelayCommand(OnDeleteBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
DisableBlockCommand = new RelayCommand(OnDisableBlockCommand,
() => ActiveDocumentIsScript && ActiveScriptHasSelectedEnabledBlock);
EnableBlockCommand = new RelayCommand(OnEnableBlockCommand,
() => ActiveDocumentIsScript && ActiveScriptHasSelectedDisabledBlock);
DisableBlockCommand = new RelayCommand(OnDisableBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedEnabledBlock);
EnableBlockCommand = new RelayCommand(OnEnableBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedDisabledBlock);
OpenAboutWindowCommand = new RelayCommand(OnOpenAboutWindowCommand);
ReplaceColorsCommand = new RelayCommand(OnReplaceColorsCommand, () => ActiveDocumentIsScript);
@ -116,10 +105,7 @@ namespace Filtration.ViewModels
AddTextColorThemeComponentCommand = new RelayCommand(OnAddTextColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
AddBackgroundColorThemeComponentCommand = new RelayCommand(OnAddBackgroundColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
AddBorderColorThemeComponentCommand = new RelayCommand(OnAddBorderColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
DeleteThemeComponentCommand = new RelayCommand(OnDeleteThemeComponentCommand,
() =>
ActiveDocumentIsTheme && ActiveThemeIsEditable &&
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.SelectedThemeComponent != null);
DeleteThemeComponentCommand = new RelayCommand(OnDeleteThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable && _avalonDockWorkspaceViewModel.ActiveThemeViewModel.SelectedThemeComponent != null);
ExpandAllBlocksCommand = new RelayCommand(OnExpandAllBlocksCommand, () => ActiveDocumentIsScript);
CollapseAllBlocksCommand = new RelayCommand(OnCollapseAllBlocksCommand, () => ActiveDocumentIsScript);
@ -189,8 +175,6 @@ namespace Filtration.ViewModels
}
}
});
CheckForUpdates();
}
public RelayCommand OpenScriptCommand { get; }
@ -233,19 +217,6 @@ namespace Filtration.ViewModels
public RelayCommand<bool> ToggleShowAdvancedCommand { get; }
public RelayCommand ClearFiltersCommand { get; }
private void CheckForUpdates()
{
var updateData = _updateCheckService.CheckForUpdates();
if (updateData != null && updateData.UpdateAvailable)
{
var updateAvailableView = new UpdateAvailableView { DataContext = _updateAvailableViewModel };
_updateAvailableViewModel.Initialise(updateData);
_updateAvailableViewModel.OnRequestClose += (s, e) => updateAvailableView.Close();
updateAvailableView.ShowDialog();
}
}
public ImageSource Icon { get; private set; }
public IAvalonDockWorkspaceViewModel AvalonDockWorkspaceViewModel => _avalonDockWorkspaceViewModel;