コード例 #1
0
        /// <summary>
        /// Event call from Worker Process, sends ReponseEventArgs to ResponseCallbackDelegate on callee.
        /// </summary>
        /// <param name="packet"> The PacketStateData.</param>
        private void ReturnResponseBuffer(PacketStateData packet)
        {
            //respBuffer.ContinueHeader = base.ContinueHeader;
            ResponseEventArgs args = new ResponseEventArgs();
            args.Response = packet.ResponseData;
            args.State = packet.HttpStateData;
            // args.TestItem = packet.HttpStateData.TestItem;
            // args.IsSessionLastItem = packet.HttpStateData.IsLastItem;

            // return response in a event
            EndHttp(this, args);
        }
コード例 #2
0
        /// <summary>
        /// Callback method that returns the PacketStateData from WorkerProcess and dynamically invokes the delegate associated with the state.
        /// </summary>
        /// <param name="data"> The PacketStateData.</param>
        private void WorkerProcess_ReturnPacketEvent(PacketStateData data)
        {
            PacketStateData d = data;
            Delegate method = d.CallerMethod;
            object[] a = {data};

            try
            {
                method.DynamicInvoke(a);
            }
            catch ( Exception ex)
            {
                ExceptionHandler.RegisterException(ex);
            }
        }
コード例 #3
0
        /// <summary>
        /// Callback method that sends the request to the WorkerProcess for further processing.
        /// It handles each request sequencially without blocking the asynchronous request.
        /// </summary>
        /// <param name="ar"> The IAsyncResult from async request.</param>
        protected void FastResponseCallback2(IAsyncResult ar)
        {
            HttpState httpState = (HttpState)ar.AsyncState;
            PacketStateData packet =  new PacketStateData();

            try
            {
                HttpWebResponse response = (HttpWebResponse)httpState.HttpRequest.EndGetResponse(ar);

                // Save response , httpState in packet
                packet.HttpStateData = httpState;
                packet.WebResponse = response;
                packet.CallerMethod = new ReturnPacket(ReturnResponseBuffer);
                packet.ClientSettings = this.ClientSettings;
                packet.ProxySettings = this.ProxySettings;

            }
            catch (WebException wex)
            {
                if ( wex.Status == WebExceptionStatus.ProtocolError )
                {
                    packet.HttpStateData = httpState;
                    packet.WebResponse = (HttpWebResponse)wex.Response;
                    packet.CallerMethod = new ReturnPacket(ReturnResponseBuffer);
                    packet.ClientSettings = this.ClientSettings;
                    packet.ProxySettings = this.ProxySettings;
                }
                else
                {
                    ExceptionHandler.RegisterException(wex);
                    packet.HttpStateData = httpState;
                    packet.WebResponse = null;
                    packet.ErrorMessage = wex.Message;
                    packet.CallerMethod = new ReturnPacket(ReturnResponseBuffer);
                    packet.ClientSettings = this.ClientSettings;
                    packet.ProxySettings = this.ProxySettings;
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.RegisterException(ex);
                packet.HttpStateData = httpState;
                packet.WebResponse = null;
                packet.ErrorMessage = ex.Message;
                packet.CallerMethod = new ReturnPacket(ReturnResponseBuffer);
                packet.ClientSettings = this.ClientSettings;
                packet.ProxySettings = this.ProxySettings;
            }

            // enter lock and signaled event
            Monitor.Enter( WorkerProcess.ReceiveList );

            WorkerProcess.ReceiveList.Add(packet);
            WorkerProcess.ReceiveEvent.Set();

            Monitor.Exit( WorkerProcess.ReceiveList );
        }