Moved application code to the Application layer

Imported Win10 project
Code cleanup
WIP - Use common UWP services for Win8.1 and Win10
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-06 20:20:45 +02:00
parent e795a8c3c4
commit 56d93a5187
292 changed files with 48614 additions and 837 deletions

View File

@@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using Windows.UI;
using Autofac;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Entities;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels.ListItems
{
public class EntryItemViewModel : NotifyPropertyChangedBase
{
private readonly ISecurityService _securityService;
public EntryEntity EntryEntity { get; }
public GroupItemViewModel Parent { get; }
public bool HasExpired => HasExpirationDate && EntryEntity.ExpirationDate < DateTime.Now;
public bool HasUrl => !string.IsNullOrEmpty(Url);
public double PasswordComplexityIndicator => _securityService.EstimatePasswordComplexity(Password);
public string Name
{
get => EntryEntity.Name;
set
{
EntryEntity.Name = value;
OnPropertyChanged(nameof(Name));
}
}
public string UserName
{
get => EntryEntity.UserName;
set => EntryEntity.UserName = value;
}
public string Password
{
get => EntryEntity.Password;
set
{
EntryEntity.Password = value;
OnPropertyChanged();
}
}
public string Url
{
get => EntryEntity.Url?.ToString();
set => EntryEntity.Url = new Uri(value);
}
public string Notes
{
get => EntryEntity.Notes;
set => EntryEntity.Notes = value;
}
public Icon Icon
{
get => HasExpired ? Icon.Important : EntryEntity.Icon;
set => EntryEntity.Icon = value;
}
public DateTimeOffset ExpiryDate
{
get => EntryEntity.ExpirationDate;
set
{
if (!HasExpirationDate) return;
EntryEntity.ExpirationDate = value;
}
}
public TimeSpan ExpiryTime
{
get => EntryEntity.ExpirationDate.TimeOfDay;
set
{
if (!HasExpirationDate) return;
EntryEntity.ExpirationDate = EntryEntity.ExpirationDate.Date.Add(value);
}
}
public bool HasExpirationDate
{
get => EntryEntity.HasExpirationDate;
set
{
EntryEntity.HasExpirationDate = value;
OnPropertyChanged();
}
}
public Color BackgroundColor
{
get => Color.FromArgb(EntryEntity.BackgroundColor.A, EntryEntity.BackgroundColor.R, EntryEntity.BackgroundColor.G, EntryEntity.BackgroundColor.B);
set
{
EntryEntity.BackgroundColor = System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B);
OnPropertyChanged();
}
}
public Color ForegroundColor
{
get => Color.FromArgb(EntryEntity.ForegroundColor.A, EntryEntity.ForegroundColor.R, EntryEntity.ForegroundColor.G, EntryEntity.ForegroundColor.B);
set
{
EntryEntity.ForegroundColor = System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B);
OnPropertyChanged();
}
}
public IEnumerable<EntryItemViewModel> History
{
get
{
var history = new Stack<EntryItemViewModel>();
foreach (var historyEntry in EntryEntity.History)
{
history.Push(new EntryItemViewModel(_securityService, historyEntry, Parent));
}
history.Push(this);
return history;
}
}
public Dictionary<string, string> AdditionalFields => EntryEntity.AdditionalFields;
public EntryItemViewModel(EntryEntity entryEntity, GroupItemViewModel parentGroup): this(App.Container.Resolve<ISecurityService>(), entryEntity, parentGroup)
{ }
public EntryItemViewModel(ISecurityService securityService, EntryEntity entryEntity, GroupItemViewModel parentGroup)
{
_securityService = securityService;
EntryEntity = entryEntity;
Parent = parentGroup;
}
public override string ToString() => EntryEntity.LastModificationDate.ToString("g");
}
}

View File

