mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Create DB works correctly
Sample data moved to application Tests updated (still not working - splat) WIP
This commit is contained in:
@@ -3,6 +3,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Commands.CreateDatabase;
|
||||
using ModernKeePass.Application.Database.Commands.UpdateCredentials;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Application.Database.Queries.OpenDatabase;
|
||||
@@ -110,13 +112,15 @@ namespace ModernKeePass.ViewModels
|
||||
private string _keyFilePath;
|
||||
private string _keyFileText;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly ISettingsProxy _settings;
|
||||
private readonly ResourceHelper _resource;
|
||||
|
||||
public CompositeKeyVm() : this(App.Services.GetService<IMediator>()) { }
|
||||
public CompositeKeyVm() : this(App.Services.GetService<IMediator>(), App.Services.GetService<ISettingsProxy>()) { }
|
||||
|
||||
public CompositeKeyVm(IMediator mediator)
|
||||
public CompositeKeyVm(IMediator mediator, ISettingsProxy settings)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_settings = settings;
|
||||
_resource = new ResourceHelper();
|
||||
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
|
||||
}
|
||||
@@ -127,12 +131,25 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
_isOpening = true;
|
||||
OnPropertyChanged(nameof(IsValid));
|
||||
|
||||
await _mediator.Send(new OpenDatabaseQuery {
|
||||
FilePath = databaseFilePath,
|
||||
KeyFilePath = HasKeyFile ? KeyFilePath : null,
|
||||
Password = HasPassword ? Password : null,
|
||||
});
|
||||
if (createNew)
|
||||
{
|
||||
await _mediator.Send(new CreateDatabaseCommand
|
||||
{
|
||||
FilePath = databaseFilePath,
|
||||
KeyFilePath = HasKeyFile ? KeyFilePath : null,
|
||||
Password = HasPassword ? Password : null,
|
||||
Name = "New Database",
|
||||
CreateSampleData = _settings.GetSetting<bool>("Sample")
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await _mediator.Send(new OpenDatabaseQuery {
|
||||
FilePath = databaseFilePath,
|
||||
KeyFilePath = HasKeyFile ? KeyFilePath : null,
|
||||
Password = HasPassword ? Password : null,
|
||||
});
|
||||
}
|
||||
RootGroupId = (await _mediator.Send(new GetDatabaseQuery())).RootGroupId;
|
||||
return true;
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ namespace ModernKeePass.ViewModels
|
||||
// Called from XAML
|
||||
public void UpdateAccessTime()
|
||||
{
|
||||
_recent.Get(Token).Wait();
|
||||
_recent.Get(Token, true).Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Application.Entry.Commands.SetFieldValue;
|
||||
using ModernKeePass.Application.Group.Commands.CreateEntry;
|
||||
using ModernKeePass.Application.Group.Commands.CreateGroup;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Application.Group.Queries.GetGroup;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
@@ -18,7 +10,6 @@ namespace ModernKeePass.ViewModels
|
||||
private readonly IMediator _mediator;
|
||||
private readonly ISettingsProxy _settings;
|
||||
private string _importFormatHelp;
|
||||
public string Password { get; set; }
|
||||
|
||||
public bool IsImportChecked { get; set; }
|
||||
|
||||
@@ -45,57 +36,5 @@ namespace ModernKeePass.ViewModels
|
||||
_mediator = mediator;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public async Task<GroupVm> PopulateInitialData()
|
||||
{
|
||||
var database = await _mediator.Send(new GetDatabaseQuery());
|
||||
var rootGroup = await _mediator.Send(new GetGroupQuery {Id = database.RootGroupId});
|
||||
if (_settings.GetSetting<bool>("Sample") && !IsImportChecked) await CreateSampleData(rootGroup);
|
||||
return rootGroup;
|
||||
}
|
||||
|
||||
private async Task CreateSampleData(GroupVm group)
|
||||
{
|
||||
/*var converter = new IntToSymbolConverter();
|
||||
|
||||
var bankingGroup = group.AddNewGroup("Banking");
|
||||
bankingGroup.Icon = (int)converter.ConvertBack(Symbol.Calculator, null, null, string.Empty);
|
||||
|
||||
var emailGroup = group.AddNewGroup("Email");
|
||||
emailGroup.Icon = (int)converter.ConvertBack(Symbol.Mail, null, null, string.Empty);
|
||||
|
||||
var internetGroup = group.AddNewGroup("Internet");
|
||||
internetGroup.Icon = (int)converter.ConvertBack(Symbol.World, null, null, string.Empty);
|
||||
|
||||
var sample1 = group.AddNewEntry();
|
||||
sample1.Title = "Sample Entry";
|
||||
sample1.UserName = "Username";
|
||||
sample1.Url = PwDefs.HomepageUrl;
|
||||
sample1.Password = "Password";
|
||||
sample1.Notes = "You may safely delete this sample";
|
||||
|
||||
var sample2 = group.AddNewEntry();
|
||||
sample2.Title = "Sample Entry #2";
|
||||
sample2.UserName = "Michael321";
|
||||
sample2.Url = PwDefs.HelpUrl + "kb/testform.html";
|
||||
sample2.Password = "12345";*/
|
||||
|
||||
var bankingGroup = await _mediator.Send(new CreateGroupCommand {ParentGroup = group, Name = "Banking"});
|
||||
var emailGroup = await _mediator.Send(new CreateGroupCommand {ParentGroup = group, Name = "Email" });
|
||||
var internetGroup = await _mediator.Send(new CreateGroupCommand {ParentGroup = group, Name = "Internet" });
|
||||
|
||||
var sample1 = await _mediator.Send(new CreateEntryCommand { ParentGroup = group });
|
||||
await _mediator.Send(new SetFieldValueCommand {EntryId = sample1.Id, FieldName = EntryFieldName.Title, FieldValue = "Sample Entry"});
|
||||
await _mediator.Send(new SetFieldValueCommand {EntryId = sample1.Id, FieldName = EntryFieldName.UserName, FieldValue = "Username" });
|
||||
await _mediator.Send(new SetFieldValueCommand {EntryId = sample1.Id, FieldName = EntryFieldName.Password, FieldValue = "Password" });
|
||||
await _mediator.Send(new SetFieldValueCommand {EntryId = sample1.Id, FieldName = EntryFieldName.Url, FieldValue = "https://keepass.info/" });
|
||||
await _mediator.Send(new SetFieldValueCommand {EntryId = sample1.Id, FieldName = EntryFieldName.Notes, FieldValue = "You may safely delete this sample" });
|
||||
|
||||
var sample2 = await _mediator.Send(new CreateEntryCommand { ParentGroup = group });
|
||||
await _mediator.Send(new SetFieldValueCommand {EntryId = sample2.Id, FieldName = EntryFieldName.Title, FieldValue = "Sample Entry #2"});
|
||||
await _mediator.Send(new SetFieldValueCommand {EntryId = sample2.Id, FieldName = EntryFieldName.UserName, FieldValue = "Michael321" });
|
||||
await _mediator.Send(new SetFieldValueCommand {EntryId = sample2.Id, FieldName = EntryFieldName.Password, FieldValue = "12345" });
|
||||
await _mediator.Send(new SetFieldValueCommand {EntryId = sample2.Id, FieldName = EntryFieldName.Url, FieldValue = "https://keepass.info/help/kb/testform.html" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user