Lc_AutoMapperProfile.cs 2.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
using FLY.Thick.Blowing.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FLY.FeedbackRenZiJia.Server.Model
{
    /// <summary>
    /// LC 与 DB 类的映射关系, 会在程序入口处, 手动使用 
    /// var assemblies = System.AppDomain.CurrentDomain.GetAssemblies();
    /// var cfg = new MapperConfigurationExpression();
    /// cfg.AddMaps(assemblies);
    /// Mapper.Initialize(cfg);
    /// 
    /// 枚举全部程序集 中的AutoMapper.Profile 全部加载!!!
    /// </summary>
    public class Lc_AutoMapperProfile : AutoMapper.Profile
    {
        /// <summary>
        /// 
        /// </summary>
        public static AutoMapper.IMapper Mapper;
        static Lc_AutoMapperProfile()
        {
            var cfg = new AutoMapper.Configuration.MapperConfigurationExpression();
            cfg.AddProfile<Lc_AutoMapperProfile>();
            AutoMapper.MapperConfiguration config = new AutoMapper.MapperConfiguration(cfg);
            Mapper = new AutoMapper.Mapper(config);
        }

        public Lc_AutoMapperProfile()
        {

            CreateMap<Lc_ThickHeat, Db_ThickHeat>()
                .ForMember(s => s.RPeriod, opt =>
                {
39
                    opt.MapFrom(s => Math.Round(s.RPeriod.TotalMinutes,2));
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
                })
                .ForMember(s => s.Thicks, opt =>
                {
                    opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.Thicks));
                })
                .ForMember(s => s.Boltmap, opt =>
                {
                    opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.Boltmap));
                })
                .ForMember(s => s.Heats, opt =>
                {
                    opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.Heats));
                })
            .ReverseMap()
                .ForMember(s => s.RPeriod, opt =>
                {
                    opt.MapFrom(s => TimeSpan.FromMinutes(s.RPeriod));
                })
                .ForMember(s => s.Thicks, opt =>
                {
                    opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<double[]>(s.Thicks));
                })
                .ForMember(s => s.Boltmap, opt =>
                {
                    opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<List<BoltMapCell>>(s.Boltmap));
                })
                .ForMember(s => s.Heats, opt =>
                {
                    opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<int[]>(s.Heats));
                });



        }
    }
}