public override ProfileResponse Profile(Agent agent, ProfileRequest profileRequest) { ProfileResponse agentProfile; var agentProfileKeyFormatted = string.Format(CacheKeys.AGENTPROFILEKEY, agent.AgentId, agent.AgentSequence); var cachedResult = _cacheManager.Contains <CachedObjectResponseContainer <ProfileResponse> >(agentProfileKeyFormatted, CacheRegion.Global); Func <ProfileResponse> profileCacheSaveFunction = delegate() { Console.WriteLine("Entered profileCacheSaveFunction"); agentProfile = base.Profile(agent, profileRequest); var CachedContainer = CacheAheadHelper.PopulateCacheMetadata <ProfileResponse>(agentProfile, CachePolicies.FullWeek); _cacheManager.Save(agentProfileKeyFormatted, CachedContainer, CacheRegion.Global, CachePolicies.FullWeek); return(agentProfile); }; if (cachedResult.Exists) { CacheAheadHelper.ExecuteCacheAheadProcess <ProfileResponse>(profileCacheSaveFunction, cachedResult.CachedObj.CacheMetadata); agentProfile = cachedResult.CachedObj.DataObject; } else { agentProfile = profileCacheSaveFunction(); } return(agentProfile); }
public override IndustryResponse Industry(Agent agent, IndustryRequest request) { IndustryResponse industriesResponse; var industryKeyFormatted = string.Format(CacheKeys.INDUSTRYKEY, agent.Language); var result = _cacheManager.Contains <CachedObjectResponseContainer <IndustryResponse> >(industryKeyFormatted, CacheRegion.Global); Func <IndustryResponse> industryCacheSaveFunction = delegate() { industriesResponse = base.Industry(agent, request); var CachedContainer = CacheAheadHelper.PopulateCacheMetadata <IndustryResponse>(industriesResponse, CachePolicies.FullWeek); _cacheManager.Save(industryKeyFormatted, CachedContainer, CacheRegion.Global, CachePolicies.FullWeek); return(industriesResponse); }; if (result.Exists) { CacheAheadHelper.ExecuteCacheAheadProcess <IndustryResponse>(industryCacheSaveFunction, result.CachedObj.CacheMetadata); industriesResponse = result.CachedObj.DataObject; } else { industriesResponse = industryCacheSaveFunction(); } return(industriesResponse); }
public string GetAgentPassword(string token, string agentId, string posNumber) { var agentPasswordCacheKey = string.Format(AuthCacheKeys.PARTNERSERVICECLAIMS, token); var partnerServiceCached = cacheManager.Contains <CachedObjectResponseContainer <string> >(agentPasswordCacheKey, CacheRegion.Global); if (partnerServiceCached.Exists) { // no password is cached if (string.IsNullOrEmpty(partnerServiceCached.CachedObj.DataObject)) { // We have incomplete data. Invalidate cache partnerServiceCached.Exists = false; cacheManager.Remove(agentPasswordCacheKey, CacheRegion.Global); } else { // Cache exists and there are no missing claims, use cached claims return(partnerServiceCached.CachedObj.DataObject); } } var agentPassword = ""; try { agentPassword = GetAgentPassword(agentId, posNumber); } catch (Exception ex) { if (ex is CommunicationException) { // Unreachable. throw PrincipalExceptionFactory.Create(PrincipalExceptionType.PartnerService, LocalizationKeys.SystemUnavailable, null); } // Reachable but has a problem. throw PrincipalExceptionFactory.Create(PrincipalExceptionType.PartnerService, LocalizationKeys.InvalidAgentProfile, null); } if (string.IsNullOrEmpty(agentPassword)) { // Throw exception throw PrincipalExceptionFactory.Create(PrincipalExceptionType.PartnerService, LocalizationKeys.InvalidAgentProfile, new List <string> { "agentPassword" }); } var partnerServiceClaimsCacheContainer = CacheAheadHelper.PopulateCacheMetadata <string>(agentPassword, CachePolicies.FourHours); cacheManager.Save(agentPasswordCacheKey, partnerServiceClaimsCacheContainer, CacheRegion.Global, CachePolicies.FourHours); return(agentPassword); }
public void Save() { var cacheKey = CacheIntegrationTestHelper.GetRandomCacheKey(); var cacheData = CacheAheadHelper.PopulateCacheMetadata <string>("Test", CachePolicies.FourHours); _InMemeoryCacheManager.Save(cacheKey, cacheData, CacheRegion.Global); var sucessfulSaveResult = _InMemeoryCacheManager.Contains <string>(cacheKey, CacheRegion.Global); Assert.IsTrue(sucessfulSaveResult.Exists); }
public List <Claim> GetAgentProfileClaims(string agentId, string posNumber, string password, string language, string sessionId) { var agentProfileKey = string.Format(AuthCacheKeys.AGENTPROFILECLAIMS, sessionId); var agentProfileCachedClaims = cacheManager.Contains <CachedObjectResponseContainer <List <Tuple <string, string> > > >(agentProfileKey, CacheRegion.Global); if (agentProfileCachedClaims.Exists) { var missingClaimsInCache = ClaimsInventoryHelper.CheckAgentProfileClaims(agentProfileCachedClaims.CachedObj.DataObject.ToClaims()); if (missingClaimsInCache.Any()) { agentProfileCachedClaims.Exists = false; var agentProfileKeyFormatted = string.Format(AuthCacheKeys.AGENTPROFILEKEY, agentId, posNumber); cacheManager.Remove(agentProfileKey, CacheRegion.Global); cacheManager.Remove(agentProfileKeyFormatted, CacheRegion.Global); } else { // Cache exists and there are no missing claims, use cached claims return(agentProfileCachedClaims.CachedObj.DataObject.ToClaims()); } } try { var agentProfile = GetAgentProfile(agentId, posNumber, password, language); var agentProfileClaims = ParseClaimsFromAgentProfile(agentProfile); var missingClaims = ClaimsInventoryHelper.CheckAgentProfileClaims(agentProfileClaims); if (missingClaims.Any()) { // Throw exception throw PrincipalExceptionFactory.Create(PrincipalExceptionType.OpenAm, LocalizationKeys.InvalidAgentProfile, missingClaims); } var agentProfileClaimsCacheContainer = CacheAheadHelper.PopulateCacheMetadata <List <Tuple <string, string> > >(agentProfileClaims.ToTupleList(), CachePolicies.FourHours); cacheManager.Save(agentProfileKey, agentProfileClaimsCacheContainer, CacheRegion.Global, CachePolicies.FourHours); return(agentProfileClaims); } catch (Exception ex) { if (ex is CommunicationException) { throw PrincipalExceptionFactory.Create(PrincipalExceptionType.OpenAm, LocalizationKeys.SystemUnavailable, null); } throw PrincipalExceptionFactory.Create(PrincipalExceptionType.OpenAm, LocalizationKeys.InvalidAgentProfile, null); } }
public void Contains() { var cacheKey = CacheIntegrationTestHelper.GetRandomCacheKey(); var cacheData = CacheAheadHelper.PopulateCacheMetadata <string>("Test", CachePolicies.FourHours); _InMemeoryCacheManager.Save(cacheKey, cacheData, CacheRegion.Global); var sucessfulSaveResult = _InMemeoryCacheManager.Contains <CachedObjectResponseContainer <string> >(cacheKey, CacheRegion.Global); Assert.IsTrue(sucessfulSaveResult.Exists); Assert.IsTrue(sucessfulSaveResult.CachedObj is CachedObjectResponseContainer <string>); Assert.IsTrue((sucessfulSaveResult.CachedObj as CachedObjectResponseContainer <string>).DataObject.Equals("Test")); }
public async Task <List <Claim> > GetUserInfo(string token) { var camsClaimsKey = string.Format(AuthCacheKeys.CAMSCLAIMS, token); var cachedCamsClaims = cacheManager.Contains <CachedObjectResponseContainer <List <Tuple <string, string> > > >(camsClaimsKey, CacheRegion.Global); // Check if claims are missing first if (cachedCamsClaims.Exists) { var missingClaimsInCache = ClaimsInventoryHelper.CheckCamsClaims(cachedCamsClaims.CachedObj.DataObject.ToClaims()); if (missingClaimsInCache.Any()) { // We have incomplete data. Invalidate cache cachedCamsClaims.Exists = false; cacheManager.Remove(camsClaimsKey, CacheRegion.Global); } else { return(cachedCamsClaims.CachedObj.DataObject.ToClaims()); } } Dictionary <string, object> userInfo = null; try { userInfo = await openAmIntegration.GetUserInfo(token); } catch (Exception) { throw PrincipalExceptionFactory.Create(PrincipalExceptionType.OpenAm, LocalizationKeys.SystemUnavailable, null); } var camsClaims = ClaimsManager.ParseClaims(userInfo); var missingClaims = ClaimsInventoryHelper.CheckCamsClaims(camsClaims); if (missingClaims.Any()) { // Throw exception throw PrincipalExceptionFactory.Create(PrincipalExceptionType.OpenAm, LocalizationKeys.InvalidUserProfile, missingClaims); } var camsClaimsCacheContainer = CacheAheadHelper.PopulateCacheMetadata <List <Tuple <string, string> > >(camsClaims.ToTupleList(), CachePolicies.FourHours); cacheManager.Save(camsClaimsKey, camsClaimsCacheContainer, CacheRegion.Global, CachePolicies.FourHours); return(camsClaims); }
public override GetAllFieldsResponse GetAllFields(Agent agent, GetAllFieldsRequest getAllFieldsRequest) { // GetAllFields key is TransactionType+Language+Target Audience // Product - GetAllFieldsRequest.TransactionType // Language - Request.Language // Target Audience - Request.TargetAudience (AGENT_FACING, CONSUMER_FACING, SERVICING) GetAllFieldsResponse allFieldsResponse; var allFieldsKeyFormatted = string.Format(CacheKeys.GETALLFIELDSKEY, getAllFieldsRequest.TransactionType, agent.Language, getAllFieldsRequest.TargetAudience); var result = _cacheManager.Contains <CachedObjectResponseContainer <GetAllFieldsResponse> >(allFieldsKeyFormatted, CacheRegion.Global); Func <GetAllFieldsResponse> allFieldsCacheSaveFunction = delegate() { var version = getAllFieldsRequest.CachedVersion; getAllFieldsRequest.CachedVersion = null; allFieldsResponse = base.GetAllFields(agent, getAllFieldsRequest); var CachedContainer = CacheAheadHelper.PopulateCacheMetadata <GetAllFieldsResponse>(allFieldsResponse, CachePolicies.FullWeek); if (!string.IsNullOrEmpty(allFieldsResponse.Payload.Version) && allFieldsResponse.Payload.Infos.Any()) { _cacheManager.Save(allFieldsKeyFormatted, CachedContainer, CacheRegion.Global, CachePolicies.FullWeek); } getAllFieldsRequest.CachedVersion = version; return(allFieldsResponse); }; if (result.Exists) { CacheAheadHelper.ExecuteCacheAheadProcess <GetAllFieldsResponse>(allFieldsCacheSaveFunction, result.CachedObj.CacheMetadata); if (getAllFieldsRequest.CachedVersion != result.CachedObj.DataObject.Payload.Version) { allFieldsResponse = result.CachedObj.DataObject; } else { allFieldsResponse = new GetAllFieldsResponse { Payload = new GetAllFieldsResponsePayload { Version = getAllFieldsRequest.CachedVersion } }; } } else { allFieldsResponse = allFieldsCacheSaveFunction(); } return(allFieldsResponse); }
public override GetEnumerationsResponse GetEnumerations(Agent agent, GetEnumerationsRequest getEnumerationsRequest) { // GetEnumerations key is Language+EnumerationName // Language - Request.Language // EnumerationName- Request.EnumerationName (NAME_SUFFIX, OCCUPATION, PERSONAL_ID2_TYPE) GetEnumerationsResponse enumerationsResponse; var enumerationsKeyFormatted = string.Format(CacheKeys.GETENUMERATIONSKEY, agent.Language, getEnumerationsRequest.EnumerationName); var result = _cacheManager.Contains <CachedObjectResponseContainer <GetEnumerationsResponse> >(enumerationsKeyFormatted, CacheRegion.Global); Func <GetEnumerationsResponse> enumerationsCacheSaveFunction = delegate() { var version = getEnumerationsRequest.CachedVersion; getEnumerationsRequest.CachedVersion = null; enumerationsResponse = base.GetEnumerations(agent, getEnumerationsRequest); var CachedContainer = CacheAheadHelper.PopulateCacheMetadata <GetEnumerationsResponse>(enumerationsResponse, CachePolicies.FullWeek); enumerationsResponse = base.GetEnumerations(agent, getEnumerationsRequest); if (!string.IsNullOrEmpty(enumerationsResponse.Payload.Version) && enumerationsResponse.Payload.Enumerations.Any()) { _cacheManager.Save(enumerationsKeyFormatted, CachedContainer, CacheRegion.Global, CachePolicies.FullWeek); } getEnumerationsRequest.CachedVersion = version; return(enumerationsResponse); }; if (result.Exists) { CacheAheadHelper.ExecuteCacheAheadProcess <GetEnumerationsResponse>(enumerationsCacheSaveFunction, result.CachedObj.CacheMetadata); if (getEnumerationsRequest.CachedVersion != result.CachedObj.DataObject.Payload.Version) { enumerationsResponse = result.CachedObj.DataObject; } else { enumerationsResponse = new GetEnumerationsResponse { Payload = new GetEnumerationsResponsePayload { Version = getEnumerationsRequest.CachedVersion } }; } } else { enumerationsResponse = enumerationsCacheSaveFunction(); } return(enumerationsResponse); }
public override GetCountrySubdivisionResponse GetCountrySubdivision(Agent agent, GetCountrySubdivisionRequest getCountrySubdivisionRequest) { GetCountrySubdivisionResponse countrySubdivisionResponse; var countrySubdivisionKeyFormatted = string.Format(CacheKeys.COUNTRYSUBDIVISIONKEY, agent.Language); var cachedResult = _cacheManager.Contains <CachedObjectResponseContainer <GetCountrySubdivisionResponse> >(countrySubdivisionKeyFormatted, CacheRegion.Global); Func <GetCountrySubdivisionResponse> countrySubdivisionCacheSaveFunction = delegate() { var version = getCountrySubdivisionRequest.CachedVersion; getCountrySubdivisionRequest.CachedVersion = null; countrySubdivisionResponse = base.GetCountrySubdivision(agent, getCountrySubdivisionRequest); var CachedContainer = CacheAheadHelper.PopulateCacheMetadata(countrySubdivisionResponse, CachePolicies.FullWeek); _cacheManager.Save(countrySubdivisionKeyFormatted, CachedContainer, CacheRegion.Global, CachePolicies.FullWeek); getCountrySubdivisionRequest.CachedVersion = version; return(countrySubdivisionResponse); }; if (cachedResult.Exists) { CacheAheadHelper.ExecuteCacheAheadProcess <GetCountrySubdivisionResponse>(countrySubdivisionCacheSaveFunction, cachedResult.CachedObj.CacheMetadata); if (getCountrySubdivisionRequest.CachedVersion != cachedResult.CachedObj.DataObject.Payload.Version) { countrySubdivisionResponse = cachedResult.CachedObj.DataObject; } else { countrySubdivisionResponse = new GetCountrySubdivisionResponse { Payload = new GetCountrySubdivisionResponsePayload { Version = getCountrySubdivisionRequest.CachedVersion } }; } } else { countrySubdivisionResponse = countrySubdivisionCacheSaveFunction(); } return(countrySubdivisionResponse); }
public override GetCurrencyInfoResponse GetCurrencyInfo(Agent agent, GetCurrencyInfoRequest getCurrencyInfoRequest) { GetCurrencyInfoResponse currencyInfoResp; string currencyInfoKeyFormatted = string.Format(CacheKeys.CURRENCYINFOKEY, agent.Language); var cachedResult = _cacheManager.Contains <CachedObjectResponseContainer <GetCurrencyInfoResponse> >(currencyInfoKeyFormatted, CacheRegion.Global); Func <GetCurrencyInfoResponse> currencyInfoCacheSaveFunction = delegate() { var version = getCurrencyInfoRequest.Version; getCurrencyInfoRequest.Version = null; currencyInfoResp = base.GetCurrencyInfo(agent, getCurrencyInfoRequest); var CachedContainer = CacheAheadHelper.PopulateCacheMetadata <GetCurrencyInfoResponse>(currencyInfoResp, CachePolicies.FullWeek); _cacheManager.Save(currencyInfoKeyFormatted, CachedContainer, CacheRegion.Global, CachePolicies.FullWeek); getCurrencyInfoRequest.Version = version; return(currencyInfoResp); }; if (cachedResult.Exists) { CacheAheadHelper.ExecuteCacheAheadProcess <GetCurrencyInfoResponse>(currencyInfoCacheSaveFunction, cachedResult.CachedObj.CacheMetadata); if (getCurrencyInfoRequest.Version != cachedResult.CachedObj.DataObject.Payload.Version) { currencyInfoResp = cachedResult.CachedObj.DataObject; } else { currencyInfoResp = new GetCurrencyInfoResponse { Payload = new GetCurrencyInfoResponsePayload { Version = getCurrencyInfoRequest.Version } }; } } else { currencyInfoResp = currencyInfoCacheSaveFunction(); } return(currencyInfoResp); }
public override PartnerHierarchyAgentResponse GetPartnerHierarchyAgent(PartnerHierarchyAgentRequest request) { PartnerHierarchyAgentResponse hierarchyResponse; var partnerHierarchyKeyFormatted = string.Format(CacheKeys.PARTNERHIERARCHYKEY, request.MainofficeId, request.LocationId); var cachedResult = _cacheManager.Contains <CachedObjectResponseContainer <PartnerHierarchyAgentResponse> >(partnerHierarchyKeyFormatted, CacheRegion.Global); if (cachedResult.Exists) { hierarchyResponse = cachedResult.CachedObj.DataObject; } else { // Fetch payload and process hierarchyResponse = base.GetPartnerHierarchyAgent(request); var agentPasswordCacheContainer = CacheAheadHelper.PopulateCacheMetadata <PartnerHierarchyAgentResponse>(hierarchyResponse, CachePolicies.FullWeek); // Cache it _cacheManager.Save(partnerHierarchyKeyFormatted, agentPasswordCacheContainer, CacheRegion.Global, CachePolicies.FullWeek); } return(hierarchyResponse); }
public override AgentPasswordResponse GetAgentPassword(AgentPasswordRequest agentPasswordRequest) { AgentPasswordResponse agentPasswordResponse; var agentPasswordKeyFormatted = string.Format(CacheKeys.AGENTPASSWORDKEY, agentPasswordRequest.AgentId, agentPasswordRequest.PosNumber); var cachedResult = _cacheManager.Contains <CachedObjectResponseContainer <AgentPasswordResponse> >(agentPasswordKeyFormatted, CacheRegion.Global); if (cachedResult.Exists) { agentPasswordResponse = cachedResult.CachedObj.DataObject; } else { // Fetch payload and process agentPasswordResponse = base.GetAgentPassword(agentPasswordRequest); var agentPasswordCacheContainer = CacheAheadHelper.PopulateCacheMetadata <AgentPasswordResponse>(agentPasswordResponse, CachePolicies.FullWeek); // Cache it _cacheManager.Save(agentPasswordKeyFormatted, agentPasswordCacheContainer, CacheRegion.Global, CachePolicies.FullWeek); } return(agentPasswordResponse); }