public void ShouldMapToNewISet()
        {
            new PlatformSpecificMapperRegistryOverride().Initialize();
            var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);

            config.CreateMap <SourceWithIEnumerable, TargetWithISet>()
            .ForMember(dest => dest.Stuff, opt => opt.MapFrom(src => src.Stuff.Select(s => s.Value)));

            config.AssertConfigurationIsValid();

            var engine = new MappingEngine(config);

            var source = new SourceWithIEnumerable
            {
                Stuff = new[]
                {
                    new TypeWithStringProperty {
                        Value = "Microphone"
                    },
                    new TypeWithStringProperty {
                        Value = "Check"
                    },
                    new TypeWithStringProperty {
                        Value = "1, 2"
                    },
                    new TypeWithStringProperty {
                        Value = "What is this?"
                    }
                }
            };

            var target = engine.Map <SourceWithIEnumerable, TargetWithISet>(source);
        }
        private static IConfigurationProvider CreateMapperConfiguration()
        {
            var result = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);

            result.AllowNullCollections = true;
            result.CreateMap <D.ScrumTeam, ScrumTeam>();
            result.CreateMap <D.Observer, TeamMember>()
            .ForMember(m => m.Type, mc => mc.ResolveUsing((D.Observer o) => o.GetType().Name));
            result.CreateMap <D.Message, Message>()
            .Include <D.MemberMessage, MemberMessage>()
            .Include <D.EstimationResultMessage, EstimationResultMessage>()
            .ForMember(m => m.Type, mc => mc.MapFrom(m => m.MessageType));
            result.CreateMap <D.MemberMessage, MemberMessage>();
            result.CreateMap <D.EstimationResultMessage, EstimationResultMessage>();
            result.CreateMap <KeyValuePair <D.Member, D.Estimation>, EstimationResultItem>()
            .ForMember(i => i.Member, mc => mc.MapFrom(p => p.Key))
            .ForMember(i => i.Estimation, mc => mc.MapFrom(p => p.Value));
            result.CreateMap <D.EstimationParticipantStatus, EstimationParticipantStatus>();
            result.CreateMap <D.Estimation, Estimation>()
            .ForMember(e => e.Value, mc => mc.ResolveUsing(e => e.Value.HasValue && double.IsPositiveInfinity(e.Value.Value) ? Estimation.PositiveInfinity : e.Value));

            result.AssertConfigurationIsValid();

            return(result);
        }
        public static IMappingEngine CreateEngine(Profile mappingProfile)
        {
            ConfigurationStore store = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);
            store.AssertConfigurationIsValid();
            MappingEngine engine = new MappingEngine(store);

            store.AddProfile(mappingProfile);
            return engine;
        }
Exemple #4
0
        public ProjectRepository(string connectionString)
        {
            var store = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);

            store.AssertConfigurationIsValid();
            _engine = new MappingEngine(store);
            CreateMaps(store);
            _context = new DependencyGraphContext(connectionString);
        }
Exemple #5
0
        public static IMappingEngine CreateEngine(Profile mappingProfile)
        {
            ConfigurationStore store = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);

            store.AssertConfigurationIsValid();
            MappingEngine engine = new MappingEngine(store);

            store.AddProfile(mappingProfile);
            return(engine);
        }
Exemple #6
0
        private IMappingEngine CustomMappingEngine()
        {
            ConfigurationStore store  = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);
            MappingEngine      engine = new MappingEngine(store);

            store.AddProfile(new OrderToOrderMapperProfile002(engine));
            store.AllowNullDestinationValues = true;
            store.AssertConfigurationIsValid();
            return(engine);
        }
Exemple #7
0
        public DatabaseObjectsGraphRepository(string connectionString)
        {
            _connectionString = connectionString;

            var store = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);

            store.AssertConfigurationIsValid();
            _engine = new MappingEngine(store);
            CreateMaps(store);
        }
Exemple #8
0
        public static void RegisterAutoMapperType(this IUnityContainer container, LifetimeManager lifetimeManager = null)
        {
            RegisterAutoMapperProfiles(container);

            var profiles = container.ResolveAll<Profile>();
            var autoMapperConfigurationStore = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);
            profiles.Each(autoMapperConfigurationStore.AddProfile);

            autoMapperConfigurationStore.AssertConfigurationIsValid();

            container.RegisterInstance<IConfigurationProvider>(autoMapperConfigurationStore, new ContainerControlledLifetimeManager());
            container.RegisterInstance<IConfiguration>(autoMapperConfigurationStore, new ContainerControlledLifetimeManager());

            //container.RegisterType<IMappingEngine, MappingEngine>(lifetimeManager ?? new TransientLifetimeManager(), new InjectionConstructor(typeof(IConfigurationProvider)));
            container.RegisterType<IMappingEngine, MappingEngine>(lifetimeManager ?? new TransientLifetimeManager(), new InjectionConstructor(typeof(IConfigurationProvider)), new InjectionFactory(_ => Mapper.Engine));

        }
Exemple #9
0
        private static IMappingEngine ConfigureMappingEngine()
        {
            var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers());
            ApplyMap.On(config).AddFromAssemblyOf<ProductMapCreator>().Apply();
            config.AssertConfigurationIsValid();

            return new MappingEngine(config);

            // Another way, Useful if we want to reuse the
            // static Mapper class' engine or we already have it
            // spread around in our code

            //Mapper.Initialize(cfg =>
            //    ApplyMap.On(cfg).AddFromAssemblyOf<ProductMapCreator>().Apply());

            //return Mapper.Engine;
        }
Exemple #10
0
        private static IMappingEngine ConfigureMappingEngine()
        {
            var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers());

            ApplyMap.On(config).AddFromAssemblyOf <ProductMapCreator>().Apply();
            config.AssertConfigurationIsValid();

            return(new MappingEngine(config));

            // Another way, Useful if we want to reuse the
            // static Mapper class' engine or we already have it
            // spread around in our code

            //Mapper.Initialize(cfg =>
            //    ApplyMap.On(cfg).AddFromAssemblyOf<ProductMapCreator>().Apply());

            //return Mapper.Engine;
        }
Exemple #11
0
        public static void RegisterAutoMapperType(this IUnityContainer container, LifetimeManager lifetimeManager = null)
        {
            //Automate profiles
                RegisterAutomapperProfiles(container);

                //Collect all profiles in container and resolve them.
                var profiles = container.ResolveAll<Profile>();
                var autoMapperConfigurationStore = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);
                profiles.Each(autoMapperConfigurationStore.AddProfile);

                //Automapper Validate
                autoMapperConfigurationStore.AssertConfigurationIsValid();

                //Unity Injection
                container.RegisterInstance<IConfigurationProvider>(autoMapperConfigurationStore, new ContainerControlledLifetimeManager());
                container.RegisterInstance<IConfiguration>(autoMapperConfigurationStore, new ContainerControlledLifetimeManager());
                container.RegisterType<IMappingEngine, MappingEngine>(lifetimeManager ?? new TransientLifetimeManager(), new InjectionConstructor(typeof(IConfigurationProvider)));

                container.RegisterType<IStorage, MemoryStorage>();
                container.RegisterType<ICustomerRepository, CustomerRepository>();
        }
        public override void Load()
        {
            Bind<ConfigurationStore>().ToMethod(ctx =>
            {
                var factory = ctx.Kernel.Get<ITypeMapFactory>();
                var cfg = new ConfigurationStore(factory, MapperRegistry.AllMappers());
                cfg.ConstructServicesUsing(x => ctx.Kernel.Get(x));

                cfg.LoadProfiles(ctx.Kernel, Assemblies);
                cfg.AllowNullCollections = true;
                cfg.AllowNullDestinationValues = true;

                cfg.AssertConfigurationIsValid();
                return cfg;
            }).InSingletonScope();

            Bind<IConfigurationProvider>().ToBound().Get<ConfigurationStore>();
            Bind<IConfiguration>().ToBound().Get<ConfigurationStore>();
            Bind<IMappingEngine>().To<MappingEngineDelegate>();
            Bind<MappingEngine>().ToSelf();
            Bind<ITypeMapFactory>().To<TypeMapFactory>();
        }
Exemple #13
0
        public DatabaseCollector(string connectionString)
        {
            var sqlConnectionStringBuilder = new SqlConnectionStringBuilder {
                ConnectionString = connectionString
            };

            _connection = new ServerConnection(sqlConnectionStringBuilder.DataSource);
            if (!sqlConnectionStringBuilder.IntegratedSecurity)
            {
                _connection.LoginSecure = false;
                _connection.Login       = sqlConnectionStringBuilder.UserID;
                _connection.Password    = sqlConnectionStringBuilder.Password;
            }
            ;
            _server = new Server(_connection);

            // Instead of traditional Mapper.CreateMap<T1, T2>() which is global, we want instance mapping since those maps are just for this particular class
            var store = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);

            store.AssertConfigurationIsValid();
            _engine = new MappingEngine(store);
            CreateMaps(store);
        }
        public void ShouldMapToNewISet()
        {
            var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers());
            config.CreateMap<SourceWithIEnumerable, TargetWithISet>()
                  .ForMember(dest => dest.Stuff, opt => opt.MapFrom(src => src.Stuff.Select(s => s.Value)));

            config.AssertConfigurationIsValid();

            var engine = new MappingEngine(config);

            var source = new SourceWithIEnumerable
            {
                Stuff = new[]
                            {
                                new TypeWithStringProperty { Value = "Microphone" },
                                new TypeWithStringProperty { Value = "Check" },
                                new TypeWithStringProperty { Value = "1, 2" },
                                new TypeWithStringProperty { Value = "What is this?" }
                            }
            };

            var target = engine.Map<SourceWithIEnumerable, TargetWithISet>(source);
        }
Exemple #15
0
        public void ShouldMapOneToTwo()
        {
            var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers());

            config.CreateMap <One, Two>();

            config.CreateMap <IEnumerable <string>, IEnumerable <Item> >().ConvertUsing <StringToItemConverter>();

            config.AssertConfigurationIsValid();

            var engine = new MappingEngine(config);
            var one    = new One
            {
                Stuff = new List <string> {
                    "hi", "", "mom"
                }
            };

            var two = engine.Map <One, Two>(one);

            two.ShouldNotBeNull();
            two.Stuff.Count().ShouldEqual(2);
        }
 public void AssertConfigurationIsValid()
 {
     _configurationStore.AssertConfigurationIsValid();
 }
        /// <summary>
        /// Registers services for the Automapper.
        /// </summary>
        /// <param name="container">Containser interface exposing all the functionality the Windsor implements.</param>
        private static void RegisterAutoMapper(IWindsorContainer container)
        {
            container.Register(
                Component.For<IEnumerable<IObjectMapper>>().UsingFactoryMethod(() => MapperRegistry.Mappers),
                Component.For<ConfigurationStore>()
                    .LifestyleSingleton()
                    .UsingFactoryMethod(x =>
                    {
                        var typeMapFactory = x.Resolve<ITypeMapFactory>();
                        var mappers = x.Resolve<IEnumerable<IObjectMapper>>();
                        ConfigurationStore configurationStore = new ConfigurationStore(typeMapFactory, mappers);
                        configurationStore.ConstructServicesUsing(x.Resolve);
                        configurationStore.AssertConfigurationIsValid();
                        configurationStore.CreateMap<string, InfoIdentifier>().ConvertUsing<InfoIdentifierTypeConverter>();
                        configurationStore.CreateMap<string, BirthNumber>().ConvertUsing<BirthNumberTypeConverter>();
                        configurationStore.CreateMap<string, PatientName>().ConvertUsing<PatientNameTypeConverter>();
                        configurationStore.CreateMap<string, string>().ConvertUsing(c => c);
                        return configurationStore;
                    }),
                Component.For<IConfigurationProvider>().UsingFactoryMethod(x => x.Resolve<ConfigurationStore>()),
                Component.For<IConfiguration>().UsingFactoryMethod(x => x.Resolve<ConfigurationStore>()),
                Component.For<IMappingEngine>().ImplementedBy<MappingEngine>().LifestyleSingleton(),
                Component.For<ITypeMapFactory>().ImplementedBy<TypeMapFactory>()
            );

            // Add all Profiles
            var configuration = container.Resolve<IConfiguration>();
            container.ResolveAll<Profile>().ToList().ForEach(configuration.AddProfile);
        }