Exemple #1
0
        public void DetachDuplexInputChannel(string channelId)
        {
            using (EneterTrace.Entering())
            {
                using (ThreadLock.Lock(myDuplexInputChannels))
                {
                    TDuplexInputChannel anInputChannel = null;
                    myDuplexInputChannels.TryGetValue(channelId, out anInputChannel);
                    if (anInputChannel != null)
                    {
                        anInputChannel.DuplexInputChannel.StopListening();
                        anInputChannel.DuplexInputChannel.MessageReceived -= OnMessageReceived;
                    }

                    myDuplexInputChannels.Remove(channelId);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// The method is called when a reponse message is received from the duplex output channel.
        /// The received response is unwrapped and sent as a response to the matching duplex input channel.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void OnResponseMessageReceived(object sender, DuplexChannelMessageEventArgs e)
        {
            using (EneterTrace.Entering())
            {
                try
                {
                    ISerializer aSerializer  = mySerializer.ForResponseReceiver(e.ResponseReceiverId);
                    WrappedData aWrappedData = DataWrapper.Unwrap(e.Message, aSerializer);

                    // WrappedData.AddedData represents the channel id.
                    // Therefore if everything is ok then it must be string.
                    if (aWrappedData.AddedData is string)
                    {
                        // Get the output channel according to the channel id.
                        TDuplexInputChannel aDuplexInputChannel = null;

                        using (ThreadLock.Lock(myDuplexInputChannels))
                        {
                            myDuplexInputChannels.TryGetValue((string)aWrappedData.AddedData, out aDuplexInputChannel);
                        }

                        if (aDuplexInputChannel != null)
                        {
                            aDuplexInputChannel.DuplexInputChannel.SendResponseMessage(aDuplexInputChannel.ResponseReceiverId, aWrappedData.OriginalData);
                        }
                        else
                        {
                            EneterTrace.Warning(TracedObject + "could not send the response message to the duplex input channel '" + (string)aWrappedData.AddedData + "' because the channel is not attached to the unwrapper.");
                        }
                    }
                    else
                    {
                        EneterTrace.Error(TracedObject + "detected that the unwrapped message does not contain the channel id as the string type.");
                    }
                }
                catch (Exception err)
                {
                    EneterTrace.Error(TracedObject + "failed to process the response message.", err);
                }
            }
        }