2015-12-13 15:17:15 -05:00
|
|
|
|
using System.IO;
|
2015-07-05 17:43:17 -04:00
|
|
|
|
using System.Linq;
|
2015-07-25 14:02:42 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2015-06-26 12:42:20 -04:00
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Filtration.ObjectModel;
|
2018-08-24 15:07:24 -04:00
|
|
|
|
using Filtration.ObjectModel.Enums;
|
2015-06-26 12:42:20 -04:00
|
|
|
|
using Filtration.ObjectModel.ThemeEditor;
|
|
|
|
|
using Filtration.ThemeEditor.Services;
|
|
|
|
|
using Filtration.ThemeEditor.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace Filtration.ThemeEditor.Providers
|
|
|
|
|
{
|
|
|
|
|
public interface IThemeProvider
|
|
|
|
|
{
|
2017-06-17 08:50:44 -04:00
|
|
|
|
IThemeEditorViewModel NewThemeForScript(IItemFilterScript script);
|
|
|
|
|
IThemeEditorViewModel MasterThemeForScript(IItemFilterScript script);
|
2015-07-25 14:02:42 -04:00
|
|
|
|
Task<IThemeEditorViewModel> LoadThemeFromFile(string filePath);
|
|
|
|
|
Task<Theme> LoadThemeModelFromFile(string filePath);
|
|
|
|
|
Task SaveThemeAsync(IThemeEditorViewModel themeEditorViewModel, string filePath);
|
2015-06-26 12:42:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class ThemeProvider : IThemeProvider
|
|
|
|
|
{
|
|
|
|
|
private readonly IThemeViewModelFactory _themeViewModelFactory;
|
|
|
|
|
private readonly IThemePersistenceService _themePersistenceService;
|
|
|
|
|
|
|
|
|
|
public ThemeProvider(IThemeViewModelFactory themeViewModelFactory, IThemePersistenceService themePersistenceService)
|
|
|
|
|
{
|
|
|
|
|
_themeViewModelFactory = themeViewModelFactory;
|
|
|
|
|
_themePersistenceService = themePersistenceService;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-17 08:50:44 -04:00
|
|
|
|
public IThemeEditorViewModel NewThemeForScript(IItemFilterScript script)
|
2015-06-26 12:42:20 -04:00
|
|
|
|
{
|
2015-07-05 17:43:17 -04:00
|
|
|
|
var themeComponentCollection = script.ThemeComponents.Aggregate(new ThemeComponentCollection(),
|
|
|
|
|
(c, component) =>
|
|
|
|
|
{
|
2018-08-24 15:07:24 -04:00
|
|
|
|
switch(component.ComponentType)
|
|
|
|
|
{
|
|
|
|
|
case ThemeComponentType.BackgroundColor:
|
|
|
|
|
case ThemeComponentType.BorderColor:
|
|
|
|
|
case ThemeComponentType.TextColor:
|
|
|
|
|
c.Add(new ColorThemeComponent(component.ComponentType, component.ComponentName, ((ColorThemeComponent)component).Color));
|
|
|
|
|
break;
|
2018-08-25 08:52:16 -04:00
|
|
|
|
case ThemeComponentType.FontSize:
|
|
|
|
|
c.Add(new IntegerThemeComponent(component.ComponentType, component.ComponentName, ((IntegerThemeComponent)component).Value));
|
|
|
|
|
break;
|
2018-08-26 13:24:13 -04:00
|
|
|
|
case ThemeComponentType.AlertSound:
|
|
|
|
|
c.Add(new StrIntThemeComponent(component.ComponentType, component.ComponentName, ((StrIntThemeComponent)component).Value, ((StrIntThemeComponent)component).SecondValue));
|
|
|
|
|
break;
|
2018-08-24 15:07:24 -04:00
|
|
|
|
}
|
2015-07-05 17:43:17 -04:00
|
|
|
|
return c;
|
|
|
|
|
});
|
|
|
|
|
|
2015-06-26 12:42:20 -04:00
|
|
|
|
var themeViewModel = _themeViewModelFactory.Create();
|
2015-07-06 08:41:46 -04:00
|
|
|
|
themeViewModel.InitialiseForNewTheme(themeComponentCollection);
|
2015-06-26 12:42:20 -04:00
|
|
|
|
themeViewModel.FilePath = "Untitled.filtertheme";
|
|
|
|
|
|
|
|
|
|
return themeViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-17 08:50:44 -04:00
|
|
|
|
public IThemeEditorViewModel MasterThemeForScript(IItemFilterScript script)
|
2015-07-05 17:43:17 -04:00
|
|
|
|
{
|
|
|
|
|
var themeViewModel = _themeViewModelFactory.Create();
|
2015-07-06 08:41:46 -04:00
|
|
|
|
themeViewModel.InitialiseForMasterTheme(script);
|
2015-07-05 17:43:17 -04:00
|
|
|
|
themeViewModel.FilePath = "<Master Theme> " + Path.GetFileName(script.FilePath);
|
|
|
|
|
|
|
|
|
|
return themeViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 14:02:42 -04:00
|
|
|
|
public async Task<IThemeEditorViewModel> LoadThemeFromFile(string filePath)
|
2015-06-26 12:42:20 -04:00
|
|
|
|
{
|
2015-07-25 14:02:42 -04:00
|
|
|
|
var model = await _themePersistenceService.LoadThemeAsync(filePath);
|
2015-07-05 17:43:17 -04:00
|
|
|
|
var viewModel = Mapper.Map<IThemeEditorViewModel>(model);
|
2015-06-26 12:42:20 -04:00
|
|
|
|
viewModel.FilePath = filePath;
|
|
|
|
|
return viewModel;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 14:02:42 -04:00
|
|
|
|
public async Task<Theme> LoadThemeModelFromFile(string filePath)
|
2015-06-26 16:54:20 -04:00
|
|
|
|
{
|
2015-07-25 14:02:42 -04:00
|
|
|
|
return await _themePersistenceService.LoadThemeAsync(filePath);
|
2015-06-26 16:54:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 14:02:42 -04:00
|
|
|
|
public async Task SaveThemeAsync(IThemeEditorViewModel themeEditorViewModel, string filePath)
|
2015-06-26 12:42:20 -04:00
|
|
|
|
{
|
2015-07-25 14:02:42 -04:00
|
|
|
|
await Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
var theme = Mapper.Map<Theme>(themeEditorViewModel);
|
|
|
|
|
_themePersistenceService.SaveThemeAsync(theme, filePath);
|
|
|
|
|
});
|
2015-06-26 12:42:20 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|