예제 #1
0
        /// <summary>
        /// Queues a request to create an IMapper.
        /// </summary>
        /// <param name="mapperRequest"></param>
        /// <returns>The 'true' key present in the dictionary. This will be the key given if no previous matching registration has occured.</returns>

        public IAutoMapperRequestKeyGen RegisterAutoMapperRequest(IAutoMapperRequestKeyGen mapperRequest)
        {
            IAutoMapperRequestKeyGen result;

            if (_sealedAutoMappers.ContainsKey(mapperRequest))
            {
                //ICollection<IAutoMapperRequestKeyGen> keys = _sealedAutoMappers.Keys;

                //// TODO: This is relatively resource intensive, perhaps there's a better way.
                //IAutoMapperRequestKeyGen existingKey = keys.FirstOrDefault(x => x.DestinationTypeGenDef.Equals(autoMapperRequestKeyGen.DestinationTypeGenDef));

                //if(!ReferenceEquals(existingKey, autoMapperRequestKeyGen))
                //{
                //    System.Diagnostics.Debug.WriteLine("The mapRequest given to RegisterRawAutoMapperRequest was not the original key.");
                //}
                //result = existingKey;
                result = mapperRequest;
            }
            else
            {
                _unSealedAutoMappers.GetOrAdd(mapperRequest);
                result = mapperRequest;
            }

            return(result);
        }
예제 #2
0
        public IMapper GetAutoMapper(IAutoMapperRequestKeyGen mapperRequest)
        {
            IAutoMapperRequestKeyGen save = mapperRequest;

            if (_sealedAutoMappers.TryGetValue(mapperRequest, out IMapper result))
            {
                CheckForChanges(save, mapperRequest, "Find in Sealed -- First Check.");
                return(result);
            }

            _unSealedAutoMappers.GetOrAdd(mapperRequest);
            CheckForChanges(save, mapperRequest, "GetOrAdd to UnSealed");

            // Seal all pending mapper requests.
            int numberInThisBatch = SealThis(pCntr++);

            CheckForChanges(save, mapperRequest, "Seal");

            if (!_sealedAutoMappers.TryGetValue(mapperRequest, out result))
            {
                CheckForChanges(save, mapperRequest, "Find in Sealed -- second check.");
                result = null;
            }

            return(result);
        }
예제 #3
0
        // Typed Submit Raw Auto
        public IAutoMapperRequestKey <TSource, TDestination> SubmitRawAutoMapperRequest <TSource, TDestination>
        (
            IMapTypeDefinition srcMapTypeDef,
            IMapTypeDefinition dstMapTypeDef,
            IAutoMapperConfigDetails configuationDetails,
            IConfigureAMapper <TSource, TDestination> mappingConfiguration,
            IHaveAMapperConfigurationStep configStarterForThisRequest
        )
        {
            // Create a MapperBuilder for this request.
            IAutoMapperBuilder <TSource, TDestination> autoMapperBuilder
                = BuildTheAutoMapperBuilder <TSource, TDestination>(configStarterForThisRequest);

            // Create the mapper request.
            IAutoMapperRequestKey <TSource, TDestination> autoMapperRequestKey
                = new AutoMapperRequestKey <TSource, TDestination>
                  (
                      sourceMapTypeDef: srcMapTypeDef,
                      destinationMapTypeDef: dstMapTypeDef,
                      autoMapperConfigDetails: configuationDetails,
                      mappingConfiguration: mappingConfiguration,
                      autoMapperBuilder: autoMapperBuilder);

            IAutoMapperRequestKeyGen response_AutoMapperRequestKey
                = RegisterAutoMapperRequest(autoMapperRequestKey);

            return((IAutoMapperRequestKey <TSource, TDestination>)response_AutoMapperRequestKey);
        }
예제 #4
0
        private IMapper BuildAutoMapperGen(IAutoMapperRequestKeyGen mapRequestGen)
        {
            IAutoMapperRequestKey <TSource, TDestination> mapRequestTyped
                = mapRequestGen as IAutoMapperRequestKey <TSource, TDestination>;

            if (mapRequestTyped == null)
            {
                throw new InvalidOperationException($"{nameof(mapRequestGen)} does not implement the correct typed {nameof(IAutoMapperRequestKey<TSource, TDestination>)} interface.");
            }

            return(BuildAutoMapper(mapRequestTyped));
        }
예제 #5
0
 public PropBagMapperRequestKeyGen
 (
     Func <IPropBagMapperRequestKeyGen, ViewModelFactoryInterface, IPropBagMapperGen> mapperCreator,
     IAutoMapperRequestKeyGen autoMapperRequestKeyGen
     //,
     //PropModelType propModel
 )
 {
     PropBagMapperCreator    = mapperCreator;
     AutoMapperRequestKeyGen = autoMapperRequestKeyGen;
     //PropModel = propModel;
 }
예제 #6
0
        private void CheckForChanges(IAutoMapperRequestKeyGen original, IAutoMapperRequestKeyGen current, string operationName)
        {
            if (!ReferenceEquals(original, current))
            {
                System.Diagnostics.Debug.WriteLine($"The mapRequest object was replaced by method call: {operationName}.");
            }

            if (original != current)
            {
                System.Diagnostics.Debug.WriteLine($"The mapRequest was updated by method call: {operationName}.");
            }
        }
예제 #7
0
        // From AutoMapperRequestKey (Gen)
        private IMapper GetRawAutoMapperGen(IAutoMapperRequestKeyGen rawAutoMappeRequestKeyGen)
        {
            //if (rawAutoMappeRequestKeyGen.AutoMapper == null)
            //{
            //    IMapper autoMapper = _autoMapperService.GetAutoMapper(rawAutoMappeRequestKeyGen);
            //    rawAutoMappeRequestKeyGen.AutoMapper = autoMapper;
            //}

            //return rawAutoMappeRequestKeyGen.AutoMapper;

            IMapper result = _autoMapperService.GetAutoMapper(rawAutoMappeRequestKeyGen);

            return(result);
        }
예제 #8
0
        // Gen Submit
        public IAutoMapperRequestKeyGen SubmitRawAutoMapperRequest
        (
            Type sourceType,
            Type destinationType,
            IAutoMapperConfigDetails autoMapperConfigDetails,
            string configPackageName,
            IHaveAMapperConfigurationStep configStarterForThisRequest
        )
        {
            AutoMapperReqSubDelegate mapperRequestSubmitter = GetAutoMapperReqSubDelegate(sourceType, destinationType);
            IAutoMapperRequestKeyGen result = mapperRequestSubmitter(autoMapperConfigDetails, sourceType, destinationType, configPackageName, configStarterForThisRequest, this);

            return(result);
        }
예제 #9
0
 private IAutoMapperRequestKeyGen RequestFactory(IAutoMapperRequestKeyGen key)
 {
     return(key);
 }
예제 #10
0
        private IMapper MapperFactory(IAutoMapperRequestKeyGen key)
        {
            IMapper result = key.BuildAutoMapper();

            return(result);
        }
예제 #11
0
 public IMapper GetAutoMapper(IAutoMapperRequestKeyGen autoMapperRequestKey)
 {
     return(_autoMapperCache.GetAutoMapper(autoMapperRequestKey));
 }
예제 #12
0
 public IAutoMapperRequestKeyGen RegisterAutoMapperRequest(IAutoMapperRequestKeyGen autoMapperRequestKey)
 {
     return(_autoMapperCache.RegisterAutoMapperRequest(autoMapperRequestKey));
 }