/// <summary>
        /// Called when a corresponding asynchronous send operation completes.
        /// </summary>
        /// <param name="result">The result of the asynchronous operation.</param>
        private static void AsyncSendCallback(IAsyncResult result)
        {
            TrackbackResponse response       = null;
            WebRequest        httpWebRequest = null;
            TrackbackClient   client         = null;
            Uri host = null;
            TrackbackMessage  message   = null;
            WebRequestOptions options   = null;
            object            userToken = null;

            if (result.IsCompleted)
            {
                object[] parameters = (object[])result.AsyncState;
                httpWebRequest = parameters[0] as WebRequest;
                client         = parameters[1] as TrackbackClient;
                host           = parameters[2] as Uri;
                message        = parameters[3] as TrackbackMessage;
                options        = parameters[4] as WebRequestOptions;
                userToken      = parameters[5];

                if (client != null)
                {
                    WebResponse httpWebResponse = (WebResponse)httpWebRequest.EndGetResponse(result);

                    response = new TrackbackResponse(httpWebResponse);

                    client.OnMessageSent(new TrackbackMessageSentEventArgs(host, message, response, options, userToken));

                    client.SendOperationInProgress = false;
                }
            }
        }
Ejemplo n.º 2
0
        //============================================================
        //	CALLBACK DELEGATE METHODS
        //============================================================
        #region AsyncSendCallback(IAsyncResult result)
        /// <summary>
        /// Called when a corresponding asynchronous send operation completes.
        /// </summary>
        /// <param name="result">The result of the asynchronous operation.</param>
        private static void AsyncSendCallback(IAsyncResult result)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            TrackbackResponse response       = null;
            WebRequest        httpWebRequest = null;
            TrackbackClient   client         = null;
            Uri host = null;
            TrackbackMessage  message   = null;
            WebRequestOptions options   = null;
            object            userToken = null;

            //------------------------------------------------------------
            //	Determine if the async send operation completed
            //------------------------------------------------------------
            if (result.IsCompleted)
            {
                //------------------------------------------------------------
                //	Extract the send operations parameters from the user state
                //------------------------------------------------------------
                object[] parameters = (object[])result.AsyncState;
                httpWebRequest = parameters[0] as WebRequest;
                client         = parameters[1] as TrackbackClient;
                host           = parameters[2] as Uri;
                message        = parameters[3] as TrackbackMessage;
                options        = parameters[4] as WebRequestOptions;
                userToken      = parameters[5];

                //------------------------------------------------------------
                //	Verify expected parameters were found
                //------------------------------------------------------------
                if (client != null)
                {
                    //------------------------------------------------------------
                    //	Get the Trackback response to the Trackback ping request
                    //------------------------------------------------------------
                    WebResponse httpWebResponse = (WebResponse)httpWebRequest.EndGetResponse(result);

                    //------------------------------------------------------------
                    //	Extract the Trackback response to the Trackback ping request
                    //------------------------------------------------------------
                    response = new TrackbackResponse(httpWebResponse);

                    //------------------------------------------------------------
                    //	Raise SendCompleted event to notify registered handlers of state change
                    //------------------------------------------------------------
                    client.OnMessageSent(new TrackbackMessageSentEventArgs(host, message, response, options, userToken));

                    //------------------------------------------------------------
                    //	Reset async operation in progress indicator
                    //------------------------------------------------------------
                    client.SendOperationInProgress = false;
                }
            }
        }