Esempio n. 1
0
        public void Initialize(Message rootMessage)
        {
            RootMessage = _messageFactory.MakeMessageViewModel(rootMessage);
            RootMessage.LoadSender();

            AllMessages.Add(RootMessage);

            SelfIsSender = _sessionService.LoggedInUser.Id == rootMessage.SenderId;
        }
        /// <remarks>Used for fatal exception messages caugth by the LongPollingHandler</remarks>
        internal LongPollingConnection(RootMessage message, HttpContext httpContext, AsyncCallback asyncCallback, object asyncState)
        {
            ASSERT( message != null, "Missing parameter 'message'" );
            ASSERT( httpContext != null, "Missing parameter 'httpContext'" );

            AsyncState = asyncState;

            HttpContext = httpContext;
            AsyncCallback = asyncCallback;

            SendResponseMessageSynchroneously( message );
        }
 /// <remarks>Can only be called from LongPollingHandler</remarks>
 internal void SendResponseMessageSynchroneously(RootMessage responseMessage)
 {
     CompletedSynchronously = true;
     SendResponseMessage( responseMessage );
 }
        /// <remarks>
        /// WARNING: Every calls to this method should be performed outside any lock()s because the call to "AsyncCallback(this)" will try to create a new thread.<br/>
        /// Example dead-lock scenario:<br/>
        /// Under heavy load, all worker threads are busy and they are all waiting for a lock() to liberate.<br/>
        /// One of the worker thread is calling this method from inside of this lock().<br/>
        /// This thread will try to create a new thread from the "AsyncCallback(this)".<br/>
        /// The problem is that "AsyncCallback(this)" will then hang, waiting for a worker slot thread to liberate...
        /// </remarks>
        public void SendResponseMessage(RootMessage responseMessage)
        {
            ASSERT( responseMessage != null, "Missing parameter 'responseMessage'" );

            LOG( "SendResponseMessage(" + responseMessage + ") - Start" );
            try
            {
                ResponseMessage = responseMessage;

                // Declare message as completed
                int oldIsCompleted = Interlocked.Exchange( ref isCompleted, 1 );
                if( oldIsCompleted != 0 )
                    throw new InvalidOperationException( GetType().FullName + "::" + System.Reflection.MethodInfo.GetCurrentMethod().Name + "() can only be called once" );

                // Invoke callback that will invoke LongPollingHandler.EndProcessRequest()
                LOG( "SendResponseMessage(" + responseMessage + ") - AsyncCallback is " + (AsyncCallback != null ? "not null" : "null") );
                if( AsyncCallback != null )
                    AsyncCallback( this );

                LOG( "SendResponseMessage(" + responseMessage + ") - Exit" );
            }
            catch( System.Exception ex )
            {
                LOG( "*** Error while terminating the HTTP request - Could not invoke the request's callback (" + ex.GetType().FullName + "): " + ex.Message );
            }
        }