コード例 #1
0
        public Main()
        {
            try
            {
                InitializeComponent();
                ProcessFile();
                WriteFile();
                MessageBox.Show("Done!");
                return;
                _mMouseHookManager = new MouseHookListener(new GlobalHooker()) {Enabled = true};
                _mMouseHookManager.MouseUp += mMouseHookManager_MouseUp;

                ReadKeyFile(Properties.Settings.Default.KeyPath);

                IDuplexTypedMessagesFactory aSenderFactory = new DuplexTypedMessagesFactory();
                _mySender = aSenderFactory.CreateDuplexTypedMessageSender<AppQA, MyResponse>();

                IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
                IDuplexOutputChannel anOutputChannel =
                    aMessaging.CreateDuplexOutputChannel("tcp://" + Properties.Settings.Default.IpAddress + ":8060/");

                // Attach the input channel and start to listen to messages.
                _mySender.AttachDuplexOutputChannel(anOutputChannel);
            }
            catch (Exception exception)
            {
                WriteAnswer(Properties.Settings.Default.AnswerPath, exception.Message);
            }
        }
コード例 #2
0
        private void OpenConnectionBtn_Click(object sender, EventArgs e)
        {
            if (!mySender.IsDuplexOutputChannelAttached)
            {
                // The output channel is not attached yet.
                // So attach the output channel and be able to send
                // request messagas and receive response messages.
                IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory()
                {
                    // Set to receive messages in the main UI thread.
                    // Note: if this is not set then methods OnResponseReceived and
                    //       OnConnectionClosed would not be called from main UI thread
                    //       but from a listener thread.
                    OutputChannelThreading = new WinFormsDispatching(this)
                };
                IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("tcp://127.0.0.1:8033/");
                mySender.AttachDuplexOutputChannel(anOutputChannel);

                ConnectionStatusLabel.Text = "Client Connected";
            }
            else if (!mySender.AttachedDuplexOutputChannel.IsConnected)
            {
                // The output channel is attached but the client got disconnected.
                // So jut reopen the connection.
                mySender.AttachedDuplexOutputChannel.OpenConnection();

                ConnectionStatusLabel.Text = "Client Connected";
            }
        }
コード例 #3
0
        public void Openconnection()
        {
            // Create message sender sending request messages of type Person and receiving responses of type string.
            IDuplexTypedMessagesFactory aTypedMessagesFactory = new DuplexTypedMessagesFactory();

            myMessageSender = aTypedMessagesFactory.CreateDuplexTypedMessageSender <string, Person>();
            myMessageSender.ResponseReceived += OnResponseReceived;
            // Create messaging based on TCP.
            IMessagingSystemFactory aMessagingSystemFactory = new TcpMessagingSystemFactory();
            IDuplexOutputChannel    anOutputChannel         = aMessagingSystemFactory.CreateDuplexOutputChannel("tcp://127.0.0.1:8094/");

            // Attach output channel and be able to send messages and receive response messages.
            myMessageSender.AttachDuplexOutputChannel(anOutputChannel);
        }
