Beispiel #1
0
        private bool Command_Initialize()
        {
            // Create duplex message sender.
            // It can send messages and also receive messages.
            IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory();

            Command_MessageSender = aStringMessagesFactory.CreateDuplexStringMessageSender();
            Command_MessageSender.ResponseReceived += Command_ResponseReceived;

            // Create TCP based messaging.
            IMessagingSystemFactory aMessaging           = new TcpMessagingSystemFactory();
            IDuplexOutputChannel    aDuplexOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + serverIP.Text + ":4502/");

            // Attach the duplex output channel to the message sender
            // and be able to send messages and receive messages.
            try
            {
                Command_MessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel);
            }
            catch (Exception e)
            {
                Log(e.Message);
            }

            if (Command_MessageSender.IsDuplexOutputChannelAttached)
            {
                Log("Initialized connection.");
                return(true);
            }
            else
            {
                Log("Unable to initialize connection");
                return(false);
            }
        }
Beispiel #2
0
        public void Setup()
        {
            IDuplexStringMessagesFactory aDuplexStringMessagesFactory = new DuplexStringMessagesFactory();

            myStringMessageSender11  = aDuplexStringMessagesFactory.CreateDuplexStringMessageSender();
            myStringMessageSender12  = aDuplexStringMessagesFactory.CreateDuplexStringMessageSender();
            myStringMessageSender13  = aDuplexStringMessagesFactory.CreateDuplexStringMessageSender();
            myStringMessageSender22  = aDuplexStringMessagesFactory.CreateDuplexStringMessageSender();
            myStringMessageReceiver1 = aDuplexStringMessagesFactory.CreateDuplexStringMessageReceiver();
            myStringMessageReceiver2 = aDuplexStringMessagesFactory.CreateDuplexStringMessageReceiver();
            myStringMessageReceiver3 = aDuplexStringMessagesFactory.CreateDuplexStringMessageReceiver();


            myMessagingSystemFactory = new SynchronousMessagingSystemFactory();
            IDuplexDispatcherFactory aDuplexDispatcherFactory = new DuplexDispatcherFactory(myMessagingSystemFactory);

            myDuplexDispatcher = aDuplexDispatcherFactory.CreateDuplexDispatcher();
        }
Beispiel #3
0
        protected void Setup(IMessagingSystemFactory messagingSystemFactory, string channelId)
        {
            MessagingSystemFactory = messagingSystemFactory;

            DuplexOutputChannel = MessagingSystemFactory.CreateDuplexOutputChannel(channelId);
            DuplexInputChannel  = MessagingSystemFactory.CreateDuplexInputChannel(channelId);

            IDuplexStringMessagesFactory aMessageFactory = new DuplexStringMessagesFactory();

            MessageRequester = aMessageFactory.CreateDuplexStringMessageSender();
            MessageResponser = aMessageFactory.CreateDuplexStringMessageReceiver();
        }
