public TWrapper WrapResponse <TWrapper, TWrapped>(IMovilwayApiResponse response) where TWrapped : IMovilwayApiResponse { var wrappedResponse = Activator.CreateInstance <TWrapper>(); var movilwayApiResponseWrapper = wrappedResponse as IMovilwayApiResponseWrapper <TWrapped>; if (movilwayApiResponseWrapper != null) { movilwayApiResponseWrapper.Response = (TWrapped)response; } return(wrappedResponse); }
public IMovilwayApiResponse PerformOperation(IMovilwayApiRequest request) { try { LOG_PREFIX = HttpContext.Current.Session["LOG_PREFIX"].ToString() + "[" + new Random(DateTime.Now.Millisecond * 5).Next(100000000, 999999999) + "] "; } catch (Exception) { LOG_PREFIX = ""; } UMarketSCClient utibaClient = new UMarketSCClient(); IMovilwayApiResponse response = null; try { try { logger.InfoLow("[API] " + LOG_PREFIX + "[UtibaProvider] [INPUT] UserInfo {IP=" + HttpContext.Current.Request.UserHostAddress + ",Username="******"} " + request.ToString()); } catch (Exception) { logger.InfoLow("[API] " + LOG_PREFIX + "[UtibaProvider] [INPUT] UserInfo {IP=" + "NULL" + ",Username="******"} " + request.ToString()); } int timeOutSeconds = int.Parse(ConfigurationManager.AppSettings["DefaultTimeout"]); utibaClient.InnerChannel.OperationTimeout = new TimeSpan(0, 0, timeOutSeconds); String sessionID = null; if (!(request is GetSessionRequestBody)) { sessionID = GetSessionID(request); } response = PerformUtibaOperation(request, utibaClient, sessionID); logger.InfoLow("[API] " + LOG_PREFIX + "[UtibaProvider] [OUTPUT] " + response.ToString()); } catch (Exception e) { logger.ErrorLow("[API] " + LOG_PREFIX + "[UtibaProvider] [EXCEPTION] Exception trying to serve UTIBA Operation {message=" + e.Message + ",stackTrace=" + e.StackTrace + "}"); } return(response); }
/// <summary> /// Inicia la ejecucion del metodo /// </summary> /// <param name="request"></param> /// <returns></returns> public IMovilwayApiResponse PerformOperation(IMovilwayApiRequest request) { IMovilwayApiResponse response = null; //DATOS DE AUTENTICACION try { #region antes // PREFIX //try //{ // LOG_PREFIX = HttpContext.Current.Session["LOG_PREFIX"].ToString() + "[" + new Random(DateTime.Now.Millisecond * 3).Next(100000000, 999999999) + "] "; //} //catch (Exception) //{ // LOG_PREFIX = ""; //} #endregion InitPrefix(); #region log data //try //{ // logger.InfoLow("[API] " + LOG_PREFIX + "[KinacuProvider] [INPUT] UserInfo {IP=" + HttpContext.Current.Request.UserHostAddress + ",Username="******"} " + request.ToString()); //} //catch (Exception) //{ // logger.InfoLow("[API] " + LOG_PREFIX + "[KinacuProvider] [INPUT] UserInfo {IP=" + "NULL" + ",Username="******"} " + request.ToString()); //} #endregion PrintLoginValues(request); #region antes //if (request.DeviceType == cons.ACCESS_H2H) //{ // if (!NetWorkSecurity.IpIsWithinRangeH2H(HttpContext.Current.Request.UserHostAddress)) // { // string message = String.Concat("[LA IP NO ESTA REGISTRADA EN EL RANGO PERMITIDO H2H (", HttpContext.Current.Request.UserHostAddress, ")]"); // logger.ErrorHigh(() => TagValue.New().Message("[ERROR DE PERMISOS H2H]").Message(message).Tag("[PARA ACCESO]").Value(request.AuthenticationData)); // throw new Exception(message); // } //} #endregion //si no se activa la optimizacion de seguridad //siempre ejecuta las validaciones de seguridad //if (!ApiConfiguration.API_SECURE_OPTIMIZATION) SecureValidation(request); //la restriccion se mantiene con el fin de que se pueda volver a validar el tiempo del session ID String sessionID = null; if (!(request is GetSessionRequestBody)) { sessionID = GetSessionID(request); } SaleInterface kinacuWS = new SaleInterface(); // CONDIGURACION INTERFAZ int timeOutSeconds = int.Parse(ConfigurationManager.AppSettings["DefaultTimeout"]); kinacuWS.Timeout = timeOutSeconds * 1000; response = PerformKinacuOperation(request, kinacuWS, sessionID); // no deberia lanzar second request deberia solo se responsabilidad #region secondrequest //if (!ValidateNumberOfExecution(request)) // response = PerformKinacuOperation(request, kinacuWS, sessionID); //else //{ // if (_delegateSecondExecution == null) // throw new Exception("NO SE HA DEFINIDO EL MANEJADOR PARA LA SEGUNDA PETICION"); // bool isNew = false; // Func<int> callback = delegate() // { // logger.InfoLow("[API] " + LOG_PREFIX + "[KinacuProvider] [DOUBLE REQUEST] [CALL BACK] [IS NEW]"); // isNew = true; // return 1; // }; // int hascode = request.GetHashCode(); // logger.InfoLow("[API] " + LOG_PREFIX + "[KinacuProvider] [DOUBLE REQUEST VALIDATION] [" + hascode + "] "+_cacheRequest.ToString()); // //Action<object,object> oncache= delegate(object k , object v) // // { // // logger.InfoLow("[API] " + LOG_PREFIX + "[KinacuProvider] [DOUBLE REQUEST] [CALL BACK] [IS DOUBLE]"); // // isNew = false; // // }; // _cacheRequest.GetValue<int>(hascode, callback);//, oncache); // if (isNew) // { // response = PerformKinacuOperation(request, kinacuWS, sessionID); // } // else // { // logger.InfoLow("[API] " + LOG_PREFIX + "[KinacuProvider] [SecondExecution]"); // response = _delegateSecondExecution (request, kinacuWS, sessionID); // } //} #endregion if (!(request is GetSessionRequestBody)) { if (bool.Parse(ConfigurationManager.AppSettings["LogoffAuto"] ?? "true")) { logger.InfoLow("[KIN] " + this.LOG_PREFIX + "[LogOffProvider] [SEND-DATA] logoffParameters {userid=" + sessionID + "}"); kinacuWS.LogOff(int.Parse(sessionID)); logger.InfoLow("[KIN] " + this.LOG_PREFIX + "[LogOffProvider] [RECV-DATA] logoffResult {nothing}"); } } logger.InfoLow("[API] " + LOG_PREFIX + "[KinacuProvider] [OUTPUT] " + response.ToString()); } catch (Exception e) { logger.ErrorLow("[API] " + LOG_PREFIX + "[KinacuProvider] [EXCEPTION] Exception trying to serve KINACU Operation {message=" + e.Message + ",stackTrace=" + e.StackTrace + "}"); //SE DELEGA EL MANEJO DE LA EXPECION A QUIEN LO INVOCA GENERALMENTE SERVICEEXECUTIONDELEGATOR throw; #region intento de respuesta anterior //Type a = this.GetType().GetMethod("PerformOperation").ReturnType; //response = new AGenericApiResponse() { ResponseCode = 99, ResponseMessage = e.Message, TransactionID = 0 }; //Type name = MethodBase.GetCurrentMethod().GetType(); //ProviderLogger.ExceptionLow(() => TagValue.New().Message("Exception trying to serve KINACU Operation").Exception(e)); #endregion } return(response); }
/// <summary> /// Ejecuta la operacion validando los constrains de seguridad /// /// </summary> /// <param name="request"></param> /// <returns></returns> public IMovilwayApiResponse PerformSecureOperation(IMovilwayApiRequest request) { IMovilwayApiResponse response = null; //DATOS DE AUTENTICACION try { InitPrefix(); PrintLoginValues(request); //Validaciones de seguridad teniendo en cuenta los datos de la peticion SecureValidation(request); SecureAccessValidation(request); // String sessionID = null; if (!(request is GetSessionRequestBody)) { sessionID = GetSessionID(request); } SaleInterface kinacuWS = new SaleInterface(); // // CONDIGURACION INTERFAZ int timeOutSeconds = int.Parse(ConfigurationManager.AppSettings["DefaultTimeout"]); kinacuWS.Timeout = timeOutSeconds * 1000; response = PerformKinacuOperation(request, kinacuWS, sessionID); #region secondrequest //if (!ValidateNumberOfExecution(request)) // response = PerformKinacuOperation(request, kinacuWS, sessionID); //else //{ // if (_delegateSecondExecution == null) // throw new Exception("NO SE HA DEFINIDO EL MANEJADOR PARA LA SEGUNDA PETICION"); // bool isNew = false; // Func<int> callback = delegate() // { // logger.InfoLow("[API] " + LOG_PREFIX + "[KinacuProvider] [DOUBLE REQUEST] [CALL BACK] [IS NEW]"); // isNew = true; // return 1; // }; // int hascode = request.GetHashCode(); // logger.InfoLow("[API] " + LOG_PREFIX + "[KinacuProvider] [DOUBLE REQUEST VALIDATION] [" + hascode + "] "+_cacheRequest.ToString()); // //Action<object,object> oncache= delegate(object k , object v) // // { // // logger.InfoLow("[API] " + LOG_PREFIX + "[KinacuProvider] [DOUBLE REQUEST] [CALL BACK] [IS DOUBLE]"); // // isNew = false; // // }; // _cacheRequest.GetValue<int>(hascode, callback);//, oncache); // if (isNew) // { // response = PerformKinacuOperation(request, kinacuWS, sessionID); // } // else // { // logger.InfoLow("[API] " + LOG_PREFIX + "[KinacuProvider] [SecondExecution]"); // response = _delegateSecondExecution (request, kinacuWS, sessionID); // } //} #endregion if (bool.Parse(ConfigurationManager.AppSettings["LogoffAuto"] ?? "true")) { logger.InfoLow("[KIN] " + this.LOG_PREFIX + "[LogOffProvider] [SEND-DATA] logoffParameters {userid=" + sessionID + "}"); kinacuWS.LogOff(int.Parse(sessionID)); logger.InfoLow("[KIN] " + this.LOG_PREFIX + "[LogOffProvider] [RECV-DATA] logoffResult {nothing}"); } logger.InfoLow("[API] " + LOG_PREFIX + "[KinacuProvider] [OUTPUT] " + response.ToString()); } catch (Exception e) { logger.ErrorLow("[API] " + LOG_PREFIX + "[KinacuProvider] [EXCEPTION] Exception trying to serve KINACU Operation {message=" + e.Message + ",stackTrace=" + e.StackTrace + "}"); //SE DELEGA EL MANEJO DE LA EXPECION A QUIEN LO INVOCA GENERALMENTE SERVICEEXECUTIONDELEGATOR throw; #region intento de respuesta anterior //Type a = this.GetType().GetMethod("PerformOperation").ReturnType; //response = new AGenericApiResponse() { ResponseCode = 99, ResponseMessage = e.Message, TransactionID = 0 }; //Type name = MethodBase.GetCurrentMethod().GetType(); //ProviderLogger.ExceptionLow(() => TagValue.New().Message("Exception trying to serve KINACU Operation").Exception(e)); #endregion } return(response); }
public IMovilwayApiResponse PerformOperation(IMovilwayApiRequest requestObject) { try { //validar una vez la ip //ASecuredApiRequest securityrequest = null; GetSessionResponseBody responseBody = null; switch (_securemode) { case ApiSecurityMode.CREDENTIALS: //securityrequest = Reflection.FactoryObject<ASecuredApiRequest>(typeof(ASecuredApiRequest)); //securityrequest.AuthenticationData = new AuthenticationData(); //securityrequest.AuthenticationData.Username = requestObject.AuthenticationData.Username; //securityrequest.AuthenticationData.Password = requestObject.AuthenticationData.Password; //securityrequest.AuthenticationData.SessionID = requestObject.AuthenticationData.SessionID; //securityrequest.AuthenticationData.Tokken = requestObject.AuthenticationData.Tokken; responseBody = new ServiceExecutionDelegator <GetSessionResponseBody, IMovilwayApiRequest>().ResolveRequest( requestObject , _target, ApiServiceName.GetSession); break; case ApiSecurityMode.USER: //securityrequest = Reflection.FactoryObject<ASecuredApiRequest>(typeof(ASecuredApiRequest)); //securityrequest.AuthenticationData = new AuthenticationData(); //securityrequest.AuthenticationData.Username = requestObject.AuthenticationData.Username; //securityrequest.AuthenticationData.Password = requestObject.AuthenticationData.Password; //securityrequest.AuthenticationData.SessionID = string.Empty; //securityrequest.AuthenticationData.Tokken = string.Empty; responseBody = new ServiceExecutionDelegator <GetSessionResponseBody, IMovilwayApiRequest>().ResolveRequest( requestObject , _target, ApiServiceName.GetSession); break; } if (responseBody.ResponseCode == 0)//&& tokken es valido { // si la validacion es segura return(_serviceImpl.PerformOperation(requestObject)); } else { IMovilwayApiResponse response = Reflection.FactoryObject <IMovilwayApiResponse>(_typeresponse); response.ResponseCode = 90; response.ResponseMessage = responseBody.ResponseMessage; //"ERROR DE SEGURIDAD DATOS ASOCIADOS AL TOKKEN INVALIDO"; return(response); } } catch (Exception ex) { //TODO DESHABILITAR LA EJECUCION DE EST HANDLER IMovilwayApiResponse response = Reflection.FactoryObject <IMovilwayApiResponse>(_typeresponse); response.ResponseCode = 500; response.ResponseMessage = "ERROR INESPERADO EJECUTANDO SECUREPROVIDER"; logger.ErrorHigh(String.Concat(response.ResponseCode, "-", response.ResponseMessage, " ", ex.Message, "-.", ex.StackTrace)); return(response); } }