Beispiel #1
0
        /// <summary>
        /// Ejecuta un servicio de negocio.
        /// </summary>
        /// <param name="providerName">Nombre del proveedor de metadata de servicios.-</param>
        /// <param name="serviceName">Nombre del servicio de negocio.</param>
        /// <param name="pXmlRequest">XML con datos de entrada para la  ejecución del servicio.</param>
        /// <returns>XML con el resultado de la  ejecución del servicio.</returns>
        /// <date>2008-04-07T00:00:00</date>
        /// <author>moviedo</author>
        public static string ExecuteService(string providerName, string serviceName, string pXmlRequest)
        {
            string wResult;

            ServiceConfiguration wServiceConfiguration = FacadeHelper.GetServiceConfiguration(providerName, serviceName);

            IServiceContract wRequest = (IServiceContract)ReflectionFunctions.CreateInstance(wServiceConfiguration.Request);

            if (wRequest == null)
            {
                TechnicalException te = new TechnicalException(string.Concat("El despachador de servicio no pudo continuar debido\r\na que no logro construir el requets del servicio: ",
                                                                             serviceName, "\r\nVerifique que se encuentre los componentes necesarios para su ejecucion esten en el servidor de aplicación. "));

                Fwk.Exceptions.ExceptionHelper.SetTechnicalException <StaticFacade>(te);

                if (string.IsNullOrEmpty(ConfigurationsHelper.HostApplicationName))
                {
                    te.Source = "Despachador de servicios en " + Environment.MachineName;
                }
                else
                {
                    te.Source = ConfigurationsHelper.HostApplicationName;
                }

                te.ErrorId = "7003";
                throw te;
            }
            wRequest.SetXml(pXmlRequest);

            wResult = ExecuteService(providerName, wRequest).GetXml();

            return(wResult);
        }
Beispiel #2
0
        /// <summary>
        /// Obtiene un objeto Response :: IServiceContract
        /// </summary>
        /// <param name="pServiceConfiguration"><see cref="ServiceConfiguration"/></param>
        /// <returns>IServiceContract</returns>
        static IServiceContract GetResponse(ServiceConfiguration pServiceConfiguration)
        {
            IServiceContract wResponse;

            try
            {
                wResponse = (IServiceContract)ReflectionFunctions.CreateInstance(pServiceConfiguration.Response);

                if (wResponse == null)
                {
                    System.Text.StringBuilder wMessage = new StringBuilder();

                    wMessage.Append("El servicio " + pServiceConfiguration.Handler);
                    wMessage.AppendLine(" no se puede ejecutar debido a que esta faltando el assembly ");
                    wMessage.Append(pServiceConfiguration.Response);
                    wMessage.Append(" en el despachador de servicio");

                    throw GetTechnicalException(wMessage.ToString(), "7003", null);
                }
            }
            catch (Exception ex)
            {
                System.Text.StringBuilder wMessage = new StringBuilder();

                wMessage.Append("El servicio " + pServiceConfiguration.Handler);
                wMessage.AppendLine(" no se puede ejecutar debido a que esta faltando el assembly ");
                wMessage.Append(pServiceConfiguration.Response);
                wMessage.Append(" en el despachador de servicio");

                throw GetTechnicalException(wMessage.ToString(), "7003", ex);
            }


            return(wResponse);
        }
