mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Code cleanup (bis)
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ModernKeePass.Application.Common.Interfaces
|
namespace ModernKeePass.Application.Common.Interfaces
|
||||||
{
|
{
|
||||||
public interface IImportFormat
|
public interface IImportFormat
|
||||||
{
|
{
|
||||||
Task<List<Dictionary<string, string>>> Import(IList<string> fileContents);
|
List<Dictionary<string, string>> Import(IList<string> fileContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ModernKeePass.Application.Common.Interfaces;
|
using ModernKeePass.Application.Common.Interfaces;
|
||||||
|
|
||||||
namespace ModernKeePass.Infrastructure.File
|
namespace ModernKeePass.Infrastructure.File
|
||||||
@@ -10,7 +9,7 @@ namespace ModernKeePass.Infrastructure.File
|
|||||||
private const char Delimiter = ';';
|
private const char Delimiter = ';';
|
||||||
private const char LineDelimiter = '\n';
|
private const char LineDelimiter = '\n';
|
||||||
|
|
||||||
public async Task<List<Dictionary<string, string>>> Import(IList<string> fileContents)
|
public List<Dictionary<string, string>> Import(IList<string> fileContents)
|
||||||
{
|
{
|
||||||
var parsedResult = new List<Dictionary<string, string>>();
|
var parsedResult = new List<Dictionary<string, string>>();
|
||||||
foreach (var line in fileContents)
|
foreach (var line in fileContents)
|
||||||
|
@@ -3,19 +3,12 @@ using System.Linq;
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using ModernKeePass.Domain.Entities;
|
using ModernKeePass.Domain.Entities;
|
||||||
using ModernKeePassLib;
|
using ModernKeePassLib;
|
||||||
using ModernKeePassLib.Security;
|
|
||||||
|
|
||||||
namespace ModernKeePass.Infrastructure.KeePass
|
namespace ModernKeePass.Infrastructure.KeePass
|
||||||
{
|
{
|
||||||
public class EntryMappingProfile: Profile
|
public class EntryMappingProfile: Profile
|
||||||
{
|
{
|
||||||
public EntryMappingProfile()
|
public EntryMappingProfile()
|
||||||
{
|
|
||||||
FromModelToDto();
|
|
||||||
FromDtoToModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FromDtoToModel()
|
|
||||||
{
|
{
|
||||||
Uri url;
|
Uri url;
|
||||||
CreateMap<PwEntry, EntryEntity>()
|
CreateMap<PwEntry, EntryEntity>()
|
||||||
@@ -43,39 +36,6 @@ namespace ModernKeePass.Infrastructure.KeePass
|
|||||||
.ForMember(dest => dest.LastModificationDate, opt => opt.MapFrom(src => new DateTimeOffset(src.LastModificationTime)));
|
.ForMember(dest => dest.LastModificationDate, opt => opt.MapFrom(src => new DateTimeOffset(src.LastModificationTime)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FromModelToDto()
|
|
||||||
{
|
|
||||||
CreateMap<EntryEntity, PwEntry>().ConvertUsing<EntryToPwEntryDictionaryConverter>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetEntryValue(PwEntry entry, string key) => entry.Strings.GetSafe(key).ReadString();
|
private string GetEntryValue(PwEntry entry, string key) => entry.Strings.GetSafe(key).ReadString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EntryToPwEntryDictionaryConverter : ITypeConverter<EntryEntity, PwEntry>
|
|
||||||
{
|
|
||||||
public PwEntry Convert(EntryEntity source, PwEntry destination, ResolutionContext context)
|
|
||||||
{
|
|
||||||
//destination.Uuid = new PwUuid(System.Convert.FromBase64String(source.Id));
|
|
||||||
destination.ExpiryTime = source.ExpirationDate.DateTime;
|
|
||||||
destination.Expires = source.HasExpirationDate;
|
|
||||||
destination.LastModificationTime = source.LastModificationDate.DateTime;
|
|
||||||
destination.BackgroundColor = source.BackgroundColor;
|
|
||||||
destination.ForegroundColor = source.ForegroundColor;
|
|
||||||
destination.IconId = IconMapper.MapIconToPwIcon(source.Icon);
|
|
||||||
SetEntryValue(destination, PwDefs.TitleField, source.Name);
|
|
||||||
SetEntryValue(destination, PwDefs.UserNameField, source.UserName);
|
|
||||||
SetEntryValue(destination, PwDefs.PasswordField, source.Password);
|
|
||||||
SetEntryValue(destination, PwDefs.UrlField, source.Url?.ToString());
|
|
||||||
SetEntryValue(destination, PwDefs.NotesField, source.Notes);
|
|
||||||
foreach (var additionalField in source.AdditionalFields)
|
|
||||||
{
|
|
||||||
SetEntryValue(destination, additionalField.Key, additionalField.Value);
|
|
||||||
}
|
|
||||||
return destination;
|
|
||||||
}
|
|
||||||
private void SetEntryValue(PwEntry entry, string key, string newValue)
|
|
||||||
{
|
|
||||||
if (newValue != null) entry.Strings.Set(key, new ProtectedString(true, newValue));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -7,12 +7,6 @@ namespace ModernKeePass.Infrastructure.KeePass
|
|||||||
public class GroupMappingProfile : Profile
|
public class GroupMappingProfile : Profile
|
||||||
{
|
{
|
||||||
public GroupMappingProfile()
|
public GroupMappingProfile()
|
||||||
{
|
|
||||||
FromModelToDto();
|
|
||||||
FromDtoToModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FromDtoToModel()
|
|
||||||
{
|
{
|
||||||
CreateMap<PwGroup, GroupEntity>()
|
CreateMap<PwGroup, GroupEntity>()
|
||||||
.ForMember(d => d.ParentId, opts => opts.MapFrom(s => s.ParentGroup.Uuid.ToHexString()))
|
.ForMember(d => d.ParentId, opts => opts.MapFrom(s => s.ParentGroup.Uuid.ToHexString()))
|
||||||
@@ -25,9 +19,5 @@ namespace ModernKeePass.Infrastructure.KeePass
|
|||||||
.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.Groups))
|
.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.Groups))
|
||||||
.MaxDepth(2);
|
.MaxDepth(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FromModelToDto()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -23,6 +23,8 @@ namespace ModernKeePass.Infrastructure.KeePass
|
|||||||
private readonly IDateTime _dateTime;
|
private readonly IDateTime _dateTime;
|
||||||
private readonly PwDatabase _pwDatabase = new PwDatabase();
|
private readonly PwDatabase _pwDatabase = new PwDatabase();
|
||||||
private Credentials _credentials;
|
private Credentials _credentials;
|
||||||
|
// Flag: Has Dispose already been called?
|
||||||
|
private bool _disposed;
|
||||||
|
|
||||||
public string ZeroId => PwUuid.Zero.ToHexString();
|
public string ZeroId => PwUuid.Zero.ToHexString();
|
||||||
|
|
||||||
@@ -317,7 +319,22 @@ namespace ModernKeePass.Infrastructure.KeePass
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (IsOpen) CloseDatabase();
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Protected implementation of Dispose pattern.
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (_disposed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
_pwDatabase.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
_disposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user