예제 #1
0
        /// <summary>
        /// 客户端接收到数据
        /// </summary>
        /// <param name="tcpClient"></param>
        /// <param name="saea"></param>
        /// <param name="clientErrorType"></param>
        private void OnReceive(HHTcpClient tcpClient, SocketAsyncEventArgs saea, ClientErrorType clientErrorType)
        {
            if (clientErrorType != ClientErrorType.Success)
            {
                Close(clientErrorType);
                return;
            }
            if (HttpProxySessionInfo.HeadLength == -1)//尚为解析协议头
            {
                if (HttpProxySessionInfo.MemoryStream == null)
                {
                    HttpProxySessionInfo.MemoryStream = new System.IO.MemoryStream();
                }
                HttpProxySessionInfo.MemoryStream.Write(saea.Buffer, saea.Offset, saea.BytesTransferred);

                ToParseQuery();//解析协议头
            }
            else
            {
                if (DSsaea == null)
                {
                    DSsaea = new SocketAsyncEventArgs();
                }
                //直接转发就行了
                DSsaea.SetBuffer(saea.Buffer, saea.Offset, saea.BytesTransferred);
                if (!desTcpCliet.BeginSend(DSsaea, out var errorType))
                {
                    Close(errorType);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// 目的地发送数据结束
 /// </summary>
 /// <param name="tcpClient"></param>
 /// <param name="saea"></param>
 /// <param name="clientErrorType"></param>
 private void DOnSendEnd(HHTcpClient tcpClient, SocketAsyncEventArgs saea, ClientErrorType clientErrorType)
 {
     if (clientErrorType != ClientErrorType.Success)
     {
         Close(clientErrorType);
     }
     else
     {
         if (connectedOver == 0)
         {
             connectedOver = 1;
             if (DRsaea == null)
             {
                 int l = ReceiveBufferSize;
                 DRsaea    = new SocketAsyncEventArgs();
                 DReBuffer = new byte[l];
                 DRsaea.SetBuffer(DReBuffer, 0, DReBuffer.Length);
             }
             if (!desTcpCliet.BeginReceive(DRsaea, out var errorType))
             {
                 Close(errorType);
             }
             //Console.WriteLine($"连接已建立");
         }
         HttpProxySessionInfo.AddSendNum(saea.BytesTransferred);
         //Console.WriteLine($"发送给目的地 {saea.BytesTransferred}");
         if (!cTcpClient.BeginReceive(Rsaea, out var errorType1))
         {
             Close(errorType1);
         }
     }
 }
        public ErrClientWorkTypeViewModel(IErrClientWorkTypeView view)
            : base(view)
        {
            ThisView = view;

            RefreshCommand = new MedQuist.BillingAdmin.ViewModels.SimpleCommand
            {
                CanExecuteDelegate = x => (true),
                ExecuteDelegate    = x => Refresh()
            };

            ErrClientErrorTypeTarget = Spheris.Billing.Data.BillingDataFactory.NewInstance().CreateErrClientErrorRepository();
            ClientErrorTypes         = ErrClientErrorTypeTarget.GetClientErrorTypes();

            //ClientErrorTypes.ForEach((thislist, eachContract) => RemoveWeakEventListener(eachContract, ContractRateListener));

            SelectedClientErrorType = new ClientErrorType()
            {
                DESC = "All", EXT_CLIENT_ERR_TYPE = "*"
            };
            if (ClientErrorTypes != null)
            {
                ClientErrorTypes.Insert(0, SelectedClientErrorType);
            }
            ErrClientWorkTypeTarget = Spheris.Billing.Data.BillingDataFactory.NewInstance().CreateErrClientWorkTypeRepository();
        }
예제 #4
0
 protected override void RowConverter(ClientErrorType r, DataRow record)
 {
     try
     {
         r.DESC = CastDbValueRow(record, "DESCR");
         r.EXT_CLIENT_ERR_TYPE = CastDbValueRow(record, "EXT_CLIENT_ERR_TYPE");
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #5
0
        private static void OnPorxyOver(HttpProxySessionInfo httpProxySessionInfo, ClientErrorType errorType)
        {
            string msg = $"本次代理结束:{httpProxySessionInfo.HttpRequestType} {httpProxySessionInfo.HttpPath} {httpProxySessionInfo.HttpVersion} {Environment.NewLine}"
                         + $"Host: {httpProxySessionInfo.Host} {Environment.NewLine}"
                         + $"Port: {httpProxySessionInfo.Port} {Environment.NewLine}"
                         + $"累计转发到目的地: {httpProxySessionInfo.AllSendLength} {Environment.NewLine}"
                         + $"累计转发到客户端: {httpProxySessionInfo.AllRetLength} {Environment.NewLine}"
                         + $"结束原因: {errorType.ToString()} {Environment.NewLine}"
                         + $"持续时间: {(httpProxySessionInfo.LastActionTime - httpProxySessionInfo.ConnectTime).TotalMilliseconds}ms {Environment.NewLine}"
                         + $"当前时间: {DateTime.Now.ToLocalTime().ToString()} {Environment.NewLine}"
                         + $"连接时间: {httpProxySessionInfo.ConnectTime.ToLocalTime().ToString()} {Environment.NewLine}"
                         + $"最后连接时间: {httpProxySessionInfo.LastActionTime.ToLocalTime().ToString()} {Environment.NewLine}";

            Console.WriteLine(msg);
        }
예제 #6
0
        /// <summary>
        /// 结束本地代理会话
        /// </summary>
        public void Close(ClientErrorType clientErrorType)
        {
            if (Interlocked.CompareExchange(ref Closing, 1, 0) == 0)
            {
                desTcpCliet?.Close();
                cTcpClient.Close();

                Rsaea?.Dispose();
                DRsaea?.Dispose();

                Ssaea?.Dispose();
                DSsaea?.Dispose();

                OnClose?.Invoke(HttpProxySessionInfo, clientErrorType);
            }
        }
예제 #7
0
 /// <summary>
 /// 目的地接收到数据
 /// </summary>
 /// <param name="tcpClient"></param>
 /// <param name="saea"></param>
 /// <param name="clientErrorType"></param>
 private void DOnReceive(HHTcpClient tcpClient, SocketAsyncEventArgs saea, ClientErrorType clientErrorType)
 {
     if (clientErrorType != ClientErrorType.Success)
     {
         Close(clientErrorType);
     }
     else
     {
         if (Ssaea == null)
         {
             Ssaea = new SocketAsyncEventArgs();
         }
         //直接转发就行了
         Ssaea.SetBuffer(saea.Buffer, saea.Offset, saea.BytesTransferred);
         if (!cTcpClient.BeginSend(Ssaea, out var errorType))
         {
             Close(errorType);
         }
     }
 }
예제 #8
0
 /// <summary>
 /// 客户端异常时
 /// </summary>
 /// <param name="tcpClient"></param>
 /// <param name="clientErrorType"></param>
 /// <param name="exc"></param>
 private void OnError(HHTcpClient tcpClient, ClientErrorType clientErrorType, Exception exc)
 {
     Close(clientErrorType);
 }
예제 #9
0
 internal ErrorClientArgs(ClientErrorType type, string message)
 {
     Type    = type;
     Message = message;
 }
예제 #10
0
 /// <summary>
 /// Вызов событий об ошибках
 /// </summary>
 /// <param name="type">тип ошибки</param>
 /// <param name="message">сообщение об ошибке</param>
 internal void CallErrorClient(ClientErrorType type, string message)
 {
     Task.Factory.StartNew(() => ClientErrors?.Invoke(this, new ErrorClientArgs(type, message)));
 }