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); }
public IPropBagMapperGen GetPropBagMapper(IPropBagMapperRequestKeyGen mapperRequest) { if (mapperRequest.AutoMapper == null) { throw new InvalidOperationException($"The {nameof(SimplePropBagMapperCache)} was asked to GetPropBagMapper, however the mapperRequest has a null AutoMapper."); } IPropBagMapperRequestKeyGen save = mapperRequest; if (_propBagMappers.TryGetValue(mapperRequest, out IPropBagMapperGen result)) { return(result); } else { //IPropBagMapperKeyGen newOrExistingRequest = _Requests.GetOrAdd(mapperRequest); //result = _propBagMappers.GetOrAdd(newOrExistingRequest); // Remove the request from the request que if present. _requests.TryRemoveValue(mapperRequest, out IPropBagMapperRequestKeyGen dummyExistingRequest); result = _propBagMappers.GetOrAdd(mapperRequest); CheckForChanges(save, mapperRequest, "GetOrAdd PropBagMapper."); } return(result); }
// TODO: Need to protect this with a lock. public IPropBagMapperGen GetMapperToUse(IPropBagMapperKeyGen mapRequest) { System.Diagnostics.Debug.WriteLine($""); if (_sealedPropBagMappers.TryGetValue(mapRequest, out IPropBagMapperGen result)) { return(result); } _unSealedPropBagMappers.GetOrAdd(mapRequest); SealThis(pCntr++); result = _sealedPropBagMappers[mapRequest]; return(result); }