mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
More queries/commands
This commit is contained in:
@@ -67,6 +67,7 @@
|
|||||||
<Compile Include="Database\Queries\OpenDatabase\OpenDatabaseQueryValidator.cs" />
|
<Compile Include="Database\Queries\OpenDatabase\OpenDatabaseQueryValidator.cs" />
|
||||||
<Compile Include="Database\Queries\ReOpenDatabase\ReOpenDatabaseQuery.cs" />
|
<Compile Include="Database\Queries\ReOpenDatabase\ReOpenDatabaseQuery.cs" />
|
||||||
<Compile Include="DependencyInjection.cs" />
|
<Compile Include="DependencyInjection.cs" />
|
||||||
|
<Compile Include="Entry\Commands\SetFieldValue\SetFieldValueCommand.cs" />
|
||||||
<Compile Include="Entry\Models\EntryVm.cs" />
|
<Compile Include="Entry\Models\EntryVm.cs" />
|
||||||
<Compile Include="Group\Commands\AddEntry\AddEntryCommand.cs" />
|
<Compile Include="Group\Commands\AddEntry\AddEntryCommand.cs" />
|
||||||
<Compile Include="Group\Commands\AddGroup\AddGroupCommand.cs" />
|
<Compile Include="Group\Commands\AddGroup\AddGroupCommand.cs" />
|
||||||
@@ -80,25 +81,22 @@
|
|||||||
<Compile Include="Group\Commands\SortGroups\SortGroupsCommand.cs" />
|
<Compile Include="Group\Commands\SortGroups\SortGroupsCommand.cs" />
|
||||||
<Compile Include="Group\Models\GroupVm.cs" />
|
<Compile Include="Group\Models\GroupVm.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Resources\Queries\GetResourceQuery.cs" />
|
||||||
<Content Include="Services\CryptographyService.cs" />
|
<Content Include="Services\CryptographyService.cs" />
|
||||||
<Content Include="Services\DatabaseService.cs" />
|
<Content Include="Services\DatabaseService.cs" />
|
||||||
<Content Include="Services\FileService.cs" />
|
<Content Include="Services\FileService.cs" />
|
||||||
<Content Include="Services\ImportService.cs" />
|
<Content Include="Services\ImportService.cs" />
|
||||||
<Content Include="Services\RecentService.cs" />
|
<Content Include="Services\RecentService.cs" />
|
||||||
<Content Include="Services\ResourceService.cs" />
|
|
||||||
<Content Include="Services\SecurityService.cs" />
|
<Content Include="Services\SecurityService.cs" />
|
||||||
<Content Include="Services\SettingsService.cs" />
|
<Content Include="Services\SettingsService.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Entry\Commands\SetFieldValue\" />
|
|
||||||
<Folder Include="Entry\Queries\GetEntry\" />
|
<Folder Include="Entry\Queries\GetEntry\" />
|
||||||
<Folder Include="Group\Commands\UpdateGroup\" />
|
<Folder Include="Group\Commands\UpdateGroup\" />
|
||||||
<Folder Include="Group\Queries\GetGroup\" />
|
<Folder Include="Group\Queries\GetGroup\" />
|
||||||
<Folder Include="Parameters\Commands\SetCipher\" />
|
<Folder Include="Parameters\Commands\SetCipher\" />
|
||||||
<Folder Include="Parameters\Commands\SetCompression\" />
|
<Folder Include="Parameters\Commands\SetCompression\" />
|
||||||
<Folder Include="Parameters\Commands\SetKeyDerivation\" />
|
<Folder Include="Parameters\Commands\SetKeyDerivation\" />
|
||||||
<Folder Include="Resources\Commands\" />
|
|
||||||
<Folder Include="Resources\Queries\" />
|
|
||||||
<Folder Include="Settings\" />
|
<Folder Include="Settings\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@@ -26,8 +26,8 @@ namespace ModernKeePass.Application.Common.Interfaces
|
|||||||
|
|
||||||
Task AddEntry(string parentGroupId, string entryId);
|
Task AddEntry(string parentGroupId, string entryId);
|
||||||
Task AddGroup(string parentGroupId, string groupId);
|
Task AddGroup(string parentGroupId, string groupId);
|
||||||
Task UpdateEntry(string entryId);
|
void UpdateEntry(string entryId, string fieldName, string fieldValue);
|
||||||
Task UpdateGroup(string groupId);
|
void UpdateGroup(string groupId);
|
||||||
Task RemoveEntry(string parentGroupId, string entryId);
|
Task RemoveEntry(string parentGroupId, string entryId);
|
||||||
Task RemoveGroup(string parentGroupId, string groupId);
|
Task RemoveGroup(string parentGroupId, string groupId);
|
||||||
EntryEntity CreateEntry(string parentGroupId);
|
EntryEntity CreateEntry(string parentGroupId);
|
||||||
|
@@ -0,0 +1,35 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using MediatR;
|
||||||
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
|
using ModernKeePass.Application.Database.Queries.IsDatabaseOpen;
|
||||||
|
using ModernKeePass.Domain.Exceptions;
|
||||||
|
|
||||||
|
namespace ModernKeePass.Application.Entry.Commands.SetFieldValue
|
||||||
|
{
|
||||||
|
public class SetFieldValueCommand : IRequest
|
||||||
|
{
|
||||||
|
public string EntryId { get; set; }
|
||||||
|
public string FieldName { get; set; }
|
||||||
|
public string FieldValue { get; set; }
|
||||||
|
|
||||||
|
public class SetFieldValueCommandHandler : IAsyncRequestHandler<SetFieldValueCommand>
|
||||||
|
{
|
||||||
|
private readonly IDatabaseProxy _database;
|
||||||
|
private readonly IMediator _mediator;
|
||||||
|
|
||||||
|
public SetFieldValueCommandHandler(IDatabaseProxy database, IMediator mediator)
|
||||||
|
{
|
||||||
|
_database = database;
|
||||||
|
_mediator = mediator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Handle(SetFieldValueCommand message)
|
||||||
|
{
|
||||||
|
var isDatabaseOpen = await _mediator.Send(new IsDatabaseOpenQuery());
|
||||||
|
if (!isDatabaseOpen) throw new DatabaseClosedException();
|
||||||
|
|
||||||
|
_database.UpdateEntry(message.EntryId, message.FieldName, message.FieldValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,23 @@
|
|||||||
|
using MediatR;
|
||||||
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
|
|
||||||
|
namespace ModernKeePass.Application.Resources.Queries
|
||||||
|
{
|
||||||
|
public class GetResourceQuery: IRequest<string>
|
||||||
|
{
|
||||||
|
public string Key { get; set; }
|
||||||
|
public class GetResourceQueryHandler: IRequestHandler<GetResourceQuery, string>
|
||||||
|
{
|
||||||
|
private readonly IResourceProxy _resourceProxy;
|
||||||
|
|
||||||
|
public GetResourceQueryHandler(IResourceProxy resourceProxy)
|
||||||
|
{
|
||||||
|
_resourceProxy = resourceProxy;
|
||||||
|
}
|
||||||
|
public string Handle(GetResourceQuery message)
|
||||||
|
{
|
||||||
|
return _resourceProxy.GetResourceValue(message.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,20 +0,0 @@
|
|||||||
using ModernKeePass.Application.Common.Interfaces;
|
|
||||||
using ModernKeePass.Domain.Interfaces;
|
|
||||||
|
|
||||||
namespace ModernKeePass.Application.Services
|
|
||||||
{
|
|
||||||
public class ResourceService: IResourceService
|
|
||||||
{
|
|
||||||
private readonly IResourceProxy _resourceProxy;
|
|
||||||
|
|
||||||
public ResourceService(IResourceProxy resourceProxy)
|
|
||||||
{
|
|
||||||
_resourceProxy = resourceProxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetResourceValue(string key)
|
|
||||||
{
|
|
||||||
return _resourceProxy.GetResourceValue(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -47,6 +47,7 @@
|
|||||||
<Compile Include="Entities\EntryEntity.cs" />
|
<Compile Include="Entities\EntryEntity.cs" />
|
||||||
<Compile Include="Entities\GroupEntity.cs" />
|
<Compile Include="Entities\GroupEntity.cs" />
|
||||||
<Compile Include="Enums\CredentialStatusTypes.cs" />
|
<Compile Include="Enums\CredentialStatusTypes.cs" />
|
||||||
|
<Compile Include="Enums\EntryFieldName.cs" />
|
||||||
<Compile Include="Enums\Icon.cs" />
|
<Compile Include="Enums\Icon.cs" />
|
||||||
<Compile Include="Enums\ImportFormat.cs" />
|
<Compile Include="Enums\ImportFormat.cs" />
|
||||||
<Compile Include="Exceptions\DatabaseClosedException.cs" />
|
<Compile Include="Exceptions\DatabaseClosedException.cs" />
|
||||||
|
14
ModernKeePass.Domain/Enums/EntryFieldName.cs
Normal file
14
ModernKeePass.Domain/Enums/EntryFieldName.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace ModernKeePass.Domain.Enums
|
||||||
|
{
|
||||||
|
public class EntryFieldName
|
||||||
|
{
|
||||||
|
public const string Title = nameof(Title);
|
||||||
|
public const string UserName = nameof(UserName);
|
||||||
|
public const string Password = nameof(Password);
|
||||||
|
public const string Url = nameof(Url);
|
||||||
|
public const string Notes = nameof(Notes);
|
||||||
|
public const string Icon = nameof(Icon);
|
||||||
|
public const string ExpirationDate = nameof(ExpirationDate);
|
||||||
|
public const string HasExpirationDate = nameof(HasExpirationDate);
|
||||||
|
}
|
||||||
|
}
|
@@ -44,6 +44,7 @@
|
|||||||
<Compile Include="DependencyInjection.cs" />
|
<Compile Include="DependencyInjection.cs" />
|
||||||
<Compile Include="InfrastructureModule.cs" />
|
<Compile Include="InfrastructureModule.cs" />
|
||||||
<Compile Include="File\CsvImportFormat.cs" />
|
<Compile Include="File\CsvImportFormat.cs" />
|
||||||
|
<Compile Include="KeePass\EntryFieldMapper.cs" />
|
||||||
<Compile Include="KeePass\EntryMappingProfile.cs" />
|
<Compile Include="KeePass\EntryMappingProfile.cs" />
|
||||||
<Compile Include="KeePass\GroupMappingProfile.cs" />
|
<Compile Include="KeePass\GroupMappingProfile.cs" />
|
||||||
<Compile Include="KeePass\IconMapper.cs" />
|
<Compile Include="KeePass\IconMapper.cs" />
|
||||||
|
33
ModernKeePass.Infrastructure/KeePass/EntryFieldMapper.cs
Normal file
33
ModernKeePass.Infrastructure/KeePass/EntryFieldMapper.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using ModernKeePass.Domain.Enums;
|
||||||
|
using ModernKeePassLib;
|
||||||
|
|
||||||
|
namespace ModernKeePass.Infrastructure.KeePass
|
||||||
|
{
|
||||||
|
public static class EntryFieldMapper
|
||||||
|
{
|
||||||
|
public static string MapPwDefsToField(string value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case PwDefs.TitleField: return EntryFieldName.Title;
|
||||||
|
case PwDefs.UserNameField: return EntryFieldName.UserName;
|
||||||
|
case PwDefs.PasswordField: return EntryFieldName.Password;
|
||||||
|
case PwDefs.NotesField: return EntryFieldName.Notes;
|
||||||
|
case PwDefs.UrlField: return EntryFieldName.Url;
|
||||||
|
default: return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static string MapFieldToPwDef(string value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case EntryFieldName.Title: return PwDefs.TitleField;
|
||||||
|
case EntryFieldName.UserName: return PwDefs.UserNameField;
|
||||||
|
case EntryFieldName.Password: return PwDefs.PasswordField;
|
||||||
|
case EntryFieldName.Notes: return PwDefs.NotesField;
|
||||||
|
case EntryFieldName.Url: return PwDefs.UrlField;
|
||||||
|
default: return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -10,6 +10,7 @@ using ModernKeePassLib;
|
|||||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||||
using ModernKeePassLib.Interfaces;
|
using ModernKeePassLib.Interfaces;
|
||||||
using ModernKeePassLib.Keys;
|
using ModernKeePassLib.Keys;
|
||||||
|
using ModernKeePassLib.Security;
|
||||||
using ModernKeePassLib.Serialization;
|
using ModernKeePassLib.Serialization;
|
||||||
using ModernKeePassLib.Utility;
|
using ModernKeePassLib.Utility;
|
||||||
|
|
||||||
@@ -196,12 +197,15 @@ namespace ModernKeePass.Infrastructure.KeePass
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task UpdateEntry(string entry)
|
public void UpdateEntry(string entryId, string fieldName, string fieldValue)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var pwEntry = _pwDatabase.RootGroup.FindEntry(BuildIdFromString(entryId), true);
|
||||||
|
pwEntry.Touch(true);
|
||||||
|
pwEntry.CreateBackup(null);
|
||||||
|
pwEntry.Strings.Set(EntryFieldMapper.MapFieldToPwDef(fieldName), new ProtectedString(true, fieldValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task UpdateGroup(string group)
|
public void UpdateGroup(string group)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user