示例#1
0
        private void MockServer_ReadCompleted(object sender, AsyncReadEventArgs e)
        {
            connectionId = e.ConnectionId;
            inboundMesageQueue.TryAdd(e.ConnectionId, e);

            syncEvent.Release();
        }
        /// <summary>
        /// Receives a message from the messaging server instance
        /// </summary>
        /// <returns>An instance of <see cref="AsyncReadEventArgs"/> class containing the message that was received</returns>
        public AsyncReadEventArgs ReceiveServerMessage()
        {
            int connectionId = ConnectionId;

            System.Diagnostics.Trace.WriteLine(
                $"MessageOperationHandler.GetNextMessage() invoked for URL: {Url}",
                "TransMock.MessageOperationHandler");


            AsyncReadEventArgs receivedMessage = null;
            bool messageReceived = false;
            int  retryCount      = 0;

            while (!messageReceived)
            {
                // Now we wait for the reception of a message
                //bool waitElapsed = serverMessageReceivedEvent.Wait(TimeoutInSeconds * 1000);
                bool waitElapsed = receiveMessageSemaphore.Wait(TimeoutInSeconds * 1000);
                // Getting the connection Id right after exiting the wait
                connectionId = ConnectionId;

                System.Diagnostics.Debug.WriteLine(
                    $"MessageOperationHandler.GetNextMessage() exited the wait for endpoint with URL: {Url}, connection id: {connectionId}.",
                    "TransMock.MessageOperationHandler");

                try
                {
                    if (!waitElapsed)
                    {
                        System.Diagnostics.Trace.WriteLine(
                            $@"MessageOperationHandler.GetNextMessage() 
                                    did not receive in time message from send endpoint with URL: {Url}",
                            "TransMock.MessageOperationHandler");

                        throw new TimeoutException("No message received for the wait time set.");
                    }
                }
                finally
                {
                }

                // Now we destructive read the message from the message queue
                messageReceived = this.receivedMessages
                                  .TryRemove(
                    ConnectionId,
                    out receivedMessage);

                if (!messageReceived)
                {
                    System.Diagnostics.Trace.WriteLine(
                        $"MessageOperationHandler.GetNextMessage() did not manage to fetch message from internal collection for send endpoint with URL: {Url} and connection Id: {connectionId}. Continuing to try!",
                        "TransMock.TestMessagingClient");
                }
            }

            return(receivedMessage);
        }
示例#3
0
        //public TestCasting InParallel()
        //{

        //}

        private void MockMessageServer_ReadCompleted(object sender, AsyncReadEventArgs e)
        {
            lock (this.syncRoot)
            {
                this.receivedMessagesQueue.Enqueue(e);

                System.Threading.Monitor.Pulse(this.syncRoot);
            }
        }
示例#4
0
        /// <summary>
        /// Handler method for the ReadCompleted event
        /// </summary>
        /// <param name="sender">The instance of the object firing the event</param>
        /// <param name="e">The event arguments</param>
        private void pipeServer_ReadCompleted(object sender, AsyncReadEventArgs e)
        {
            lock (this.syncRoot)
            {
                this.receivedMessagesQueue.Enqueue(e);

                // this.requestContent = this.encoding.GetString(this.inStream.ToArray());

                Monitor.Pulse(this.syncRoot);
            }
        }
示例#5
0
文件: Mold.cs 项目: Pauwelz/transmock
        private void MockMessageServer_ReadCompleted(object sender, AsyncReadEventArgs e)
        {
            lock (this.syncRoot)
            {
                this.receivedMessagesQueue.Enqueue(e);

                System.Diagnostics.Debug.WriteLine("Message received in the MockMessageServer_ReadCompleted handler");

                System.Threading.Monitor.Pulse(this.syncRoot);
            }
        }
示例#6
0
        private void pipeServer_ReadCompleted(object sender, AsyncReadEventArgs e)
        {
            try
            {
                System.Diagnostics.Debug.WriteLine(
                    "Writing the message contents to the message body",
                    "TransMock.Wcf.Adapter.MockAdapterInboundHandler");

                string msgContents = null;

                // Adding the message contents to a predefined XML structure
                // TODO: refactor to a more efficien implementation
                using (MemoryStream memStream = e.MessageStream as MemoryStream)
                {
                    msgContents = string.Format(
                        CultureInfo.InvariantCulture,
                        "<MessageContent>{0}</MessageContent>",
                        Convert.ToBase64String(memStream.ToArray()));
                }

                XmlReader xr = XmlReader.Create(new StringReader(msgContents));

                Message inMsg = Message.CreateMessage(MessageVersion.Default, string.Empty, xr);

                System.Diagnostics.Debug.WriteLine(
                    "Message constructed. Promoting any properties to it",
                    "TransMock.Wcf.Adapter.MockAdapterInboundHandler");

                // Add any configured properties in the message context
                this.propertyParser.PromoteProperties(inMsg);

                if (inMsg != null)
                {
                    System.Diagnostics.Debug.WriteLine(
                        "Enqueuing message to the internal queue",
                        "TransMock.Wcf.Adapter.MockAdapterInboundHandler");

                    lock (this.inboundQueueSyncLock)
                    {
                        // Adding the message and pipe connection to the inbound queue
                        this.inboundQueue.Enqueue(new MessageConnectionPair(inMsg, e.ConnectionId));
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(
                    "ReadCompleted event handler threw an exception: " + ex.Message,
                    "TransMock.Wcf.Adapter.MockAdapterInboundHandler");

                throw;
            }
        }
        /// <summary>
        /// Event handler for the ReadComplete event
        /// </summary>
        /// <param name="sender">the sender of the event</param>
        /// <param name="e">The event arcuments</param>
        private void MessageServer_ReadCompleted(object sender, AsyncReadEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(
                $@"MessageOperationConfig.MessageServer_ReadCompleted() 
                    invoked for connection id: {e.ConnectionId}, URL: {Url} Active connectionId: {ConnectionId}",
                "TransMock.TestMessagingClient");


            while (!this.receivedMessages.TryAdd(e.ConnectionId, e))
            {
                System.Diagnostics.Debug.WriteLine(
                    "Message did not get added to the collection. Attempting again!",
                    "TransMock.TestMessagingClient");
            }

            ConnectionId = e.ConnectionId;
            receiveMessageSemaphore.Release();
        }