You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Profiler.cs 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using AutoMapper;
  2. using PuppeteerSharp;
  3. using BlackRock.Reporting.API.Core.Models;
  4. using BlackRock.Reporting.API.Models;
  5. using BlackRock.Reporting.API.Mediator.Model;
  6. using BlackRock.Reporting.API.Controllers.Dto;
  7. namespace BlackRock.Reporting.API.Profiles
  8. {
  9. public class Profiler : Profile
  10. {
  11. public Profiler()
  12. {
  13. CreateMap<OptionsForPdf, PdfOptions>().ConvertUsing<OptionsForPdfConverter>();
  14. CreateMap<User, UserDto>().ReverseMap();
  15. CreateMap<User, UserCommand>().ReverseMap();
  16. }
  17. }
  18. public class OptionsForPdfConverter : ITypeConverter<OptionsForPdf, PdfOptions>
  19. {
  20. public PdfOptions Convert(OptionsForPdf source, PdfOptions destination, ResolutionContext context)
  21. {
  22. if (source == null) return destination;
  23. if (destination == null)
  24. destination = new PdfOptions();
  25. destination.DisplayHeaderFooter = source.DisplayHeaderFooter;
  26. destination.HeaderTemplate = source.HeaderTemplate;
  27. destination.Height = source.Height;
  28. destination.Landscape = source.Landscape;
  29. destination.OmitBackground = source.OmitBackground;
  30. destination.PageRanges = source.PageRanges;
  31. destination.PreferCSSPageSize = source.PreferCSSPageSize;
  32. destination.PrintBackground = source.PrintBackground;
  33. destination.Scale = source.Scale;
  34. destination.Width = source.Width;
  35. destination.MarginOptions = new PuppeteerSharp.Media.MarginOptions()
  36. {
  37. Bottom = source.MarginBottom,
  38. Top = source.MarginTop,
  39. Right = source.MarginRight,
  40. Left = source.MarginLeft
  41. };
  42. switch (source.PaperFormatType)
  43. {
  44. case PaperFormatType.A4:
  45. destination.Format = PuppeteerSharp.Media.PaperFormat.A4;
  46. break;
  47. case PaperFormatType.A3:
  48. destination.Format = PuppeteerSharp.Media.PaperFormat.A3;
  49. break;
  50. case PaperFormatType.Letter:
  51. destination.Format = PuppeteerSharp.Media.PaperFormat.Letter;
  52. break;
  53. }
  54. return destination;
  55. }
  56. }
  57. }