2020-03-24 13:01:14 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using ModernKeePass.Domain.Entities;
|
|
|
|
|
using ModernKeePassLib;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Infrastructure.KeePass
|
|
|
|
|
{
|
|
|
|
|
public class EntryMappingProfile: Profile
|
|
|
|
|
{
|
|
|
|
|
public EntryMappingProfile()
|
|
|
|
|
{
|
|
|
|
|
CreateMap<PwEntry, EntryEntity>()
|
2020-03-31 19:19:02 +02:00
|
|
|
|
.ForMember(dest => dest.ParentId, opt => opt.MapFrom(src => src.ParentGroup.Uuid.ToHexString()))
|
2020-04-02 19:12:16 +02:00
|
|
|
|
.ForMember(dest => dest.ParentName, opt => opt.MapFrom(src => src.ParentGroup.Name))
|
2020-03-24 13:01:14 +01:00
|
|
|
|
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Uuid.ToHexString()))
|
|
|
|
|
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.TitleField)))
|
|
|
|
|
.ForMember(dest => dest.UserName, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.UserNameField)))
|
|
|
|
|
.ForMember(dest => dest.Password, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.PasswordField)))
|
2020-04-20 20:02:43 +02:00
|
|
|
|
.ForMember(dest => dest.Url, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.UrlField)))
|
2020-03-24 13:01:14 +01:00
|
|
|
|
.ForMember(dest => dest.Notes, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.NotesField)))
|
|
|
|
|
.ForMember(dest => dest.ForegroundColor, opt => opt.MapFrom(src => src.ForegroundColor))
|
|
|
|
|
.ForMember(dest => dest.BackgroundColor, opt => opt.MapFrom(src => src.BackgroundColor))
|
|
|
|
|
.ForMember(dest => dest.ExpirationDate, opt => opt.MapFrom(src => new DateTimeOffset(src.ExpiryTime)))
|
|
|
|
|
.ForMember(dest => dest.HasExpirationDate, opt => opt.MapFrom(src => src.Expires))
|
|
|
|
|
.ForMember(dest => dest.Icon, opt => opt.MapFrom(src => IconMapper.MapPwIconToIcon(src.IconId)))
|
|
|
|
|
.ForMember(dest => dest.AdditionalFields, opt => opt.MapFrom(src =>
|
2020-04-01 19:37:30 +02:00
|
|
|
|
src.Strings.Where(s => !PwDefs.GetStandardFields().Contains(s.Key))
|
|
|
|
|
.ToDictionary(s => s.Key, s => GetEntryValue(src, s.Key))))
|
2020-04-02 19:12:16 +02:00
|
|
|
|
.ForMember(dest => dest.LastModificationDate, opt => opt.MapFrom(src => new DateTimeOffset(src.LastModificationTime)));
|
2020-03-24 13:01:14 +01:00
|
|
|
|
}
|
2020-04-08 16:23:15 +02:00
|
|
|
|
|
2020-03-24 13:01:14 +01:00
|
|
|
|
private string GetEntryValue(PwEntry entry, string key) => entry.Strings.GetSafe(key).ReadString();
|
|
|
|
|
}
|
|
|
|
|
}
|