示例#1
0
        public string Echo(string msg)
        {
            try
            {
                lockEcho.WaitOne();
                if (lastEchoTime != null && lastEchoTime.HasValue)
                {
                    TimeSpan timespan = System.DateTime.Now - lastEchoTime.Value;
                    if (timespan.Ticks < new TimeSpan(0, 0, 0, 0, 500).Ticks)
                    {
                        if (echoSuccessful)
                        {
                            return(msg);
                        }
                        else
                        {
                            throw new Exception("echo error");
                        }
                    }
                }

                CDIServiceClient client = new CDIServiceClient(CurrentData.Instance.EndPointName);
                try
                {
                    string retu = client.Echo(msg);
                    echoSuccessful = true;
                    lastEchoTime   = System.DateTime.Now;
                    return(retu);
                }
                catch (Exception ex)
                {
                    CurrentData.Instance.Logger.Error(ex);
                    throw;
                }
                finally
                {
                    Task.Factory.StartNew(() => client.Close());
                }
            }
            finally
            {
                lockEcho.Set();
            }
        }
示例#2
0
        private T RunAction <T>(Func <CDIServiceClient, T> handleAction) where T : ResponseModel
        {
            CDIServiceClient client = new CDIServiceClient(CurrentData.Instance.EndPointName);
            T retu = default(T);

            try
            {
                retu = handleAction(client);
            }
            catch (Exception ex)
            {
                CurrentData.Instance.Logger.Error(ex);
                throw;
            }
            finally
            {
                Task.Factory.StartNew(() => client.Close());
            }
            return(retu);
        }