コード例 #1
0
ファイル: StructElement.cs プロジェクト: Yellllllow/swb
 public StructElement(Object obj)
 {
     foreach (FieldInfo fieldInfo in obj.GetType().GetFields())
     {
         object value = fieldInfo.GetValue(obj);
         if (value != null)
         {
             Value  ovalue = XmlRpcClient.GetParameter(value);
             Member member = new Member(fieldInfo.Name, ovalue);
             _values.Add(member);
         }
     }
 }
コード例 #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();
            }
        }