public async Task Handle(OpenDatabaseQuery message) { if (_database.IsDirty) { throw new DatabaseOpenException(); } var file = await _file.ReadBinaryFile(message.FilePath); var hasKeyFile = !string.IsNullOrEmpty(message.KeyFilePath); await _database.Open(file, new Credentials { KeyFileContents = hasKeyFile ? await _file.ReadBinaryFile(message.KeyFilePath): null, Password = message.Password }); if (hasKeyFile) { _file.ReleaseFile(message.KeyFilePath); } _database.Size = file.Length; _database.FileAccessToken = message.FilePath; }
public async Task Handle(ReOpenDatabaseQuery message) { if (_database.IsOpen) { throw new DatabaseOpenException(); } if (string.IsNullOrEmpty(_database.FileAccessToken)) { throw new DatabaseClosedException(); } var file = await _file.ReadBinaryFile(_database.FileAccessToken); await _database.ReOpen(file); }
private async Task AddAttachment() { var fileInfo = await _file.OpenFile(string.Empty, Domain.Common.Constants.Extensions.Any, false); if (fileInfo == null) { return; } var contents = await _file.ReadBinaryFile(fileInfo.Id); await _mediator.Send(new AddAttachmentCommand { Entry = _current, AttachmentName = fileInfo.Name, AttachmentContent = contents }); Attachments.Add(new Attachment { Name = fileInfo.Name, Content = contents }); }
public async Task Handle(UpdateCredentialsCommand message) { if (!_database.IsOpen) { throw new DatabaseClosedException(); } _database.UpdateCredentials(new Credentials { KeyFileContents = !string.IsNullOrEmpty(message.KeyFilePath) ? await _file.ReadBinaryFile(message.KeyFilePath) : null, Password = message.Password }); }
public async Task Handle(CreateDatabaseCommand message) { if (_database.IsDirty) { throw new DatabaseOpenException(); } var version = DatabaseVersion.V2; switch (message.Version) { case "4": version = DatabaseVersion.V4; break; case "3": version = DatabaseVersion.V3; break; } await _database.Create(new Credentials { KeyFileContents = !string.IsNullOrEmpty(message.KeyFilePath) ? await _file.ReadBinaryFile(message.KeyFilePath) : null, Password = message.Password }, message.Name, version); _database.FileAccessToken = message.FilePath; if (message.CreateSampleData) { var bankingGroup = _database.CreateGroup(_database.RootGroupId, "Banking"); bankingGroup.Icon = Icon.Shop; _database.UpdateGroup(bankingGroup); var emailGroup = _database.CreateGroup(_database.RootGroupId, "Email"); emailGroup.Icon = Icon.Mail; _database.UpdateGroup(emailGroup); var internetGroup = _database.CreateGroup(_database.RootGroupId, "Internet"); internetGroup.Icon = Icon.World; _database.UpdateGroup(internetGroup); var sample1 = _database.CreateEntry(_database.RootGroupId); await _database.UpdateEntry(sample1.Id, EntryFieldName.Title, "Sample Entry", false); await _database.UpdateEntry(sample1.Id, EntryFieldName.UserName, "Username", false); await _database.UpdateEntry(sample1.Id, EntryFieldName.Password, "Password", true); await _database.UpdateEntry(sample1.Id, EntryFieldName.Url, "https://keepass.info/", false); await _database.UpdateEntry(sample1.Id, EntryFieldName.Notes, "You may safely delete this sample", false); var sample2 = _database.CreateEntry(_database.RootGroupId); await _database.UpdateEntry(sample2.Id, EntryFieldName.Title, "Sample Entry #2", false); await _database.UpdateEntry(sample2.Id, EntryFieldName.UserName, "Michael321", false); await _database.UpdateEntry(sample2.Id, EntryFieldName.Password, "12345", true); await _database.UpdateEntry(sample2.Id, EntryFieldName.Url, "https://keepass.info/help/kb/testform.html", false); } }