Beispiel #3
0
        /// <summary>
        /// Ejecuta el servicio de negocio.
        /// </summary>
        /// <param name="pData">XML con datos de entrada.</param>
        /// <param name="pServiceConfiguration">configuración del servicio.</param>
        /// <param name="pserviError"></param>
        /// <returns>XML que representa el resultado de la  ejecución del servicio.</returns>
        /// <date>2007-08-07T00:00:00</date>
        /// <author>moviedo</author>
        static string RunService(string pData, ServiceConfiguration pServiceConfiguration, out ServiceError pserviError)
        {
            IServiceContract wRequest  = null;
            IServiceContract wResponse = null;

            // Obtencion del Request.
            wRequest = (IServiceContract)ReflectionFunctions.CreateInstance(pServiceConfiguration.Request);

            if (wRequest == null)
            {
                System.Text.StringBuilder wMessage = new StringBuilder();

                wMessage.Append("Verifique que este assemblie se encuentra en el host del despachador de servicios");
                wMessage.Append("El servicio " + pServiceConfiguration.Handler);
                wMessage.AppendLine(" no se puede ejecutar debido a que esta faltando el assembly ");
                wMessage.Append(pServiceConfiguration.Request);
                wMessage.Append(" en el despachador de servicio");

                throw GetTechnicalException(wMessage.ToString(), "7002", null);
            }

            wRequest.SetXml(pData);
            wRequest.InitializeServerContextInformation();


            wResponse = RunService(wRequest, pServiceConfiguration, out pserviError);


            return(wResponse.GetXml());
        }
        private void AddExpectedKeysForType <TComponentType>()
            where TComponentType : MonoBehaviour
        {
            var components = FindObjectsOfType <TComponentType>();

            foreach (var component in components)
            {
                var newlyFoundKeys = ReflectionFunctions.GetAttributeValuesOnTarget <EventOfInterestRegistrationAttribute, DialogueData>
                                     (
                    component
                                     ).ToList();

                var newExpectedKeys = new List <string>();

                foreach (var newlyFoundKey in newlyFoundKeys)
                {
                    foreach (var dialogueEntry in newlyFoundKey.DialogueEntries)
                    {
                        newExpectedKeys.Add("Key: " + dialogueEntry.DialogueEntryKey + "\tObject Name: " + component.gameObject.name);
                    }
                }

                _expectedKeys.AddRange(newExpectedKeys);
            }
        }
