Exemplo n.º 1
0
        //Crea el componente que implmente una ejecucion segura y la invoca
        private K ResolveSecureRequest(T request, ApiTargetPlatform targetPlatform, ApiServiceName serviceName)
        {
            //bandera para determinar si hubo error de la clase
            bool opok = false;

            try
            {
                if (ConfigurationManager.AppSettings["ProcessMigration"].ToLower() == "true")
                {
                    if (request.AuthenticationData != null)
                    {
                        if (GetCustomDefaultPlatform(request.AuthenticationData.Username) == "1")
                        {
                            targetPlatform = ApiTargetPlatform.Kinacu;
                        }
                    }
                }

                if (HttpContext.Current.Session != null)
                {
                    if (HttpContext.Current.Session["LOG_PREFIX"] == null)
                    {
                        HttpContext.Current.Session.Add("LOG_PREFIX", "[" + new Random(DateTime.Now.Millisecond * 9).Next(100000000, 999999999) + "] [" + serviceName.ToString() + "] ");
                    }
                }

                ISecureServiceProvider serviceImpl = ServiceProviderFactory.GetServiceProviderSecure(targetPlatform, serviceName);

                //se pudo ejecutar hasta este punto el codigo
                opok = true;

                return((K)serviceImpl.PerformSecureOperation(request));
            }

            catch (Exception ex)
            {
                K resultError = Reflection.FactoryObject <K>();
                resultError.ResponseCode = UtilResut.ResponseCode(ex);

                if (ex.Message.IndexOf("[API UNEXCEPTED ERROR]", StringComparison.Ordinal) < 0)
                {
                    resultError.ResponseMessage = String.Concat("[API UNEXCEPTED ERROR]-[", ex.Message, "]");
                }
                else
                {
                    resultError.ResponseMessage = ex.Message;
                }

                //si es un error interno del la clase se debe
                if (!opok)
                {
                    logger.Fatal(String.Concat(resultError.ResponseCode, "-", resultError.ResponseMessage, "-", ex.StackTrace), ex);
                }

                return(resultError);
            }
        }
Exemplo n.º 2
0
        public static ISecureServiceProvider GetServiceProviderSecure(ApiTargetPlatform targetPlatform, ApiServiceName serviceName)
        {
            ISecureServiceProvider serviceProviderImpl = null;

            if (_registeredProviders.ContainsKey(targetPlatform))
            {
                var registeredServicerForPlatform = _registeredProviders[targetPlatform];
                if (registeredServicerForPlatform.ContainsKey(serviceName))
                {
                    Type providerType = registeredServicerForPlatform[serviceName];
                    serviceProviderImpl = (ISecureServiceProvider)Activator.CreateInstance(providerType);
                }
            }
            return(serviceProviderImpl);
        }