Beispiel #4
0
        public MainPage()
        {
            InitializeComponent();

            // Create duplex message sender.
            // It can send messages and also receive messages.
            IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory();
            myMessageSender = aStringMessagesFactory.CreateDuplexStringMessageSender();
            myMessageSender.ResponseReceived += MessageReceived;

            // Create TCP based messaging.
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
            IDuplexOutputChannel aDuplexOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:4502/");

            // Attach the duplex output channel to the message sender
            // and be able to send messages and receive messages.
            myMessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel);
        }
        public void WrapUnwrapMessage()
        {
            // Wrapped/unwrapped channels
            string aChannel1Id = "Channel1Id";
            string aChannel2Id = "Channel2Id";

            IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory();

            IDuplexStringMessageReceiver aStringMessageReceiver1 = aStringMessagesFactory.CreateDuplexStringMessageReceiver();
            IDuplexStringMessageReceiver aStringMessageReceiver2 = aStringMessagesFactory.CreateDuplexStringMessageReceiver();

            IDuplexStringMessageSender aStringMessageSender1 = aStringMessagesFactory.CreateDuplexStringMessageSender();
            IDuplexStringMessageSender aStringMessageSender2 = aStringMessagesFactory.CreateDuplexStringMessageSender();

            // Attach input channels to string receivers.
            aStringMessageReceiver1.AttachDuplexInputChannel(myMessagingForUnwrapper.CreateDuplexInputChannel(aChannel1Id));
            aStringMessageReceiver2.AttachDuplexInputChannel(myMessagingForUnwrapper.CreateDuplexInputChannel(aChannel2Id));

            // Connect string senders with the channel wrapper.
            myDuplexChannelWrapper.AttachDuplexInputChannel(myMessagingForWrapper.CreateDuplexInputChannel(aChannel1Id));
            myDuplexChannelWrapper.AttachDuplexInputChannel(myMessagingForWrapper.CreateDuplexInputChannel(aChannel2Id));
            aStringMessageSender1.AttachDuplexOutputChannel(myMessagingForWrapper.CreateDuplexOutputChannel(aChannel1Id));
            aStringMessageSender2.AttachDuplexOutputChannel(myMessagingForWrapper.CreateDuplexOutputChannel(aChannel2Id));

            // Connect wrapper and unwrapper to global channels.
            myDuplexChannelUnwrapper.AttachDuplexInputChannel(myDuplexGlobalInputChannel);
            myDuplexChannelWrapper.AttachDuplexOutputChannel(myDuplexGlobalOutputChannel);


            StringRequestReceivedEventArgs aReceivedMessage1 = null;

            aStringMessageReceiver1.RequestReceived += (x, y) =>
            {
                aReceivedMessage1 = y;
                aStringMessageReceiver1.SendResponseMessage(y.ResponseReceiverId, "Response1");
            };

            StringRequestReceivedEventArgs aReceivedMessage2 = null;

            aStringMessageReceiver2.RequestReceived += (x, y) =>
            {
                aReceivedMessage2 = y;
                aStringMessageReceiver2.SendResponseMessage(y.ResponseReceiverId, "Response2");
            };

            StringResponseReceivedEventArgs aReceivedResponse1 = null;

            aStringMessageSender1.ResponseReceived += (x, y) =>
            {
                aReceivedResponse1 = y;
            };

            StringResponseReceivedEventArgs aReceivedResponse2 = null;

            aStringMessageSender2.ResponseReceived += (x, y) =>
            {
                aReceivedResponse2 = y;
            };

            aStringMessageSender1.SendMessage("Message1");

            Assert.AreEqual("Message1", aReceivedMessage1.RequestMessage, "Message receiver 1 received incorrect message.");
            Assert.AreEqual("Response1", aReceivedResponse1.ResponseMessage, "Response receiver 1 received incorrect message.");
            Assert.IsNull(aReceivedMessage2, "Message receiver 2 should not receive a message.");
            Assert.IsNull(aReceivedResponse2, "Response receiver 2 should not receive a message.");

            string anAssociatedResponseReceiverId = myDuplexChannelUnwrapper.GetAssociatedResponseReceiverId(aReceivedMessage1.ResponseReceiverId);

            Assert.AreEqual(myDuplexChannelWrapper.AttachedDuplexOutputChannel.ResponseReceiverId, anAssociatedResponseReceiverId);


            aReceivedMessage1  = null;
            aReceivedResponse1 = null;

            aStringMessageSender2.SendMessage("Message2");

            Assert.AreEqual("Message2", aReceivedMessage2.RequestMessage, "Message receiver 2 received incorrect message.");
            Assert.AreEqual("Response2", aReceivedResponse2.ResponseMessage, "Response receiver 2 received incorrect message.");
            Assert.IsNull(aReceivedMessage1, "Message receiver 1 should not receive a message.");
            Assert.IsNull(aReceivedResponse1, "Response receiver 1 should not receive a message.");
        }
        //[Test]
        public void AssociatedResponseReceiverId()
        {
            // Wrapped/unwrapped channels
            string aChannel1Id = "Channel1Id";
            string aChannel2Id = "Channel2Id";

            IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory();

            IDuplexStringMessageReceiver aStringMessageReceiver1 = aStringMessagesFactory.CreateDuplexStringMessageReceiver();
            IDuplexStringMessageReceiver aStringMessageReceiver2 = aStringMessagesFactory.CreateDuplexStringMessageReceiver();

            IDuplexStringMessageSender aStringMessageSender1 = aStringMessagesFactory.CreateDuplexStringMessageSender();
            IDuplexStringMessageSender aStringMessageSender2 = aStringMessagesFactory.CreateDuplexStringMessageSender();

            // Attach input channels to string receivers.
            aStringMessageReceiver1.AttachDuplexInputChannel(myMessagingForUnwrapper.CreateDuplexInputChannel(aChannel1Id));
            aStringMessageReceiver2.AttachDuplexInputChannel(myMessagingForUnwrapper.CreateDuplexInputChannel(aChannel2Id));

            // Connect string senders with the channel wrapper.
            myDuplexChannelWrapper.AttachDuplexInputChannel(myMessagingForWrapper.CreateDuplexInputChannel(aChannel1Id));
            myDuplexChannelWrapper.AttachDuplexInputChannel(myMessagingForWrapper.CreateDuplexInputChannel(aChannel2Id));
            aStringMessageSender1.AttachDuplexOutputChannel(myMessagingForWrapper.CreateDuplexOutputChannel(aChannel1Id));
            aStringMessageSender2.AttachDuplexOutputChannel(myMessagingForWrapper.CreateDuplexOutputChannel(aChannel2Id));

            try
            {
                // Connect wrapper and unwrapper to global channels.
                myDuplexChannelUnwrapper.AttachDuplexInputChannel(myDuplexGlobalInputChannel);
                myDuplexChannelWrapper.AttachDuplexOutputChannel(myDuplexGlobalOutputChannel);


                StringRequestReceivedEventArgs aReceivedMessage1 = null;
                aStringMessageReceiver1.RequestReceived += (x, y) =>
                {
                    aReceivedMessage1 = y;
                };
                bool aResponseReceiverChannel1Disconnected = false;
                aStringMessageReceiver1.ResponseReceiverDisconnected += (x, y) =>
                {
                    aResponseReceiverChannel1Disconnected = true;
                };

                StringRequestReceivedEventArgs aReceivedMessage2 = null;
                aStringMessageReceiver2.RequestReceived += (x, y) =>
                {
                    aReceivedMessage2 = y;
                };
                bool aResponseReceiverChannel2Disconnected = false;
                aStringMessageReceiver2.ResponseReceiverDisconnected += (x, y) =>
                {
                    aResponseReceiverChannel2Disconnected = true;
                };


                aStringMessageSender1.SendMessage("Message1");
                aStringMessageSender2.SendMessage("Message2");

                string anAssociatedId1 = myDuplexChannelUnwrapper.GetAssociatedResponseReceiverId(aReceivedMessage1.ResponseReceiverId);
                string anAssociatedId2 = myDuplexChannelUnwrapper.GetAssociatedResponseReceiverId(aReceivedMessage2.ResponseReceiverId);

                Assert.AreEqual(anAssociatedId1, anAssociatedId2);

                myDuplexChannelUnwrapper.AttachedDuplexInputChannel.DisconnectResponseReceiver(anAssociatedId1);
                Assert.IsTrue(aResponseReceiverChannel1Disconnected);
                Assert.IsTrue(aResponseReceiverChannel2Disconnected);
            }
            finally
            {
                myDuplexChannelUnwrapper.DetachDuplexInputChannel();
                myDuplexChannelWrapper.DetachDuplexOutputChannel();
            }
        }
Beispiel #7
0
        private bool Command_Initialize()
        {
            // Create duplex message sender.
            // It can send messages and also receive messages.
            IDuplexStringMessagesFactory aStringMessagesFactory = new DuplexStringMessagesFactory();
            Command_MessageSender = aStringMessagesFactory.CreateDuplexStringMessageSender();
            Command_MessageSender.ResponseReceived += Command_ResponseReceived;

            // Create TCP based messaging.
            IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
            IDuplexOutputChannel aDuplexOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://" + serverIP.Text + ":4502/");

            // Attach the duplex output channel to the message sender
            // and be able to send messages and receive messages.
            try
            {
                Command_MessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel);
            }
            catch (Exception e)
            {
                Log(e.Message);
            }

            if (Command_MessageSender.IsDuplexOutputChannelAttached)
            {
                Log("Initialized connection.");
                return true;
            }
            else
            {
                Log("Unable to initialize connection");
                return false;
            }
        }