Example #1
0
        public static object Create(Type itf)
        {
            Type proxyType;

            lock (_types)
            {
                proxyType = (Type)_types[itf];
                if (proxyType == null)
                {
                    Guid            guid         = Guid.NewGuid();
                    string          assemblyName = "XmlRpcProxyFactory" + guid.ToString();
                    string          moduleName   = "XmlRpcProxyFactory" + guid.ToString() + ".dll";
                    string          typeName     = "XmlRpcProxyFactory" + guid.ToString();
                    AssemblyBuilder assBldr      = BuildAssembly(itf, assemblyName,
                                                                 moduleName, typeName);
                    proxyType = assBldr.GetType(typeName);
                    _types.Add(itf, proxyType);
                }
            }
            try
            {
                object ret = Activator.CreateInstance(proxyType);
                return(ret);
            }
            catch (Exception e)
            {
                XmlRpcTraceEventLogListener.WriteError(e);
            }
            return(null);
        }
Example #2
0
        public object Invoke(MethodInfo mi, params object[] parameters)
        {
            try
            {
                XmlRpcClientConfig config = new XmlRpcClientConfig(this.WebAddress);
                config.ProxyServer = this.ProxyServer;
                config.ProxyPort   = this.ProxyPort;
                if (this.Credentials != null)
                {
                    config.Password = this.Credentials.Password;
                    config.UserName = this.Credentials.UserName;
                }
                string       rpcMethodName = GetRpcMethodName(mi);
                XmlRpcClient client        = new XmlRpcClient(config);
                Type         type          = client.GetType();
                object[]     args          = new object[4];
                args[0]            = rpcMethodName;
                args[1]            = parameters;
                args[2]            = Attachments;
                this.ResponseParts = new HashSet <Part>();
                args[3]            = this.ResponseParts;
                System.Reflection.MethodInfo executeMethod = type.GetMethod("Execute");
                if (mi.ReturnType.Name != "Void")
                {
                    executeMethod = executeMethod.MakeGenericMethod(mi.ReturnType);
                }
                else
                {
                    Type[] types = { typeof(string) };
                    executeMethod = executeMethod.MakeGenericMethod(types);
                }
                object ObjToReturn = executeMethod.Invoke(client, args);
                this.ResponseParts = (HashSet <Part>)args[3];
                return(ObjToReturn);
            }
            catch (TargetInvocationException ex)
            {
                XmlRpcTraceEventLogListener.WriteError(ex);
                Exception e = ex.GetBaseException();
                if (e is SocketException)
                {
                    MessageBox.Show("Existe un error de comunicación con el publicador.\r\nPuede que el sistema este inestable debido a esta situación.\r\nCierre la aplicación y vuelva a intentar la operación.\r\nDetalle: " + e.Message, "Error de comunicación", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    XmlRpcTraceEventLogListener.WriteError(e);
                    throw e;
                }
                else
                {
                    throw e;
                }
            }
            catch (XmlRpcException webex)
            {
                XmlRpcTraceEventLogListener.WriteError(webex);
                throw webex;
            }
            catch (WebException webex)
            {
                XmlRpcTraceEventLogListener.WriteError(webex);
                throw webex;
            }

            catch (NullReferenceException webex)
            {
                XmlRpcTraceEventLogListener.WriteError(webex);
                throw webex;
            }
            finally
            {
                this.Attachments.Clear();
            }
        }