Ejemplo n.º 1
0
        public override void Send(MailEntity entity, Dictionary <string, string> parameters)
        {
            if (entity == null)
            {
                return;
            }
            string url;

            if (!parameters.TryGetValue("url", out url) || url == null || url.Trim().Length <= 0)
            {
                throw new ConfigurationErrorsException("Not config 'url' for restful mail sender.");
            }
            string method;

            if (!parameters.TryGetValue("method", out method) || method == null || method.Trim().Length <= 0)
            {
                throw new ConfigurationErrorsException("Not config 'method' for restful mail sender.");
            }

            SoapEntityMapping.Add <MailEntity>();
            SoapEntityMapping.Add <MailTemplateEntity>();
            SoapEntityMapping.Add <VariableTable>();
            SoapEntityMapping.Add <Variable>();
            SoapClient.Invoke(url, method, entity);
        }
Ejemplo n.º 2
0
        private static object[] GetArgs(object[] args, Assembly asy)
        {
            if (args == null)
            {
                return(null);
            }
            List <object> list = new List <object>(args.Length * 2);

            for (int i = 0; i < args.Length; i++)
            {
                object x = SoapEntityMapping.ConvertToSoapObject(args[i], asy);
                list.Add(x);
                Type t = args[i].GetType();
                if (t.IsValueType)
                {
                    if (t.IsNullableType())
                    {
                        list.Add(args[i] != null);
                    }
                    else
                    {
                        list.Add(true);
                    }
                }
            }
            return(list.ToArray());
        }
Ejemplo n.º 3
0
        public static T Invoke <T>(string url, string methodName, params object[] args)
        {
            object proxy = CreateServiceProxyInstance(url);

            object[] realArgs = GetArgs(args, proxy.GetType().Assembly);
            if (typeof(T).IsValueType)
            {
                T             obj      = default(T);
                bool          hasValue = false;
                List <object> list     = new List <object>(realArgs);
                list.Add(obj);
                list.Add(hasValue);
                object[]   x  = list.ToArray();
                MethodInfo me = proxy.GetType().GetMethod(methodName);
                me.Invoke(proxy, x);
                hasValue = (bool)x[x.Length - 1];
                if (hasValue)
                {
                    object tmp = x[x.Length - 2];
                    return((T)SoapEntityMapping.ConvertFromSoapObject(tmp, typeof(T)));
                }
                else
                {
                    return(default(T));
                }
            }
            else
            {
                object tmp = Invoker.MethodInvoke(proxy, methodName, realArgs);
                return((T)SoapEntityMapping.ConvertFromSoapObject(tmp, typeof(T)));
            }
        }
Ejemplo n.º 4
0
        public static void InvokeAsync <T>(string url, string methodName, Action <T> callback, Action <Exception> errorHandler, params object[] args)
        {
            object proxy = CreateServiceProxyInstance(url);

            object[] realArgs        = GetArgs(args, proxy.GetType().Assembly);
            Type     t               = proxy.GetType();
            string   beginMethodName = "Begin" + methodName;
            string   endMethodName   = "End" + methodName;
            //MethodInfo beginMethod = t.GetMethod("Begin" + methodName);
            MethodInfo    endMethod = t.GetMethod(endMethodName);
            AsyncCallback cb        = ar =>
            {
                T    obj      = default(T);
                bool hasError = false;
                try
                {
                    if (typeof(T).IsValueType)
                    {
                        bool     hasValue = false;
                        object[] args1    = new object[] { ar, obj, hasValue };
                        endMethod.Invoke(ar.AsyncState, args1);
                        hasValue = (bool)args1[2];
                        if (hasValue)
                        {
                            obj = (T)SoapEntityMapping.ConvertFromSoapObject(args1[1], typeof(T));
                        }
                        else
                        {
                            obj = default(T);
                        }
                    }
                    else
                    {
                        object tmp = Invoker.MethodInvoke(ar.AsyncState, endMethodName, ar);
                        obj = (T)SoapEntityMapping.ConvertFromSoapObject(tmp, typeof(T));
                    }
                }
                catch (Exception ex)
                {
                    hasError = true;
                    if (errorHandler != null)
                    {
                        errorHandler(ex);
                    }
                }
                if (hasError == false && callback != null)
                {
                    callback(obj);
                }
            };
            List <object> list = new List <object>(realArgs);

            list.Add(cb);
            list.Add(proxy);
            Invoker.MethodInvoke(proxy, beginMethodName, list.ToArray());
        }
Ejemplo n.º 5
0
 public void EmitLog(LogEntry log)
 {
     SoapEntityMapping.Add <LogEntry>();
     SoapEntityMapping.Add <ExtendedPropertyData>();
     SoapClient.InvokeAsync(m_Url, m_MethodName, null, ex =>
     {
         string message = string.Format("Write log failed.\r\n\r\n Error Info: {0}. \r\n\r\n Log Type: {1}. \r\n\r\n Log Info: {2}", ex.ToString(), this.GetType().AssemblyQualifiedName, log.SerializationWithoutException());
         Logger.WriteEventLog(message, System.Diagnostics.EventLogEntryType.Error);
     }, log);
 }