@@ -0,0 +1,101 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Autofac;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Entities;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels.ListItems
{
public class GroupItemViewModel: NotifyPropertyChangedBase
{
private readonly IDatabaseService _databaseService;
//private Group _reorderedGroup;
private bool _isEditMode;
public GroupEntity GroupEntity { get; }
public GroupItemViewModel ParentViewModel { get; }
public bool IsEditMode
{
get => _isEditMode;
set
{
_isEditMode = value;
OnPropertyChanged();
}
}
public string Text
{
get => GroupEntity.Name;
set
{
GroupEntity.Name = value;
OnPropertyChanged();
}
}
public IEnumerable<EntryItemViewModel> SubEntries
{
get
{
var subEntries = new List<EntryItemViewModel>();
subEntries.AddRange(Entries);
foreach (var group in Children)
{
subEntries.AddRange(group.SubEntries);
}
return subEntries;
}
}
public Icon Symbol => GroupEntity.Icon;
public List<EntryItemViewModel> Entries { get; }
public ObservableCollection<GroupItemViewModel> Children { get; set; } = new ObservableCollection<GroupItemViewModel>();
public GroupItemViewModel(GroupEntity groupEntity, GroupItemViewModel parent): this(App.Container.Resolve<IDatabaseService>(), groupEntity, parent)
{ }
public GroupItemViewModel(IDatabaseService databaseService, GroupEntity groupEntity, GroupItemViewModel parentViewModel)
{
_databaseService = databaseService;
GroupEntity = groupEntity;
ParentViewModel = parentViewModel;
Entries = new List<EntryItemViewModel>();
foreach (var entry in groupEntity.Entries)
{
Entries.Add(new EntryItemViewModel(entry, this));
}
foreach (var subGroup in groupEntity.SubGroups)
{
Children.Add(new GroupItemViewModel(subGroup, this));
}
Children.CollectionChanged += Children_CollectionChanged;
}
// TODO: not triggered when reordering
private void Children_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Remove:
/*var oldIndex = (uint)e.OldStartingIndex;
_reorderedGroup = Group.SubGroups.GetAt(oldIndex);
Group.SubGroups.RemoveAt(oldIndex);*/
_databaseService.DeleteEntity((Entity)e.OldItems[0]);
break;
case NotifyCollectionChangedAction.Add:
/*if (_reorderedGroup == null) Group.AddGroup(((GroupItem)e.NewItems[0]).Group, true);
else Group.Groups.Insert((uint)e.NewStartingIndex, _reorderedGroup);*/
_databaseService.AddEntity(ParentViewModel.GroupEntity, (Entity)e.NewItems[0]);
break;
}
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels.ListItems
{
public class ListMenuItemViewModel : NotifyPropertyChangedBase, IIsEnabled, ISelectableModel
{
private bool _isSelected;
public string Title { get; set; }
public string Group { get; set; } = "_";
public Type PageType { get; set; }
public Symbol SymbolIcon { get; set; }
public bool IsEnabled { get; set; } = true;
public bool IsSelected
{
get => _isSelected;
set => SetProperty(ref _isSelected, value);
}
public override string ToString()
{
return Title;
}
}
}

View File

@@ -0,0 +1,10 @@
using Windows.UI.Xaml.Controls;
namespace ModernKeePass.ViewModels.ListItems
{
public class MainMenuItemViewModel: ListMenuItemViewModel
{
public object Parameter { get; set; }
public Frame Destination { get; set; }
}
}

View File

@@ -0,0 +1,36 @@
using System.Threading.Tasks;
using Autofac;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels.ListItems
{
public class RecentItemViewModel: NotifyPropertyChangedBase, ISelectableModel
{
private readonly IRecentService _recentService;
private bool _isSelected;
public string Token { get; set; }
public string Name { get; set; }
public bool IsSelected
{
get => _isSelected;
set => SetProperty(ref _isSelected, value);
}
public RecentItemViewModel(): this (App.Container.Resolve<IRecentService>())
{ }
public RecentItemViewModel(IRecentService recentService)
{
_recentService = recentService;
}
public async Task UpdateAccessTime()
{
await _recentService.Get(Token);
}
}
}

View File

@@ -0,0 +1,101 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Autofac;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Entities;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels.ListItems
{
// TODO: implement Kdf settings
public class SettingsDatabaseViewModel: NotifyPropertyChangedBase
{
private readonly IDatabaseService _databaseService;
private readonly ICryptographyService _cryptographyService;
public bool HasRecycleBin
{
get => _databaseService.IsRecycleBinEnabled;
set {
// TODO: do something here
}
}
public bool IsNewRecycleBin
{
get => _databaseService.RecycleBin == null;
set
{
// TODO: make this work
if (value) _databaseService.AddEntity(_databaseService.RootGroupEntity, new Entity{Name = "Recycle Bin"});
}
}
public ObservableCollection<GroupEntity> Groups { get; set; }
public ObservableCollection<Entity> Ciphers => new ObservableCollection<Entity>(_cryptographyService.Ciphers);
public IEnumerable<string> Compressions => _cryptographyService.CompressionAlgorithms;
public IEnumerable<Entity> KeyDerivations => _cryptographyService.KeyDerivations;
public Entity SelectedCipher
{
get => Ciphers.FirstOrDefault(c => c.Id == _databaseService.Cipher.Id);
set
{
if (_databaseService.Cipher != value)
{
_databaseService.Cipher = value;
//OnPropertyChanged(nameof(SelectedCipher));
}
}
}
public Entity SelectedKeyDerivation
{
get => _databaseService.KeyDerivation;
set
{
if (_databaseService.KeyDerivation != value)
{
_databaseService.KeyDerivation = value;
OnPropertyChanged(nameof(SelectedKeyDerivation));
}
}
}
public string SelectedCompression
{
get => _databaseService.Compression;
set
{
if (_databaseService.Compression != value)
{
_databaseService.Compression = value;
OnPropertyChanged(nameof(SelectedCompression));
}
}
}
public GroupEntity SelectedRecycleBin
{
get => _databaseService.RecycleBin;
set
{
if (_databaseService.RecycleBin != value)
{
_databaseService.RecycleBin = value;
OnPropertyChanged(nameof(SelectedRecycleBin));
}
}
}
public SettingsDatabaseViewModel() : this(App.Container.Resolve<IDatabaseService>(), App.Container.Resolve<ICryptographyService>()) { }
public SettingsDatabaseViewModel(IDatabaseService databaseService, ICryptographyService cryptographyService)
{
_databaseService = databaseService;
_cryptographyService = cryptographyService;
Groups = new ObservableCollection<GroupEntity>(_databaseService.RootGroupEntity.SubGroups);
}
}
}

View File

@@ -0,0 +1,33 @@
using System.Collections.Generic;
using Autofac;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels.ListItems
{
public class SettingsNewViewModel
{
private readonly ISettingsService _settings;
public SettingsNewViewModel() : this(App.Container.Resolve<ISettingsService>())
{ }
public SettingsNewViewModel(ISettingsService settings)
{
_settings = settings;
}
public bool IsCreateSample
{
get => _settings.GetSetting<bool>("Sample");
set => _settings.PutSetting("Sample", value);
}
public IEnumerable<string> FileFormats => new []{"2", "4"};
public string FileFormatVersion
{
get => _settings.GetSetting("DefaultFileFormat", "2");
set => _settings.PutSetting("DefaultFileFormat", value);
}
}
}

View File

@@ -0,0 +1,24 @@
using Autofac;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels.ListItems
{
public class SettingsSaveViewModel
{
private readonly ISettingsService _settings;
public SettingsSaveViewModel() : this(App.Container.Resolve<ISettingsService>())
{ }
public SettingsSaveViewModel(ISettingsService settings)
{
_settings = settings;
}
public bool IsSaveSuspend
{
get => _settings.GetSetting("SaveSuspend", true);
set => _settings.PutSetting("SaveSuspend", value);
}
}
}