Files
modernkeepass/ModernKeePass/ViewModels/NewVm.cs

99 lines
4.7 KiB
C#
Raw Normal View History

using System.Threading.Tasks;
using Windows.Storage;
using MediatR;
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.Domain.Enums;
2018-09-07 18:16:40 +02:00
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
2018-09-07 18:16:40 +02:00
namespace ModernKeePass.ViewModels
{
public class NewVm : OpenVm
{
private readonly IMediator _mediator;
private readonly ISettingsService _settings;
2018-09-10 17:29:52 +02:00
private string _importFormatHelp;
public string Password { get; set; }
2018-09-07 18:16:40 +02:00
public bool IsImportChecked { get; set; }
public IStorageFile ImportFile { get; set; }
2018-09-10 17:29:52 +02:00
public string ImportFileExtensionFilter { get; set; } = "*";
2018-09-07 18:16:40 +02:00
public IFormat ImportFormat { get; set; }
2018-09-10 17:29:52 +02:00
public string ImportFormatHelp
{
get { return _importFormatHelp; }
set
{
_importFormatHelp = value;
OnPropertyChanged(nameof(ImportFormatHelp));
}
}
public NewVm(): this(App.Mediator, new SettingsService()) { }
public NewVm(IMediator mediator, ISettingsService settings)
{
_mediator = mediator;
_settings = settings;
}
public async Task<Application.Group.Models.GroupVm> PopulateInitialData()
2018-09-07 18:16:40 +02:00
{
var database = await _mediator.Send(new GetDatabaseQuery());
if (_settings.GetSetting<bool>("Sample") && !IsImportChecked) await CreateSampleData(database.RootGroup);
return database.RootGroup;
2018-09-07 18:16:40 +02:00
}
private async Task CreateSampleData(Application.Group.Models.GroupVm group)
2018-09-07 18:16:40 +02:00
{
/*var converter = new IntToSymbolConverter();
2018-09-10 17:29:52 +02:00
var bankingGroup = group.AddNewGroup("Banking");
bankingGroup.Icon = (int)converter.ConvertBack(Symbol.Calculator, null, null, string.Empty);
2018-09-07 18:16:40 +02:00
2018-09-10 17:29:52 +02:00
var emailGroup = group.AddNewGroup("Email");
emailGroup.Icon = (int)converter.ConvertBack(Symbol.Mail, null, null, string.Empty);
2018-09-07 18:16:40 +02:00
2018-09-10 17:29:52 +02:00
var internetGroup = group.AddNewGroup("Internet");
internetGroup.Icon = (int)converter.ConvertBack(Symbol.World, null, null, string.Empty);
2018-09-07 18:16:40 +02:00
2018-09-10 17:29:52 +02:00
var sample1 = group.AddNewEntry();
sample1.Title = "Sample Entry";
2018-09-07 18:16:40 +02:00
sample1.UserName = "Username";
sample1.Url = PwDefs.HomepageUrl;
sample1.Password = "Password";
sample1.Notes = "You may safely delete this sample";
2018-09-10 17:29:52 +02:00
var sample2 = group.AddNewEntry();
sample2.Title = "Sample Entry #2";
2018-09-07 18:16:40 +02:00
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" });
2018-09-07 18:16:40 +02:00
}
}
}