コード例 #4
0
        public MainWindow()
        {
            InitializeComponent();
            IDuplexTypedMessagesFactory aTypedMessagesFactory = new DuplexTypedMessagesFactory();

            mySender = aTypedMessagesFactory.CreateDuplexTypedMessageSender <MyResponse, MyRequest>();
            mySender.ResponseReceived += OnResponseReceived;

            // Create messaging based on TCP.
            IMessagingSystemFactory aMessagingSystemFactory = new TcpMessagingSystemFactory();
            IDuplexOutputChannel    anOutputChannel         = aMessagingSystemFactory.CreateDuplexOutputChannel("tcp://192.168.2.9:8060/");

            // Attach output channel and be able to send messages and receive response messages.
            mySender.AttachDuplexOutputChannel(anOutputChannel);
            MyRequest test = new MyRequest {
                side = "L", strength = 10
            };

            mySender.SendRequestMessage(test);
            MyRequest reset = new MyRequest {
                side = "L", strength = 0
            };

            mySender.SendRequestMessage(reset);
            try
            {
                USBInterface usb = new USBInterface("vid_044f", "pid_b108");
                usb.Connect();
                usb.enableUsbBufferEvent(new System.EventHandler(myEventCacher));
                usb.startRead();

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
コード例 #5
0
 public void AttachOutputChannel()
 {
     try
     {
         switch (MessagesFactoryType)
         {
         case YZXMessagesFactoryType.Duplex:
             if (DSender == null)
             {
                 ConfigSender();
             }
             else
             {
                 if (DSender.IsDuplexOutputChannelAttached)
                 {
                 }
                 else
                 {
                     try
                     {
                         anOutputChannel = UnderlyingMessaging.CreateDuplexOutputChannel(Partner);
                         DSender.AttachDuplexOutputChannel(anOutputChannel);
                     }
                     catch (Exception ex)
                     {
                         Console.WriteLine(ex);
                     }
                 }
             }
             break;
         }
     }
     catch (Exception EX)
     {
         Console.WriteLine(EX);
     }
 }
コード例 #6
0
        public void SendReceive_1Message_PerClientSerializer()
        {
            string aClient1Id = null;

            IDuplexTypedMessagesFactory aSender1Factory  = new DuplexTypedMessagesFactory(new XmlStringSerializer());
            IDuplexTypedMessagesFactory aSender2Factory  = new DuplexTypedMessagesFactory(new BinarySerializer());
            IDuplexTypedMessagesFactory aReceiverFactory = new DuplexTypedMessagesFactory()
            {
                SerializerProvider = x => (x == aClient1Id) ? (ISerializer) new XmlStringSerializer() : (ISerializer) new BinarySerializer()
            };

            IDuplexTypedMessageSender <int, int>   aSender1  = aSender1Factory.CreateDuplexTypedMessageSender <int, int>();
            IDuplexTypedMessageSender <int, int>   aSender2  = aSender2Factory.CreateDuplexTypedMessageSender <int, int>();
            IDuplexTypedMessageReceiver <int, int> aReceiver = aReceiverFactory.CreateDuplexTypedMessageReceiver <int, int>();

            aReceiver.ResponseReceiverConnected += (x, y) => aClient1Id = aClient1Id ?? y.ResponseReceiverId;


            int aReceivedMessage = 0;

            aReceiver.MessageReceived += (x, y) =>
            {
                aReceivedMessage = y.RequestMessage;

                // Send the response
                aReceiver.SendResponseMessage(y.ResponseReceiverId, 1000);
            };

            AutoResetEvent aSender1MessageReceivedEvent = new AutoResetEvent(false);
            int            aSender1ReceivedResponse     = 0;

            aSender1.ResponseReceived += (x, y) =>
            {
                aSender1ReceivedResponse = y.ResponseMessage;

                // Signal that the response message was received -> the loop is closed.
                aSender1MessageReceivedEvent.Set();
            };


            AutoResetEvent aSender2MessageReceivedEvent = new AutoResetEvent(false);
            int            aSender2ReceivedResponse     = 0;

            aSender2.ResponseReceived += (x, y) =>
            {
                aSender2ReceivedResponse = y.ResponseMessage;

                // Signal that the response message was received -> the loop is closed.
                aSender2MessageReceivedEvent.Set();
            };

            try
            {
                aReceiver.AttachDuplexInputChannel(DuplexInputChannel);
                aSender1.AttachDuplexOutputChannel(MessagingSystemFactory.CreateDuplexOutputChannel(DuplexInputChannel.ChannelId));
                aSender2.AttachDuplexOutputChannel(MessagingSystemFactory.CreateDuplexOutputChannel(DuplexInputChannel.ChannelId));

                aSender1.SendRequestMessage(2000);
                aSender2.SendRequestMessage(2000);

                // Wait for the signal that the message is received.
                aSender1MessageReceivedEvent.WaitIfNotDebugging(2000);
                aSender2MessageReceivedEvent.WaitIfNotDebugging(2000);
                //Assert.IsTrue(aMessageReceivedEvent.WaitOne(2000));
            }
            finally
            {
                aSender1.DetachDuplexOutputChannel();
                aSender2.DetachDuplexOutputChannel();
                aReceiver.DetachDuplexInputChannel();

                // Give some time to complete tracing.
                Thread.Sleep(300);
            }

            // Check received values
            Assert.AreEqual(2000, aReceivedMessage);
            Assert.AreEqual(1000, aSender1ReceivedResponse);
            Assert.AreEqual(1000, aSender2ReceivedResponse);
        }
コード例 #7
0
        // The method is called when the button to send message is clicked.
        private void SendMessage_Click(object sender, RoutedEventArgs e)
        {
            // Create message sender sending request messages of type Person and receiving responses of type string.
            IDuplexTypedMessagesFactory aTypedMessagesFactory = new DuplexTypedMessagesFactory();
            myMessageSender = aTypedMessagesFactory.CreateDuplexTypedMessageSender<byte[], byte[]>();
            myMessageSender.ResponseReceived += ResponseReceived;

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

            // Attach output channel and be able to send messages and receive response messages.
            myMessageSender.AttachDuplexOutputChannel(aDuplexOutputChannel);

            myMessageSender.SendRequestMessage(GetBytes(textBox1.Text));
        }
コード例 #8
0
        public void CalculatePi()
        {
            //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug;
            //EneterTrace.TraceLog = new StreamWriter("d:/tracefile.txt");

            IMessagingSystemFactory aThreadMessaging = new ThreadMessagingSystemFactory();

            List <CalculatorService> aServices = new List <CalculatorService>();

            ILoadBalancer aDistributor = null;
            IDuplexTypedMessageSender <double, Interval> aSender = null;

            // Create 50 calculating services.
            try
            {
                for (int i = 0; i < 50; ++i)
                {
                    aServices.Add(new CalculatorService("a" + i.ToString(), aThreadMessaging));
                }

                // Create Distributor
                ILoadBalancerFactory aDistributorFactory = new RoundRobinBalancerFactory(aThreadMessaging);
                aDistributor = aDistributorFactory.CreateLoadBalancer();

                // Attach available services to the distributor.
                for (int i = 0; i < aServices.Count; ++i)
                {
                    aDistributor.AddDuplexOutputChannel("a" + i.ToString());
                }

                // Attach input channel to the distributor.
                IDuplexInputChannel anInputChannel = aThreadMessaging.CreateDuplexInputChannel("DistributorAddress");
                aDistributor.AttachDuplexInputChannel(anInputChannel);


                // Create client that needs to calculate PI.
                IDuplexTypedMessagesFactory aTypedMessagesFactory = new DuplexTypedMessagesFactory();
                aSender = aTypedMessagesFactory.CreateDuplexTypedMessageSender <double, Interval>();

                AutoResetEvent aCalculationCompletedEvent = new AutoResetEvent(false);
                int            aCount = 0;
                double         aPi    = 0.0;
                aSender.ResponseReceived += (x, y) =>
                {
                    ++aCount;
                    EneterTrace.Debug("Completed interval: " + aCount.ToString());

                    aPi += y.ResponseMessage;

                    if (aCount == 400)
                    {
                        aCalculationCompletedEvent.Set();
                    }
                };

                IDuplexOutputChannel anOutputChannel = aThreadMessaging.CreateDuplexOutputChannel("DistributorAddress");
                aSender.AttachDuplexOutputChannel(anOutputChannel);

                // Sender sends several parallel requests to calculate specified intervals.
                // 2 / 0.005 = 400 intervals.
                for (double i = -1.0; i <= 1.0; i += 0.005)
                {
                    Interval anInterval = new Interval(i, i + 0.005);
                    aSender.SendRequestMessage(anInterval);
                }

                // Wait until all requests are calculated.
                EneterTrace.Debug("Test waits until completion.");
                aCalculationCompletedEvent.WaitOne();

                EneterTrace.Info("Calculated PI = " + aPi.ToString());
            }
            catch (Exception err)
            {
                EneterTrace.Error("Test failed", err);
                throw;
            }
            finally
            {
                aSender.DetachDuplexOutputChannel();
                aDistributor.DetachDuplexInputChannel();
                aServices.ForEach(x => x.Dispose());
            }
        }