Guest User

Untitled

a guest
May 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. using System;
  2. using AutoMapper;
  3. using Microsoft.Extensions.Configuration;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Newtonsoft.Json;
  6. using Newtonsoft.Json.Linq;
  7.  
  8. namespace Core.Configuration
  9. {
  10. public class AutomapperProfileConfiguration : Profile
  11. {
  12. private readonly IConfiguration Configuration;
  13.  
  14. public AutomapperProfileConfiguration(IConfiguration configuration)
  15. {
  16. this.Configuration = configuration;
  17. var pecAckTimeoutIntervalHours = Convert.ToInt32(Configuration["AppSettings:PecAckTimeoutIntervalHours"]);
  18.  
  19. CreateMap<Sessions, Session>().ForMember(
  20. dest => dest.Invalidated,
  21. opt => opt.MapFrom(src => src.InvalidationTime));
  22.  
  23. CreateMap<DataBuckets, DataBucket<JObject>>().ForMember(
  24. dest => dest.Kind,
  25. opt => opt.MapFrom(src => src.Kind.Name))
  26. .ForMember(
  27. dest => dest.Data,
  28. opt => opt.MapFrom(src => JsonConvert.DeserializeObject<JObject>(src.Data)));
  29.  
  30. CreateMap<Files, FileInfo>().ForMember(
  31. dest => dest.ContentType,
  32. opt => opt.MapFrom(src => src.MimeType))
  33. .ForMember(
  34. dest => dest.Hash,
  35. opt => opt.MapFrom(src => Convert.ToBase64String(src.Hash)))
  36. .ForMember(
  37. dest => dest.Kind,
  38. opt => opt.MapFrom(src => ((FileKind) src.KindId).GetDescription()));
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment