public CustomMapperAttribute(Type customMapperType)
        {
            customMapperType.ThrowIfNull("customMapperType");

            if (customMapperType.IsNotPublic)
            {
                throw new ArgumentException("Type must be public.", "customMapperType");
            }
            if (customMapperType.IsAbstract)
            {
                throw new ArgumentException("Type cannot be abstract or static.", "customMapperType");
            }
            if (!customMapperType.ImplementsInterface<ICustomMapper>())
            {
                throw new ArgumentException(String.Format("Type must implement {0}.", customMapperType.FullName), "customMapperType");
            }

            ConstructorInfo constructorInfo = customMapperType.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);

            if (constructorInfo == null)
            {
                throw new ArgumentException("Type must declare a public default constructor.", "customMapperType");
            }

            _mapper = (ICustomMapper)Activator.CreateInstance(customMapperType);
        }
Exemple #2
0
        public VehiclesController(
            ICarService carService,
            ILogger <VehiclesController> logger,
            IUriService uriService,
            ICustomMapper customMapper,
            IWebHostEnvironment appEnvironment,
            IVehicleImageRetriever vehicleImageRetriever,
            ICustomAuthorizationService authorizationService
            )
        {
            _carService            = carService;
            _logger                = logger;
            _uriService            = uriService;
            _customMapper          = customMapper;
            _appEnvironment        = appEnvironment;
            _vehicleImageRetriever = vehicleImageRetriever;

            _customAuthorizationService = authorizationService;

            // var directory = Directory.GetCurrentDirectory();
            var directory = _appEnvironment.WebRootPath;

            _logger.LogInformation($"current directory {directory}");

            var imgDirectory = $@"{directory}/{ApiRoutes.imgsPath}";

            _imgDirectory = imgDirectory;

            _logger.LogInformation($"VehiclesController _imgDirectory \n {_imgDirectory}");
        }
 public CreateQuizCommandHandler(DataContext context, IRandomStringGenerator stringGenerator,
                                 ICustomMapper customMapper)
 {
     _context         = context;
     _stringGenerator = stringGenerator;
     _customMapper    = customMapper;
 }
Exemple #4
0
 public StudentDataProcessor(IFileReader fileReader, ICustomMapper mapper, IFileWriter fileWriter, IValidator validator)
 {
     this.fileReader = fileReader;
     this.mapper     = mapper;
     this.fileWriter = fileWriter;
     this.validator  = validator;
 }
Exemple #5
0
 public RecipeController(IDataRepository <Recipe> dataRepository, IMapper mapper, ICustomMapper custumMapper, UserManager <ApplicationUser> userManager)
 {
     _dataRepository = dataRepository;
     _mapper         = mapper;
     _custumMapper   = custumMapper;
     _userManager    = userManager;
 }
 public CreateProductCommandHandler(ICustomMapper <Product, CreateProductCommand> customMapper,
                                    ICurrentUser currentUser, IProductRepository productRepository)
 {
     _customMapper      = customMapper;
     _currentUser       = currentUser;
     _productRepository = productRepository;
 }
Exemple #7
0
        public CustomMapperAttribute(Type customMapperType)
        {
            customMapperType.ThrowIfNull("customMapperType");

            if (customMapperType.IsNotPublic)
            {
                throw new ArgumentException("Type must be public.", "customMapperType");
            }
            if (customMapperType.IsAbstract)
            {
                throw new ArgumentException("Type cannot be abstract or static.", "customMapperType");
            }
            if (!customMapperType.ImplementsInterface <ICustomMapper>())
            {
                throw new ArgumentException(String.Format("Type must implement {0}.", customMapperType.FullName), "customMapperType");
            }

            ConstructorInfo constructorInfo = customMapperType.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);

            if (constructorInfo == null)
            {
                throw new ArgumentException("Type must declare a public default constructor.", "customMapperType");
            }

            _mapper = (ICustomMapper)Activator.CreateInstance(customMapperType);
        }
Exemple #8
0
        /// <summary>
        /// specify a special mapping, e.g. CLS ArrayList <=> java.util.ArrayList.
        /// </summary>
        /// <param name="clsType">the native cls type, e.g. ArrayList</param>
        /// <param name="idlType">the idl type (mapped from idl to CLS) used to describe serialisation / deserialisation, e.g. java.util.ArrayListImpl</param>
        /// <param name="mapper">the mapper, knowing how to map instances of CLS ArrayList to java.util.ArrayListImpl and in the other direction</param>
        public void AddMapping(Type clsType, Type idlType, ICustomMapper mapper)
        {
            // check that idlType implements IIdlEntity:
            if (!(ReflectionHelper.IIdlEntityType.IsAssignableFrom(idlType)))
            {
                throw new Exception("illegal type for custom mapping encountered: " + idlType.FullName);
            }
            // be aware: mapping is not bijektive, because of impl classes; however for an idl type only one
            // cls type is allowed
            if (m_mappingsIdl.ContainsKey(idlType) && (!((CustomMappingDesc)m_mappingsIdl[idlType]).ClsType.Equals(clsType)))
            {
                throw new Exception("mapping constraint violated, tried to insert another cls type " + clsType +
                                    "mapped to the idl type " + idlType);
            }

            CustomMappingDesc desc = new CustomMappingDesc(clsType, idlType, mapper);

            m_mappingsCls[clsType] = desc;
            m_mappingsIdl[idlType] = desc;
            // check for impl class attribute, if present: add impl class here too
            object[] implAttr = idlType.GetCustomAttributes(ReflectionHelper.ImplClassAttributeType, false);
            if ((implAttr != null) && (implAttr.Length > 0))
            {
                ImplClassAttribute implCl = (ImplClassAttribute)implAttr[0];
                // get the type
                Type implIdlType = Repository.GetValueTypeImplClass(implCl.ImplClass);
                if (implIdlType != null)   // if impl type not found, (test needed e.g. when called from CLSToIDLGen)
                {
                    CustomMappingDesc descImpl = new CustomMappingDesc(clsType, implIdlType, mapper);
                    m_mappingsIdl[implIdlType] = descImpl;
                }
            }
        }
 public StudentDataProcessorBuilder()
 {
     this.fileReader = Substitute.For <IFileReader>();
     this.mapper     = Substitute.For <ICustomMapper>();
     this.fileWriter = Substitute.For <IFileWriter>();
     this.validator  = Substitute.For <IValidator>();
 }
Exemple #10
0
 public DomainBase(IServiceProvider serviceProvider)
 {
     Logger             = serviceProvider.GetService <IAppLogger <T> >();
     SessionManager     = serviceProvider.GetService <ISessionManager>();
     Mapper             = serviceProvider.GetService <ICustomMapper>();
     DatabaseUnitOfWork = serviceProvider.GetService <IDatabaseUnitOfWork>();
 }
Exemple #11
0
 public CreateQuestionCommandHandler(DataContext context, ICustomMapper customMapper,
                                     IUploadFiles uploadFiles, IDocumentsUrl documentsUrl)
 {
     _context      = context;
     _customMapper = customMapper;
     _uploadFiles  = uploadFiles;
     _documentsUrl = documentsUrl;
 }
Exemple #12
0
 public UserService(
     IUserManager <User> userManager,
     IUserRepository userRepository,
     ICustomMapper customMapper)
 {
     this.userManager    = userManager;
     this.userRepository = userRepository;
     this.customMapper   = customMapper;
 }
 public IdentityController(
     IIdentityService identityService,
     ILogger <IdentityController> logger,
     ICustomMapper customMapper)
 {
     _identityService = identityService;
     _logger          = logger;
     _customMapper    = customMapper;
 }
 public CarOwnersController(
     ICarOwnerService carOwnerService,
     ILogger <VehiclesController> logger,
     IUriService uriService,
     ICustomMapper customMapper)
 {
     _carOwnerService = carOwnerService;
     _logger          = logger;
     _uriService      = uriService;
     _customMapper    = customMapper;
 }
Exemple #15
0
 public OrderService(
     IOrderRepository orderRepository,
     IProductRepository productRepository,
     IOrderFactory orderFactory,
     ICustomMapper customMapper)
 {
     this.orderRepository   = orderRepository;
     this.productRepository = productRepository;
     this.orderFactory      = orderFactory;
     this.customMapper      = customMapper;
 }
Exemple #16
0
 public RecipeHelperController(IDataRepository <Recipe> dataRepository,
                               IDataRepositoryTokenis <RecipeTokenLookUP> tokenRepository,
                               ICustomMapper custumMapper,
                               UserManager <ApplicationUser> userManager,
                               IDataRepository <Country> countryRepository)
 {
     _dataRepository    = dataRepository;
     _tokenRepository   = tokenRepository;
     _custumMapper      = custumMapper;
     _userManager       = userManager;
     _countryRepository = countryRepository;
 }
Exemple #17
0
 public ProductService(
     IProductRepository productRepository,
     ICategoryRepository categoryRepository,
     IPictureRepository pictureRepository,
     IProductFactory productFactory,
     ICustomMapper customMapper)
 {
     this.productRepository  = productRepository;
     this.categoryRepository = categoryRepository;
     this.pictureRepository  = pictureRepository;
     this.productFactory     = productFactory;
     this.customMapper       = customMapper;
 }
Exemple #18
0
 public PenaltyController(
     IPenaltyRepository penaltyRepository,
     ILogger <PenaltyController> logger,
     ICustomAuthorizationService customAuthorizationService,
     ICustomMapper customMapper,
     ICarService carService
     )
 {
     _penaltyRepository          = penaltyRepository;
     _logger                     = logger;
     _customAuthorizationService = customAuthorizationService;
     _customMapper               = customMapper;
     _carService                 = carService;
 }
Exemple #19
0
 public ShoppingCartService(
     ILogger <IShoppingCartService> logger,
     IShoppingCartRepository shoppingCartRepository,
     IProductRepository productRepository,
     IPictureRepository pictureRepository,
     IShoppingCartFactory shoppingCartFactory,
     ICustomMapper customMapper)
 {
     this.logger = logger;
     this.shoppingCartRepository = shoppingCartRepository;
     this.productRepository      = productRepository;
     this.pictureRepository      = pictureRepository;
     this.shoppingCartFactory    = shoppingCartFactory;
     this.customMapper           = customMapper;
 }
 public CategoryService(
     ICategoryFactory factory,
     ICategoryRepository repository,
     IProductRepository productRepository,
     IPictureRepository pictureRepository,
     IProductService productService,
     ICustomMapper customMapper)
 {
     this.factory            = factory;
     this.categoryRepository = repository;
     this.productRepository  = productRepository;
     this.pictureRepository  = pictureRepository;
     this.productService     = productService;
     this.customMapper       = customMapper;
 }
Exemple #21
0
        public void Test_map_From_recipeVieModel_To_recipe()
        {
            RecipeViewModel acctual = new MockDBHandler().buildMockRecipeView();
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                _custumMapper = new CustomMapper(context);

                //Act
                var recipDes = _custumMapper.Map(acctual);
                var expected = _custumMapper.Map(recipDes);

                // Assert
                Assert.True(expected.Equals(acctual));
            }
        }
Exemple #22
0
        /// <summary>
        /// takes an instance deserialised from a cdr stream and maps it to the instance
        /// used in .NET. The mapped instance must be assignable to formalSig.
        /// </summary>
        /// <remarks>
        /// Custom mapping must be present; otherwise an exception is thrown.
        /// </remarks>
        public object CreateClsForIdlInstance(object idlInstance, Type formalSig)
        {
            // for subtype of idl formal support, get acutal mapping
            CustomMappingDesc actualMapping = GetMappingForIdl(idlInstance.GetType());

            if (actualMapping == null)
            {
                throw new BAD_PARAM(12309, CompletionStatus.Completed_MayBe);
            }
            ICustomMapper mapper = actualMapping.Mapper;
            object        result = mapper.CreateClsForIdlInstance(idlInstance);

            // check, if mapped instance is assignable to formal in CLS signature -> otherwise will not work.
            if (!formalSig.IsAssignableFrom(result.GetType()))
            {
                throw new BAD_PARAM(12311, CompletionStatus.Completed_MayBe);
            }
            return(result);
        }
Exemple #23
0
        /// <summary>
        /// adds special mappings from a config stream
        /// </summary>
        public void AddMappingFromStream(Stream configStream)
        {
            // check schema ok
            if (m_mappingPluginSchema == null)
            {
                configStream.Close();
                throw new Exception("schema loading problem");
            }
            XmlDocument       doc      = new XmlDocument();
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.ValidationType = ValidationType.Schema;
            settings.Schemas.Add(m_mappingPluginSchema);
            XmlReader validatingReader = XmlReader.Create(configStream, settings);

            try {
                doc.Load(validatingReader);
                // process the file
                XmlNodeList elemList = doc.GetElementsByTagName("mapping");
                foreach (XmlNode elem in elemList)
                {
                    XmlElement idlTypeName      = elem["idlTypeName"];
                    XmlElement idlTypeAsm       = elem["idlTypeAssembly"];
                    XmlElement clsTypeAsqName   = elem["clsType"];
                    XmlElement customMapperElem = elem["customMapper"];
                    // idlType:
                    String asmQualIdlName = idlTypeName.InnerText + "," + idlTypeAsm.InnerText;
                    Type   idlType        = Type.GetType(asmQualIdlName, true);
                    // clsType:
                    Type clsType = Type.GetType(clsTypeAsqName.InnerText, true);
                    // custom Mapper:
                    ICustomMapper customMapper = null;
                    if (customMapperElem != null)
                    {
                        Type customMapperType = Type.GetType(customMapperElem.InnerText, true);
                        customMapper = (ICustomMapper)Activator.CreateInstance(customMapperType);
                    }
                    AddMapping(clsType, idlType, customMapper);
                }
            } finally {
                validatingReader.Close();
            }
        }
Exemple #24
0
        /// <summary>
        /// takes a .NET instance and maps it to the instance, which should be serialised into
        /// the CDR stream. The mapped instance must be assignable to the formal type specified in idl.
        /// </summary>
        /// <remarks>
        /// Custom mapping must be present; otherwise an exception is thrown.
        /// </remarks>
        public object CreateIdlForClsInstance(object clsInstance, Type formal)
        {
            // for subtypes support (subtypes of formal before cls to idl mapping; new formal is idl formal)
            CustomMappingDesc actualMapping =
                GetMappingForCls(clsInstance.GetType());

            if (actualMapping == null)
            {
                throw new BAD_PARAM(12308, CompletionStatus.Completed_MayBe);
            }
            ICustomMapper mapper = actualMapping.Mapper;
            object        actual = mapper.CreateIdlForClsInstance(clsInstance);

            // check, if mapped is instance is assignable to formal -> otherwise will not work on other side ...
            if (!formal.IsAssignableFrom(actual.GetType()))
            {
                throw new BAD_PARAM(12310, CompletionStatus.Completed_MayBe);
            }
            return(actual);
        }
Exemple #25
0
        public void Test_map_From_recipe_To_recipeVieModel()
        {
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                _custumMapper = new CustomMapper(context);
                var acctual = context.Recipe.Include(y => y.Category)
                              .Include(r => r.Country)
                              .Include(w => w.Ingredients)
                              .FirstOrDefaultAsync().Result;
                acctual.Ingredients = context.RecipeIngredient.Include(x => x.Ingredient).Include(y => y.Unit).Where(T => T.RecipeID == acctual.ID).ToList();

                //Act
                var recipDes = _custumMapper.Map(acctual);
                var expected = _custumMapper.Map(recipDes);

                // Assert
                Assert.True(expected.Equals(acctual));
            }
        }
        public static IPagedList <TResult> ToMappedPagedList <TSource, TResult>(this IPagedList <TSource> list, ICustomMapper <TSource, TResult> mapper) where TSource : class
        {
            var sourceList = mapper.Map(list);

            return(new StaticPagedList <TResult>(sourceList, list.GetMetaData()));
        }
Exemple #27
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="clsType"></param>
 /// <param name="idlType"></param>
 /// <param name="mapper"></param>
 /// <remarks>precondition: clsType != null, idlType != null, mapper != null</remarks>
 public CustomMappingDesc(Type clsType, Type idlType, ICustomMapper mapper)
 {
     m_clsType = clsType;
     m_idlType = idlType;
     m_mapper  = mapper;
 }
 public StudentDataProcessorBuilder WithMapper(ICustomMapper mapper)
 {
     this.mapper = mapper;
     return(this);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="clsType"></param>
 /// <param name="idlType"></param>
 /// <param name="mapper"></param>
 /// <remarks>precondition: clsType != null, idlType != null, mapper != null</remarks>
 public CustomMappingDesc(Type clsType, Type idlType, ICustomMapper mapper) {
     m_clsType = clsType;
     m_idlType = idlType;
     m_mapper = mapper;
 }
        /// <summary>
        /// specify a special mapping, e.g. CLS ArrayList <=> java.util.ArrayList.
        /// </summary>
        /// <param name="clsType">the native cls type, e.g. ArrayList</param>
        /// <param name="idlType">the idl type (mapped from idl to CLS) used to describe serialisation / deserialisation, e.g. java.util.ArrayListImpl</param>
        /// <param name="mapper">the mapper, knowing how to map instances of CLS ArrayList to java.util.ArrayListImpl and in the other direction</param>
        public void AddMapping(Type clsType, Type idlType, ICustomMapper mapper) {
            // check that idlType implements IIdlEntity:
            if (!(ReflectionHelper.IIdlEntityType.IsAssignableFrom(idlType))) {
                throw new Exception("illegal type for custom mapping encountered: " + idlType.FullName);
            }
            // be aware: mapping is not bijektive, because of impl classes; however for an idl type only one
            // cls type is allowed
            if (m_mappingsIdl.ContainsKey(idlType) && (!((CustomMappingDesc)m_mappingsIdl[idlType]).ClsType.Equals(clsType))) {
                throw new Exception("mapping constraint violated, tried to insert another cls type " + clsType +
                                     "mapped to the idl type " + idlType);
            }

            CustomMappingDesc desc = new CustomMappingDesc(clsType, idlType, mapper);
            m_mappingsCls[clsType] = desc;
            m_mappingsIdl[idlType] = desc;
            // check for impl class attribute, if present: add impl class here too
            object[] implAttr = idlType.GetCustomAttributes(ReflectionHelper.ImplClassAttributeType, false);
            if ((implAttr != null) && (implAttr.Length > 0)) {
                ImplClassAttribute implCl = (ImplClassAttribute) implAttr[0];
                // get the type
                Type implIdlType = Repository.GetValueTypeImplClass(implCl.ImplClass);
                if (implIdlType != null) { // if impl type not found, (test needed e.g. when called from CLSToIDLGen)
                    CustomMappingDesc descImpl = new CustomMappingDesc(clsType, implIdlType, mapper);
                    m_mappingsIdl[implIdlType] = descImpl;
                }
            }
        }
 public HomeController(IWeatherService weatherService, ICustomMapper mapper)
 {
     _weatherService = weatherService;
     _mapper         = mapper;
 }
 public EditQuizCommandHandler(DataContext context, ICustomMapper customMapper)
 {
     _context      = context;
     _customMapper = customMapper;
 }
Exemple #33
0
 public GenericManager(IGenericRepository <T> genericRepository, IMapper mapper, ICustomMapper customMapper)
 {
     this.genericRepository = genericRepository;
     this.mapper            = mapper;
     this.customMapper      = customMapper;
 }