diff --git a/Filtration/Filtration.csproj b/Filtration/Filtration.csproj
index a4fac00..f6cb9e6 100644
--- a/Filtration/Filtration.csproj
+++ b/Filtration/Filtration.csproj
@@ -217,6 +217,7 @@
+
diff --git a/Filtration/Services/Bootstrapper.cs b/Filtration/Services/Bootstrapper.cs
index a969b05..d0c5260 100644
--- a/Filtration/Services/Bootstrapper.cs
+++ b/Filtration/Services/Bootstrapper.cs
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using System.Windows;
+using Filtration.Properties;
using Filtration.Views;
using NLog;
@@ -17,16 +18,19 @@ namespace Filtration.Services
private readonly IItemFilterScriptDirectoryService _itemFilterScriptDirectoryService;
private readonly IMainWindow _mainWindow;
+ private readonly IScriptLoadingService _scriptLoadingService;
private readonly ISettingsService _settingsService;
private readonly IUpdateService _updateService;
public Bootstrapper(IItemFilterScriptDirectoryService itemFilterScriptDirectoryService,
IMainWindow mainWindow,
+ IScriptLoadingService scriptLoadingService,
ISettingsService settingsService,
IUpdateService updateService)
{
_itemFilterScriptDirectoryService = itemFilterScriptDirectoryService;
_mainWindow = mainWindow;
+ _scriptLoadingService = scriptLoadingService;
_settingsService = settingsService;
_updateService = updateService;
}
@@ -44,6 +48,12 @@ namespace Filtration.Services
_mainWindow.Show();
+ // If there were scripts open the last time the application was closed, reopen them
+ if (!string.IsNullOrWhiteSpace(Settings.Default.LastOpenScripts))
+ {
+ await _scriptLoadingService.LoadScriptsAsync(Settings.Default.LastOpenScripts.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries));
+ }
+
await _updateService.CheckForUpdatesAsync();
}
diff --git a/Filtration/Services/ScriptLoadingService.cs b/Filtration/Services/ScriptLoadingService.cs
new file mode 100644
index 0000000..91b51ff
--- /dev/null
+++ b/Filtration/Services/ScriptLoadingService.cs
@@ -0,0 +1,98 @@
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using System.Windows;
+using Filtration.Common.Services;
+using Filtration.Repositories;
+using Filtration.ThemeEditor.Providers;
+using Filtration.ThemeEditor.ViewModels;
+using Filtration.ViewModels;
+using GalaSoft.MvvmLight.Messaging;
+using NLog;
+
+namespace Filtration.Services
+{
+ internal interface IScriptLoadingService
+ {
+ Task LoadScriptAsync(string scriptFilename);
+ Task LoadScriptsAsync(string[] files);
+ Task LoadThemeAsync(string themeFilename);
+ }
+
+ internal sealed class ScriptLoadingService : IScriptLoadingService
+ {
+ private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
+
+ private readonly IAvalonDockWorkspaceViewModel _avalonDockWorkspaceViewModel;
+ private readonly IMessageBoxService _messageBoxService;
+ private readonly IThemeProvider _themeProvider;
+ private readonly IItemFilterScriptRepository _itemFilterScriptRepository;
+
+ public ScriptLoadingService(IAvalonDockWorkspaceViewModel avalonDockWorkspaceViewModel,
+ IItemFilterScriptRepository itemFilterScriptRepository,
+ IMessageBoxService messageBoxService,
+ IThemeProvider themeProvider)
+ {
+ _avalonDockWorkspaceViewModel = avalonDockWorkspaceViewModel;
+ _messageBoxService = messageBoxService;
+ _themeProvider = themeProvider;
+ _itemFilterScriptRepository = itemFilterScriptRepository;
+ }
+
+ public async Task LoadScriptsAsync(string[] files)
+ {
+ foreach (var file in files)
+ {
+ if (File.Exists(file))
+ {
+ await LoadScriptAsync(file);
+ }
+ }
+ }
+
+ public async Task LoadScriptAsync(string scriptFilename)
+ {
+ IItemFilterScriptViewModel loadedViewModel;
+
+ Messenger.Default.Send(new NotificationMessage("ShowLoadingBanner"));
+ try
+ {
+ loadedViewModel = await _itemFilterScriptRepository.LoadScriptFromFileAsync(scriptFilename);
+ }
+ catch (Exception e)
+ {
+ Logger.Error(e);
+ _messageBoxService.Show("Script Load Error", "Error loading filter script - " + e.Message,
+ MessageBoxButton.OK,
+ MessageBoxImage.Error);
+ return;
+ }
+ finally
+ {
+ Messenger.Default.Send(new NotificationMessage("HideLoadingBanner"));
+ }
+
+ _avalonDockWorkspaceViewModel.AddDocument(loadedViewModel);
+ }
+
+ public async Task LoadThemeAsync(string themeFilename)
+ {
+ IThemeEditorViewModel loadedViewModel;
+
+ try
+ {
+ loadedViewModel = await _themeProvider.LoadThemeFromFile(themeFilename);
+ }
+ catch (Exception e)
+ {
+ Logger.Error(e);
+ _messageBoxService.Show("Theme Load Error", "Error loading filter theme - " + e.Message,
+ MessageBoxButton.OK,
+ MessageBoxImage.Error);
+ return;
+ }
+
+ _avalonDockWorkspaceViewModel.AddDocument(loadedViewModel);
+ }
+ }
+}
diff --git a/Filtration/ViewModels/MainWindowViewModel.cs b/Filtration/ViewModels/MainWindowViewModel.cs
index 2466aff..1aed815 100644
--- a/Filtration/ViewModels/MainWindowViewModel.cs
+++ b/Filtration/ViewModels/MainWindowViewModel.cs
@@ -49,6 +49,7 @@ namespace Filtration.ViewModels
private readonly IItemFilterScriptTranslator _itemFilterScriptTranslator;
private readonly IReplaceColorsViewModel _replaceColorsViewModel;
private readonly IAvalonDockWorkspaceViewModel _avalonDockWorkspaceViewModel;
+ private readonly IScriptLoadingService _scriptLoadingService;
private readonly IThemeProvider _themeProvider;
private readonly IThemeService _themeService;
private readonly IMessageBoxService _messageBoxService;
@@ -63,6 +64,7 @@ namespace Filtration.ViewModels
IItemFilterScriptTranslator itemFilterScriptTranslator,
IReplaceColorsViewModel replaceColorsViewModel,
IAvalonDockWorkspaceViewModel avalonDockWorkspaceViewModel,
+ IScriptLoadingService scriptLoadingService,
ISettingsPageViewModel settingsPageViewModel,
IThemeProvider themeProvider,
IThemeService themeService,
@@ -75,6 +77,7 @@ namespace Filtration.ViewModels
_itemFilterScriptTranslator = itemFilterScriptTranslator;
_replaceColorsViewModel = replaceColorsViewModel;
_avalonDockWorkspaceViewModel = avalonDockWorkspaceViewModel;
+ _scriptLoadingService = scriptLoadingService;
SettingsPageViewModel = settingsPageViewModel;
_themeProvider = themeProvider;
_themeService = themeService;
@@ -204,10 +207,6 @@ namespace Filtration.ViewModels
}
});
- if (!string.IsNullOrWhiteSpace(Settings.Default.LastOpenScripts))
- {
- LoadScriptsAsync(Settings.Default.LastOpenScripts.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries));
- }
}
public RelayCommand OpenScriptCommand { get; }
@@ -369,12 +368,12 @@ namespace Filtration.ViewModels
{
case ".FILTER":
{
- await LoadScriptAsync(filename);
+ await _scriptLoadingService.LoadScriptAsync(filename);
break;
}
case ".FILTERTHEME":
{
- await LoadThemeAsync(filename);
+ await _scriptLoadingService.LoadThemeAsync(filename);
break;
}
}
@@ -431,43 +430,7 @@ namespace Filtration.ViewModels
return;
}
- await LoadScriptAsync(filePath); // TODO: fix crash
- }
-
- private async Task LoadScriptsAsync(string[] files)
- {
- foreach (var file in files)
- {
- if (File.Exists(file))
- {
- await LoadScriptAsync(file);
- }
- }
- }
-
- private async Task LoadScriptAsync(string scriptFilename)
- {
- IItemFilterScriptViewModel loadedViewModel;
-
- Messenger.Default.Send(new NotificationMessage("ShowLoadingBanner"));
- try
- {
- loadedViewModel = await _itemFilterScriptRepository.LoadScriptFromFileAsync(scriptFilename);
- }
- catch (Exception e)
- {
- Logger.Error(e);
- _messageBoxService.Show("Script Load Error", "Error loading filter script - " + e.Message,
- MessageBoxButton.OK,
- MessageBoxImage.Error);
- return;
- }
- finally
- {
- Messenger.Default.Send(new NotificationMessage("HideLoadingBanner"));
- }
-
- _avalonDockWorkspaceViewModel.AddDocument(loadedViewModel);
+ await _scriptLoadingService.LoadScriptAsync(filePath);
}
private async Task OnOpenThemeCommandAsync()
@@ -478,27 +441,7 @@ namespace Filtration.ViewModels
return;
}
- await LoadThemeAsync(filePath);
- }
-
- private async Task LoadThemeAsync(string themeFilename)
- {
- IThemeEditorViewModel loadedViewModel;
-
- try
- {
- loadedViewModel = await _themeProvider.LoadThemeFromFile(themeFilename);
- }
- catch (Exception e)
- {
- Logger.Error(e);
- _messageBoxService.Show("Theme Load Error", "Error loading filter theme - " + e.Message,
- MessageBoxButton.OK,
- MessageBoxImage.Error);
- return;
- }
-
- _avalonDockWorkspaceViewModel.AddDocument(loadedViewModel);
+ await _scriptLoadingService.LoadThemeAsync(filePath);
}
private async Task OnApplyThemeToScriptCommandAsync()
diff --git a/Filtration/WindsorInstallers/ServicesInstaller.cs b/Filtration/WindsorInstallers/ServicesInstaller.cs
index 8bf6258..5300868 100644
--- a/Filtration/WindsorInstallers/ServicesInstaller.cs
+++ b/Filtration/WindsorInstallers/ServicesInstaller.cs
@@ -5,7 +5,7 @@ using Filtration.Services;
namespace Filtration.WindsorInstallers
{
- public class ServicesInstaller :IWindsorInstaller
+ public class ServicesInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
@@ -19,6 +19,11 @@ namespace Filtration.WindsorInstallers
.ImplementedBy()
.LifeStyle.Singleton);
+ container.Register(
+ Component.For()
+ .ImplementedBy()
+ .LifeStyle.Singleton);
+
container.Register(
Component.For()
.ImplementedBy()