示例#1
0
 private Task <TaskResult> ServiceRunTask(Func <EGESupportClient, object> Func, string login = null, string password = null)
 {
     return(Task <TaskResult> .Factory.StartNew(() =>
     {
         TaskResult res = new TaskResult();
         EGESupportClient service = GetService(login, password);
         try
         {
             res.result = Func(service);
         }
         catch (Exception error)
         {
             if ((error is FaultException <Fault>))
             {
                 res.fault = ((FaultException <Fault>)error).Detail;
             }
             else if (error.InnerException != null && error.InnerException is FaultException <Fault> )
             {
                 res.fault = ((FaultException <Fault>)error.InnerException).Detail;
             }
             else if (error.InnerException != null)
             {
                 res.fault = new Fault()
                 {
                     Token = "error", Message = error.InnerException.Message
                 }
             }
             ;
             else
             {
                 res.fault = new Fault()
                 {
                     Token = "error", Message = error.Message
                 }
             };
         }
         finally
         {
             if (service.State == CommunicationState.Faulted)
             {
                 service.Abort();
             }
             else
             {
                 service.Close();
             }
             service = null;
         }
         return res;
     }));
 }
示例#2
0
        //private void ServiceRun<T>(EGESupportClient service, T result, Exception error, Action<T, Fault> FuncComplete, Action<T> Func)
        //{
        //    try
        //    {
        //        if (error != null)
        //        {
        //            if (error is FaultException<Fault>)
        //                FuncComplete(default(T), ((FaultException<Fault>)error).Detail);
        //            else
        //                FuncComplete(default(T), new Fault() { Token = "error", Message = error.Message });
        //        }
        //        else
        //        {
        //            Func(result);
        //            FuncComplete(result, null);
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        FuncComplete(default(T), new Fault() { Token = "error", Message = e.Message });
        //    }
        //    finally
        //    {
        //        if (service.State == CommunicationState.Faulted)
        //            service.Abort();
        //        else
        //            service.Close();
        //        service = null;
        //    }
        //}

        private async void ServiceRunTask(Action <Fault> FuncComplete, Func <EGESupportClient, Task> Func)
        {
            EGESupportClient service = GetService(null, null);

            try
            {
                await Func(service);
            }
            catch (Exception error)
            {
                if ((error is FaultException <Fault>))
                {
                    FuncComplete(((FaultException <Fault>)error).Detail);
                }
                else if (error.InnerException != null && error.InnerException is FaultException <Fault> )
                {
                    FuncComplete(((FaultException <Fault>)error.InnerException).Detail);
                }
                else if (error.InnerException != null)
                {
                    FuncComplete(new Fault()
                    {
                        Token = "error", Message = error.InnerException.Message
                    });
                }
                else
                {
                    FuncComplete(new Fault()
                    {
                        Token = "error", Message = error.Message
                    });
                }
            }
            finally
            {
                if (service.State == CommunicationState.Faulted)
                {
                    service.Abort();
                }
                else
                {
                    service.Close();
                }
                service = null;
            }
        }