Beispiel #5
0
        public void OpenForm()
        {
            string wAssemblyInfo = String.Concat(new string[] { _FormClassName, ", ", _FormAssemblyName });

            try
            {
                //Obtener la instancia del Formulario
                using (FrmBase f = (FrmBase)ReflectionFunctions.CreateInstance(wAssemblyInfo))
                {
                    //Busco en el archivo Configuration Manager el nombre de ensamblado, namespace y clase para crear diamicamente
                    //FrontClientes.frmModificacion , FrontClientes"

                    f.WindowState   = _FormWindowState;
                    f.StartPosition = _FormStartPosition;

                    if (_EntityParam != null)
                    {
                        f.EntityParam = _EntityParam;
                    }

                    f.ShowDialog();

                    if (f.EntityResult != null)
                    {
                        _EntityResult = f.EntityResult;
                    }
                }
                OnCloseFormEvent();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Inicializa un wrapper deacuerdo el nombre del proveedor
        /// Carga al wrapper el nombre
        /// </summary>
        /// <param name="providerName">Proveedor del wrapper. Este valor debe coincidir con un proveedor de metadata en el dispatcher</param>
        internal static void InitWrapper(string providerName)
        {
            //Si no se espesifica npmbre de provdor se da por entendido que se trata de un proveedor por defecto
            if (String.IsNullOrEmpty(providerName))
            {
                providerName = _DefaultProviderName;
            }
            if (!_WraperPepository.ContainsKey(providerName))
            {
                try
                {
                    WrapperProviderElement provider = _ProviderSection.GetProvider(providerName);

                    if (provider == null)
                    {
                        TechnicalException te;
                        if (providerName.Equals(_DefaultProviderName))
                        {
                            te = new TechnicalException(string.Concat("El proveedor de configuración del wrapper por defecto del lado del cliente, no existe, verifique en el archivo de configuracion si existe la seccion FwkWrapper y el proveedor por defecto"));
                        }
                        else
                        {
                            te = new TechnicalException(string.Concat("El proveedor de configuración del wrapper ", providerName, " del lado del cliente, no existe, verifique en el archivo de configuracion si existe la seccion FwkWrapper y el proveedor mencionado"));
                        }

                        te.ErrorId = "6000";
                        Fwk.Exceptions.ExceptionHelper.SetTechnicalException(te, typeof(WrapperFactory));
                        throw te;
                    }
                    ///No se almacenan mas providers con String.Empty
                    //if (provider.Name.Equals(_ProviderSection.DefaultProviderName)) providerName = String.Empty;



                    IServiceWrapper w = (IServiceWrapper)ReflectionFunctions.CreateInstance(provider.WrapperProviderType);

                    w.ProviderName = provider.Name;
                    w.SourceInfo   = provider.SourceInfo;
                    w.ServiceMetadataProviderName = provider.ServiceMetadataProviderName;
                    w.AppId = provider.AppId;
                    //w.DefaultCulture = provider.DefaultCulture;

                    _WraperPepository.Add(providerName, w);
                }
                catch (Exception ex)
                {
                    ServiceError       wServiceError = ProcessConnectionsException.Process(ex);
                    TechnicalException te            = new TechnicalException(wServiceError.Assembly, wServiceError.Namespace, wServiceError.Class, wServiceError.Machine, wServiceError.UserName, wServiceError.Message, ex);

                    throw te;
                }
            }
        }
Beispiel #7
0
        Type Try_get_reqType(string providerName, ServiceConfiguration serviceConfiguration)
        {
            try
            {
                Type reqType = ReflectionFunctions.CreateType(serviceConfiguration.Request);

                return(reqType);
            }
            catch (Exception ex)
            {
                throw get_TechnicalException_error_loading_req(serviceConfiguration, ex);
            }
        }
Beispiel #8
0
 /// <summary>
 /// Instancia y retorna un objeto tipo T.-
 /// </summary>
 /// <returns></returns>
 public T GetObject()
 {
     if (_SomeObject == null)
     {
         if (_ConstructorParams == null)
         {
             _SomeObject = (T)ReflectionFunctions.CreateInstance(string.Concat(typeof(T).FullName, ",", typeof(T).Assembly.FullName));
         }
         else
         {
             _SomeObject = (T)ReflectionFunctions.CreateInstance(string.Concat(typeof(T).FullName, ",", typeof(T).Assembly.FullName), _ConstructorParams);
         }
     }
     return(_SomeObject);
 }
Beispiel #9
0
 IServiceContract Try_get_IServiceContract(string providerName, ServiceConfiguration serviceConfiguration)
 {
     try
     {
         IServiceContract wRequest = (IServiceContract)ReflectionFunctions.CreateInstance(serviceConfiguration.Request);
         if (wRequest == null)
         {
             throw get_TechnicalException_error_loading_req(serviceConfiguration, null);
         }
         return(wRequest);
     }
     catch (Exception ex)
     {
         throw get_TechnicalException_error_loading_req(serviceConfiguration, ex);
     }
 }
        private static DbContext GetDbContext(this IQueryable queryable)
        {
            DbContext dbContext;

            try
            {
                object internalQuery   = ReflectionFunctions.GetReflectedMember(queryable, "InternalQuery");
                object internalContext = ReflectionFunctions.GetReflectedMember(internalQuery, "_internalContext");
                dbContext = (DbContext)ReflectionFunctions.GetReflectedMember(internalContext, "Owner");
            }
            catch (Exception e)
            {
                throw new ApplicationException("Unable to retreive db context from IQueryable", e);
            }
            return(dbContext);
        }
Beispiel #11
0
        /// <summary>
        /// Levanta la seccion FwkWrapper.-
        /// Inicialisa el repositorio de wrappers. (no lo llena con los wrappers)
        /// </summary>
        static WrapperFactory()
        {
            try
            {
                //Obtiene la la configuracion del wrapper del archivo .config
                _ProviderSection = ConfigurationManager.GetSection("FwkWrapper") as WrapperProviderSection;

                if (_ProviderSection == null)
                {
                    TechnicalException te = new TechnicalException(string.Concat("No se puede cargar la configuracion del wrapper en el cliente, verifique si existe la seccion [FwkWrapper] en el archivo de configuracion."));
                    te.ErrorId = "6000";
                    Fwk.Exceptions.ExceptionHelper.SetTechnicalException(te, typeof(WrapperFactory));
                    throw te;
                }

                _WraperPepository    = new Dictionary <string, IServiceWrapper>();
                _DefaultProviderName = _ProviderSection.DefaultProviderName;
                IServiceWrapper w = null;
                foreach (WrapperProviderElement provider in _ProviderSection.Providers)
                {
                    w = (IServiceWrapper)ReflectionFunctions.CreateInstance(provider.WrapperProviderType);
                    if (w == null)
                    {
                        TechnicalException te = new TechnicalException(string.Concat("No existe el tipo de wrapper: ", provider.WrapperProviderType));
                        te.ErrorId = "6000";
                        Fwk.Exceptions.ExceptionHelper.SetTechnicalException(te, typeof(WrapperFactory));
                        throw te;
                    }
                    w.ProviderName = provider.Name;
                    w.SourceInfo   = provider.SourceInfo;
                    w.ServiceMetadataProviderName = provider.ServiceMetadataProviderName;
                    w.AppId = provider.AppId;
                    //w.DefaultCulture = provider.DefaultCulture;
                    //if (provider.Name.Equals(_DefaultProviderName))
                    //    _WraperPepository.Add(String.Empty, w);
                    //else
                    _WraperPepository.Add(provider.Name, w);
                }
            }
            catch (System.Configuration.ConfigurationErrorsException ex)
            {
                TechnicalException te = new TechnicalException(string.Concat("No se puede cargar la configuracion del wrapper en el cliente, verifique si existe la seccion [FwkWrapper] en el archivo de configuracion."), ex);
                te.ErrorId = "6000";
                Fwk.Exceptions.ExceptionHelper.SetTechnicalException(te, typeof(WrapperFactory));
                throw te;
            }
        }
Beispiel #12
0
        public static DbContext GetDbContext <TEntity>(this DbSet <TEntity> dbSet) where TEntity : class
        {
            try
            {
                object internalSet     = ReflectionFunctions.GetReflectedMember(dbSet, "_internalSet");
                object internalContext = internalSet
                                         .GetType()
                                         .BaseType
                                         .GetField("_internalContext", BindingFlags.NonPublic | BindingFlags.Instance)
                                         .GetValue(internalSet);


                return((DbContext)ReflectionFunctions.GetReflectedMember(internalContext, "Owner"));
            }
            catch (Exception e)
            {
                throw new ApplicationException("Unable to retreive db context from DbSet", e);
            }
        }
        private void AddKeysForType <TComponentType>()
            where TComponentType : MonoBehaviour
        {
            var components = FindObjectsOfType <TComponentType>();

            foreach (var component in components)
            {
                var newlyFoundKeys = ReflectionFunctions.GetAttributeValuesOnTarget <EventOfInterestKeyAttribute, string>
                                     (
                    component
                                     ).ToList();

                for (var i = 0; i < newlyFoundKeys.Count(); i++)
                {
                    newlyFoundKeys[i] = "Key: " + newlyFoundKeys[i] + "\tObject Name: " + component.gameObject.name;
                }

                _foundKeys.AddRange(newlyFoundKeys);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Ejecuta un servicio de negocio.
        /// </summary>
        /// <param name="providerName">Nombre del proveedor de metadata de servicios.-</param>
        /// <param name="serviceName">Nombre del servicio de negocio.</param>
        /// <param name="jsonRequest">JSON con datos de entrada para la  ejecución del servicio.</param>
        /// <param name="hostContext">Info del despachador de servicio</param>
        /// <returns>JSON con el resultado de la  ejecución del servicio.</returns>
        /// <date>2008-04-07T00:00:00</date>
        /// <author>moviedo</author>
        public static string ExecuteServiceJson(string providerName, string serviceName, string jsonRequest, HostContext hostContext)
        {
            string wResult;

            ServiceConfiguration wServiceConfiguration = FacadeHelper.GetServiceConfiguration(providerName, serviceName);

            Type reqType = ReflectionFunctions.CreateType(wServiceConfiguration.Request);

            if (reqType == null)
            {
                TechnicalException te = new TechnicalException(string.Concat("El despachador de servicio no pudo continuar debido\r\na que no logro construir el requets del servicio: ",
                                                                             serviceName, "\r\nVerifique que se encuentre los componentes necesarios para su ejecucion esten en el servidor de aplicación. "));

                Fwk.Exceptions.ExceptionHelper.SetTechnicalException <StaticFacade>(te);

                if (string.IsNullOrEmpty(ConfigurationsHelper.HostApplicationName))
                {
                    te.Source = "Despachador de servicios en " + Environment.MachineName;
                }
                else
                {
                    te.Source = ConfigurationsHelper.HostApplicationName;
                }

                te.ErrorId = "7003";
                throw te;
            }
            var wRequest = (IServiceContract)Fwk.HelperFunctions.SerializationFunctions.DeSerializeObjectFromJson(reqType, jsonRequest);

            wRequest.ContextInformation.HostName = hostContext.HostName;
            wRequest.ContextInformation.HostIp   = hostContext.HostIp;
            IServiceContract res     = ExecuteService(providerName, (IServiceContract)wRequest);
            Type             resType = Type.GetType(wServiceConfiguration.Response);

            wResult = Fwk.HelperFunctions.SerializationFunctions.SerializeObjectToJson(resType, res);
            return(wResult);
        }
        internal static ObjectQuery GetObjectQuery(this IQueryable query)
        {
            object internalQueryField = ReflectionFunctions.GetReflectedMember(query, "_internalQuery");

            return(ReflectionFunctions.GetReflectedMember(internalQueryField, "_objectQuery") as ObjectQuery);
        }
Beispiel #16
0
        /// <summary>
        /// Ejecuta el servicio de negocio.
        /// </summary>
        /// <param name="pRequest">Request de entrada que se pasa al servicio</param>
        /// <param name="pServiceConfiguration">configuración del servicio.</param>
        /// <param name="pserviError">serviError</param>
        /// <returns>XML que representa el resultado de la  ejecución del servicio.</returns>
        /// <date>2007-08-07T00:00:00</date>
        /// <author>moviedo</author>
        static IServiceContract RunService(IServiceContract pRequest, ServiceConfiguration pServiceConfiguration, out ServiceError pserviError)
        {
            IServiceContract wResponse = null;

            try
            {
                pRequest.InitializeServerContextInformation();
                // obtención del Response.
                Type wServiceType = ReflectionFunctions.CreateType(pServiceConfiguration.Handler);

                object wServiceInstance = Activator.CreateInstance(wServiceType);
                wResponse =
                    (wServiceType.GetMethod("Execute").Invoke(wServiceInstance, new object[] { pRequest }) as
                     IServiceContract);

                wResponse.InitializeServerContextInformation();
            }

            #region [manage Exception]
            catch (FunctionalException fx)
            {
                fx.ServiceName = wResponse.ServiceName;
                //El response existe por q de otra manera no existiria una FunctionalException
                wResponse.Error = GetServiceError(fx);
            }
            catch (System.IO.FileNotFoundException ex)
            {
                wResponse = GetResponse(pServiceConfiguration);// (IServiceContract)ReflectionFunctions.CreateInstance(pServiceConfiguration.Response);

                wResponse.Error = new ServiceError();
                System.Text.StringBuilder wMessage = new StringBuilder();

                wResponse.Error.ErrorId = "7003";

                #region Message
                wMessage.Append("El despachador de servicio no pudo encontrar alguna de los siguientes assemblies \r\n");

                wMessage.Append("o alguna de sus dependencias: \r\n");

                wMessage.Append("Servicio: ");
                wMessage.Append(pServiceConfiguration.Handler);
                wMessage.Append(Environment.NewLine);

                wMessage.Append("Request: ");
                wMessage.Append(pServiceConfiguration.Request);
                wMessage.Append(Environment.NewLine);

                wMessage.Append("Response: ");
                wMessage.Append(pServiceConfiguration.Response);
                wMessage.Append(Environment.NewLine);

                wMessage.Append("Mensaje original :");
                wMessage.Append(Environment.NewLine);
                wMessage.Append(ex.Message);
                #endregion

                wResponse.Error.Message = wMessage.ToString();
                FillServiceError(wResponse.Error, ex);
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                wResponse       = GetResponse(pServiceConfiguration);
                wResponse.Error = GetServiceError(ex.InnerException);
            }
            catch (TypeLoadException tl)
            {
                wResponse = GetResponse(pServiceConfiguration);
                System.Text.StringBuilder wMessage = new StringBuilder();
                wResponse.Error = new ServiceError();

                wResponse.Error.ErrorId = "7002";
                wMessage.Append("No se encuentra el o los assemblies para cargar el servicio " + pServiceConfiguration.Name);
                wMessage.AppendLine();
                wMessage.AppendLine(tl.Message);
                wResponse.Error.Message = wMessage.ToString();
                FillServiceError(wResponse.Error, tl);
            }
            catch (Exception ex)
            {
                wResponse       = GetResponse(pServiceConfiguration);// (IServiceContract)ReflectionFunctions.CreateInstance(pServiceConfiguration.Response);
                wResponse.Error = GetServiceError(ex);
            }

            #endregion

            pserviError = wResponse.Error;

            #region < Log >
            //Audito ensegundo plano
            Action actionAudit = () => { DoAudit(pServiceConfiguration, pRequest, wResponse); };
            Task.Factory.StartNew(actionAudit);


            #endregion



            return(wResponse);
        }
Beispiel #17
0
 public void ReflectionFunctionsGetWithParamsTest()
 {
     Assert.AreEqual(8.0, ReflectionFunctions.GetWithParams("Math.Sqrt", new object[] { "64" }), "ok");
 }
Beispiel #18
0
 public void ReflectionFunctionsGetTest(string expression, object expected, string message) =>
 Assert.AreEqual(expected.ToString(), ReflectionFunctions.Get(expression).ToString(), message);
Beispiel #19
0
 public void ReflectionFunctionsGetOfTest(string method, object inputObject, object expected, string message) =>
 Assert.AreEqual(expected, ReflectionFunctions.GetOf(method, inputObject.ToString()).ToString(), message);
Beispiel #20
0
 public void ReflectionFunctionsGetOfNullMethodTest() => ReflectionFunctions.GetOf(null, null);
Beispiel #21
0
 public void ReflectionFunctionsGetOfMissingStaticMethodTest() => ReflectionFunctions.GetOf("Math.Wrong", null);
Beispiel #22
0
 public void ReflectionFunctionsGetOfMissingMethodForStringTest() => ReflectionFunctions.GetOf("Wrong", "hello");
Beispiel #23
0
 public void ReflectionFunctionsGetOfMissingMethodForIntTest() => ReflectionFunctions.GetOf("Wrong", "1");
Beispiel #24
0
 public void ReflectionFunctionsGetOfMissingMethodAndInputTest() => ReflectionFunctions.GetOf("Wrong", null);
Beispiel #25
0
 public void ReflectionFunctionsGetOfMissingClassTest() => ReflectionFunctions.GetOf("Wrong.Wrong", null);
Beispiel #26
0
 public void ReflectionFunctionsGetOfMethodWithoutDecimalParametersTest() => ReflectionFunctions.GetOf("substring(1.0)", "a");
 public void CommonFunctionsGetOfExceptionTest()
 {
     ReflectionFunctions.Get(string.Empty);
 }