private String GetSessionId(DataContract.MacroInternational.GetMacroProductInternationalRequest request) { string username = request.AuthenticationData.Username, platform = request.Platform ?? ConfigurationManager.AppSettings["DefaultPlatform"]; var cacheObj = new LoginDataCache(); if (request != null) { ObjectCache cache = MemoryCache.Default; var cacheKey = username + platform; ProviderLogger.InfoLow("*** Chequeo de cache ***"); foreach (var item in cache) { ProviderLogger.InfoLow(item.Key + ": " + item.Value); } ProviderLogger.InfoLow("************************"); if (!String.IsNullOrEmpty(request.AuthenticationData.SessionID)) { return(request.AuthenticationData.SessionID); } else { if (cache.Contains(cacheKey)) { cacheObj = (LoginDataCache)cache.Get(cacheKey); } else { var getSessionResponse = new ServiceExecutionDelegator <GetSessionResponseBody, GetSessionRequestBody>().ResolveRequest( new GetSessionRequestBody() { Username = request.AuthenticationData.Username, Password = request.AuthenticationData.Password, DeviceType = request.DeviceType }, ApiTargetPlatform.Kinacu, ApiServiceName.GetSession); var newCacheObject = new LoginDataCache() { UserName = username, Platform = platform, Token = getSessionResponse.SessionID }; // Store data in the cache var cacheMinutes = ConfigurationManager.AppSettings["UtibaSessionTTL"] ?? "10"; var cacheItemPolicy = new CacheItemPolicy { AbsoluteExpiration = DateTime.Now.AddSeconds(Convert.ToInt32(cacheMinutes) * 1000) }; //cache.Add(cacheKey, newCacheObject, cacheItemPolicy); ProviderLogger.InfoHigh("cacheKey: " + cacheKey + " - newCacheObject: {" + newCacheObject.UserName + "," + newCacheObject.Platform + "," + newCacheObject.Token + "} - cacheItemPolicy: " + cacheItemPolicy.AbsoluteExpiration); cacheObj = newCacheObject; } } } return(cacheObj.Token); }
public DataContract.MacroInternational.GetMacroProductInternationalResponse GetMacroProductsInter(DataContract.MacroInternational.GetMacroProductInternationalRequest request) { var response = new DataContract.MacroInternational.GetMacroProductInternationalResponse(); try { LogRequest(request); var sessionId = GetSessionId(request); //var platformId = Convert.ToInt32(request.Platform); //1 //var countryId = Convert.ToInt32(ConfigurationManager.AppSettings["CountryId"]); //10 //Platform products. var productList = new ServiceExecutionDelegator <GetProductListResponseBody, GetProductListRequestBody>(). ResolveRequest(new GetProductListRequestBody() { AuthenticationData = new AuthenticationData() { Username = request.AuthenticationData.Username, Password = request.AuthenticationData.Password, SessionID = sessionId }, Agent = request.Agent, DeviceType = request.DeviceType }, request.Platform, ApiServiceName.GetProductList); if (productList.ProductList == null) { response = new DataContract.MacroInternational.GetMacroProductInternationalResponse { ResponseCode = 99, ResponseMessage = "Error: El usuario no tiene productos asignados en la plataforma.", TransactionID = 0 }; } else { var dm = new Movilway.API.Data.MacroProduct.MacroProductInterDataManager(); if (String.IsNullOrEmpty(request.CountryId)) { request.CountryId = "0"; } response = dm.GetMacroProductsInter(Convert.ToInt32(request.CountryId), productList.ProductList, request.DeviceType); response.ResponseCode = 0; response.ResponseMessage = "Exito."; response.TransactionID = 0; } LogResponse(response); return(response); } catch (Exception e) { ProviderLogger.ExceptionLow(() => TagValue.New().Message("Exception trying to serve KINACU Operation").Exception(e)); } return(response); }
public DataContract.MacroInternational.GetMacroProductInternationalResponse GetMacroProductsInter(DataContract.MacroInternational.GetMacroProductInternationalRequest request) { if (String.IsNullOrEmpty(request.Platform)) { request.Platform = ConfigurationManager.AppSettings["DefaultPlatform"]; } var response = new MacroProductInternationalProvider().GetMacroProductsInter(request); return(response); }