コード例 #1
0
        private int BroadcastToOthers(string eventName)
        {
            string[] others = _channel.Registrar.GetRegisteredInstances(_channel.ChannelName)
                              .Where(name => name != _channel.InstanceId)
                              .ToArray();

            int sent = _channel.SendTo(1000, others, eventName, null);

            Log.Write("Informed {0} domains of new content.", sent);

            // We follow one event with another to wait for completion of the first.
            int ack = _channel.SendTo(1000, others, Events.CompletionAck, null);

            Log.Verbose("{0} domains confirmed updated/active.", ack);
            return(sent);
        }
コード例 #2
0
ファイル: ___test.cs プロジェクト: git-thinh/AppCore
        public void TestChannelNamedInstance()
        {
            int ch1count = 0, ch2count = 0;

            using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel))
                using (IpcEventChannel ch2 = new IpcEventChannel(_registrar, _channel))
                    using (IpcEventChannel sender = new IpcEventChannel(_registrar, _channel))
                    {
                        ch1.StartListening("ch1");
                        ch2.StartListening("ch2");
                        sender.EnableAsyncSend();

                        ch1["Test"].OnEvent += delegate(object o, IpcSignalEventArgs e)
                        { ch1count++; };
                        ch2["Test"].OnEvent += delegate(object o, IpcSignalEventArgs e)
                        { ch2count++; };

                        for (int i = 0; i < 1000; i++)
                        {
                            Assert.AreEqual(1, sender.SendTo(10000, i % 2 == 0 ? "ch1" : "ch2", "Test"));
                        }

                        sender.StopAsyncSending(true, -1);
                        ch1.StopListening();
                        ch2.StopListening();
                    }
            Assert.AreEqual(500, ch1count);
            Assert.AreEqual(500, ch2count);
        }
コード例 #3
0
ファイル: ___test.cs プロジェクト: git-thinh/AppCore
        public void TestChannelSendOverloads()
        {
            using (IpcEventChannel sender = new IpcEventChannel(_registrar, _channel))
                using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel))
                    using (IpcEventChannel ch2 = new IpcEventChannel(_registrar, _channel))
                    {
                        ch1.StartListening("ch1");
                        ch2.StartListening("ch2");

                        int ch1Count = 0, ch2Count = 0;
                        ch1["Message"].OnEvent += delegate(object o, IpcSignalEventArgs e) { ch1Count++; };
                        ch2["Message"].OnEvent += delegate(object o, IpcSignalEventArgs e) { ch2Count++; };

                        sender.ExecutionTimeout = 1000;
                        Assert.AreEqual(1, sender.SendTo("CH1", "Message"));
                        Assert.AreEqual(1, sender.SendTo(new string[] { "CH2" }, "Message"));
                        Assert.AreEqual(2, sender.SendTo(1000, new string[] { "ch1", "ch2" }, "Message"));

                        ch1.StopListening();
                        Assert.AreEqual(2, ch1Count);
                        ch2.StopListening();
                        Assert.AreEqual(2, ch2Count);
                    }
        }