Exemplo n.º 1
0
        /// <summary>
        /// 发送指令
        /// </summary>
        /// <param name="ins"></param>
        private bool SendInstruct(Instruct[] ins, bool isSync)
        {
            if (IsDisposed)
            {
                return(false);
            }

            watch.Reset();
            watch.Start();


            ClientInstruct[] instructs = new ClientInstruct[ins.Length];

            int i = 0;

            //转换
            foreach (Instruct instruct in ins)
            {
                ClientInstruct clientInstruct = new ClientInstruct();
                clientInstruct.InstructID = instruct.InstructID;
                if (instruct.Datas != null)
                {
                    clientInstruct.Datas = instruct.Datas.Trim('\0');
                }
                else
                {
                    clientInstruct.Datas = string.Empty;
                }
                clientInstruct.InstructType   = (int)instruct.InstructType;
                clientInstruct.CreateDateTime = instruct.CreateDate;
                clientInstruct.TargetID       = instruct.TargetID;
                instructs[i++] = clientInstruct;
            }

            try
            {
                ClientService.ReceiveInstruct(instructs);
            }
            catch (SoapException ex)//客户端异常, 跳过
            {
                LogHelper.CreateLog(ex, ex.Message + "(指令被跳过)", string.Format("passport_{0}_Exception_{1}.log", this.Client.ClientID, DateTime.Now.ToString("yyyyMMdd")));
                if (isSync)
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                LogHelper.CreateLog(ex, ex.Message, string.Format("passport_{0}_Exception_{1}.log", this.Client.ClientID, DateTime.Now.ToString("yyyyMMdd")));

                if (isSync)
                {
                    throw;
                }
                watch.Reset();
                return(false);
            }

            SendCount++;
            watch.Stop();
            ElapsedTime += watch.Elapsed.TotalMilliseconds;
            if (watch.ElapsedMilliseconds > 500)
            {
                string msg = string.Concat(
                    "InstructType = " + ins[0].InstructType, "\r\n"
                    , "Time = ", watch.Elapsed.TotalSeconds, "\r\n"
                    , " ClientID=", this.Client.ClientID, "\r\n");

                LogHelper.CreateLog(null, msg, string.Format("InstructCall_{0}.txt", DateTime.Now.ToString("yyyy-MM-dd")));
            }

            return(true);
        }