コード例 #1
0
        public void TestDeadSubscriber()
        {
            StringBuilder sb = new StringBuilder();

            var hub = new MsgBroker();

            var subscriberA = new TestSubscriber(sb);
            var subscriberB = new TestSubscriber(sb);

            hub.Subscribe <string>(subscriberA, s => sb.Append($"A({s})"));
            hub.Subscribe <string>(subscriberB, s => sb.Append($"B({s})"));

            hub.PublishObject("x");
            hub.PublishObject("y");

            Assert.That(sb.ToString(), Is.EqualTo("A(x)B(x)A(y)B(y)"));

            subscriberA = null;

            GC.Collect();

            sb.Clear();

            hub.PublishObject("x");
            hub.PublishObject("y");

            Assert.That(sb.ToString(), Is.EqualTo("B(x)B(y)"));

            subscriberB.Reset(); // make sure subscriberB stays alive
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: gumberss/LearnLanguages
        static void Main(string[] args)
        {
            var msgBroker = new MsgBroker
            {
                HostName = "localhost",
                Password = "******",
                Username = "******",
                Port     = 5672
            };

            using (var activator = new BuiltinHandlerActivator())
            {
                activator.Register((bus, context) => new ConsumerHandler(bus));

                Configure.With(activator)
                .Transport(x => x.UseRabbitMq($"amqp://{msgBroker.Username}:{msgBroker.Password}@{msgBroker.HostName}:{msgBroker.Port}/", "consumer"))
                .Start();

                activator.Bus.Subscribe <Batman>().Wait();

                Console.ReadKey();
            }

            Console.WriteLine("Quit");
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: gumberss/LearnLanguages
        static void Main(string[] args)
        {
            var msgBroker = new MsgBroker
            {
                HostName = "localhost",
                Password = "******",
                Username = "******",
                Port     = 5672
            };

            using (var activator = new BuiltinHandlerActivator())
            {
                var bus = Configure.With(activator)
                          .Transport(x => x.UseRabbitMqAsOneWayClient($"amqp://{msgBroker.Username}:{msgBroker.Password}@{msgBroker.HostName}:{msgBroker.Port}/"))
                          .Start();

                while (true)
                {
                    var key = Console.ReadKey();

                    bus.Publish(new Batman {
                        Message = "Batman"
                    });

                    if (key.KeyChar == 'q')
                    {
                        break;
                    }
                }
            }

            Console.ReadKey();
            Console.WriteLine("Quit");
        }
コード例 #4
0
        public void TypedUnnamed()
        {
            var subscriber = new TestSubscriber();

            MsgBroker createHub()
            {
                var h = new MsgBroker();

                h.Subscribe <string>(subscriber, s => subscriber.Append($"A({s})"));
                h.Subscribe <int>(subscriber, i => subscriber.Append($"B({i})"));

                return(h);
            }

            var hub = createHub();

            Check(hub, subscriber, h => h.PublishObject("x"), 1, "A(x)");
            Check(hub, subscriber, h => h.PublishObject("y"), 1, "A(y)");
            Check(hub, subscriber, h => h.PublishObject(123), 1, "B(123)");
            Check(hub, subscriber, h => h.Publish("X"), 0);
            Check(hub, subscriber, h => h.Publish("Y"), 0);
            Check(hub, subscriber, h => h.PublishObject("Z", "z"), 1, "A(z)");
            Check(hub, subscriber, h => h.PublishObject("Z", 123), 1, "B(123)");
            Check(hub, subscriber, h => h.PublishObject(new DateTime()), 0);
            Check(hub, subscriber, h => h.PublishObject("x", new DateTime()), 0);

            hub = createHub();

            hub.Unsubscribe <string>(subscriber);

            Check(hub, subscriber, h => h.PublishObject("x"), 0);
            Check(hub, subscriber, h => h.PublishObject("y"), 0);
            Check(hub, subscriber, h => h.PublishObject(123), 1, "B(123)");
            Check(hub, subscriber, h => h.Publish("X"), 0);
            Check(hub, subscriber, h => h.Publish("Y"), 0);
            Check(hub, subscriber, h => h.PublishObject("Z", "z"), 0);
            Check(hub, subscriber, h => h.PublishObject("Z", 123), 1, "B(123)");
            Check(hub, subscriber, h => h.PublishObject(new DateTime()), 0);
            Check(hub, subscriber, h => h.PublishObject("x", new DateTime()), 0);

            hub = createHub();

            hub.Unsubscribe(subscriber);

            Check(hub, subscriber, h => h.PublishObject("x"), 0);
            Check(hub, subscriber, h => h.PublishObject("y"), 0);
            Check(hub, subscriber, h => h.PublishObject(123), 0);
            Check(hub, subscriber, h => h.Publish("X"), 0);
            Check(hub, subscriber, h => h.Publish("Y"), 0);
            Check(hub, subscriber, h => h.PublishObject("Z", "z"), 0);
            Check(hub, subscriber, h => h.PublishObject("Z", 123), 0);
            Check(hub, subscriber, h => h.PublishObject(new DateTime()), 0);
            Check(hub, subscriber, h => h.PublishObject("x", new DateTime()), 0);
        }
コード例 #5
0
        void Check(MsgBroker hub, TestSubscriber subscriber, Action <MsgBroker> action, int expectedCalls, string expectedResult = null)
        {
            subscriber.Reset();

            action(hub);

            Assert.That(subscriber.Calls, Is.EqualTo(expectedCalls));

            if (expectedResult != null)
            {
                Assert.That(subscriber.Result, Is.EqualTo(expectedResult));
            }
        }
コード例 #6
0
        public void TypedRegex()
        {
            var subscriber = new TestSubscriber();

            MsgBroker createHub()
            {
                var h = new MsgBroker();

                h.Subscribe <string>(subscriber, "A", s => subscriber.Append($"A({s})"));
                h.Subscribe <int>(subscriber, "B", i => subscriber.Append($"B({i})"));
                h.Subscribe <string>(subscriber, "C", s => subscriber.Append($"B({s})"));
                h.Subscribe <int>(subscriber, new Regex("A|B"), i => subscriber.Append($"AB({i})"));
                h.Subscribe <string>(subscriber, new Regex("A|B"), s => subscriber.Append($"AB({s})"));
                h.Subscribe <int>(subscriber, new Regex("B|C"), i => subscriber.Append($"BC({i})"));
                h.Subscribe <string>(subscriber, new Regex("B|C"), s => subscriber.Append($"BC({s})"));

                return(h);
            }

            var hub = createHub();

            Check(hub, subscriber, h => h.PublishObject("x"), 0);
            Check(hub, subscriber, h => h.PublishObject("y"), 0);
            Check(hub, subscriber, h => h.PublishObject("A", "x"), 2, "A(x)AB(x)");
            Check(hub, subscriber, h => h.PublishObject("B", "x"), 2, "AB(x)BC(x)");
            Check(hub, subscriber, h => h.PublishObject(123), 0);
            Check(hub, subscriber, h => h.PublishObject("A", 123), 1, "AB(123)");
            Check(hub, subscriber, h => h.PublishObject("B", 123), 3, "B(123)AB(123)BC(123)");
            Check(hub, subscriber, h => h.Publish("A"), 0);
            Check(hub, subscriber, h => h.Publish("B"), 0);
            Check(hub, subscriber, h => h.PublishObject("A", new DateTime()), 0);
            Check(hub, subscriber, h => h.PublishObject("B", new DateTime()), 0);

            hub = createHub();

            hub.Unsubscribe <string>(subscriber, new Regex("A|B"));

            Check(hub, subscriber, h => h.PublishObject("x"), 0);
            Check(hub, subscriber, h => h.PublishObject("y"), 0);
            Check(hub, subscriber, h => h.PublishObject("A", "x"), 1, "A(x)");
            Check(hub, subscriber, h => h.PublishObject("B", "x"), 1, "BC(x)");
            Check(hub, subscriber, h => h.PublishObject(123), 0);
            Check(hub, subscriber, h => h.PublishObject("A", 123), 1, "AB(123)");
            Check(hub, subscriber, h => h.PublishObject("B", 123), 3, "B(123)AB(123)BC(123)");
            Check(hub, subscriber, h => h.Publish("A"), 0);
            Check(hub, subscriber, h => h.Publish("B"), 0);
            Check(hub, subscriber, h => h.PublishObject("A", new DateTime()), 0);
            Check(hub, subscriber, h => h.PublishObject("B", new DateTime()), 0);
        }
コード例 #7
0
        public void MultipleTypes()
        {
            var subscriber = new TestSubscriber();

            var hub = new MsgBroker();

            hub.Subscribe(subscriber, "A", (int i) => subscriber.Append($"Ai({i})"));
            hub.Subscribe(subscriber, "A", (string s) => subscriber.Append($"As({s})"));
            hub.Subscribe(subscriber, "A", (object o) => subscriber.Append($"Ao({o})"));
            hub.Subscribe(subscriber, "A", () => subscriber.Append($"A()"));

            Check(hub, subscriber, h => h.PublishObject("A", 123), 3, "Ai(123)Ao(123)A()");
            Check(hub, subscriber, h => h.PublishObject("A", "x"), 3, "As(x)Ao(x)A()");
            Check(hub, subscriber, h => h.PublishObject("A", 123d), 2, "Ao(123)A()");
            Check(hub, subscriber, h => h.Publish("A"), 1, "A()");
        }
コード例 #8
0
        public void NamedNoParam()
        {
            var subscriber = new TestSubscriber();

            MsgBroker createHub()
            {
                var h = new MsgBroker();

                h.Subscribe(subscriber, "x", () => subscriber.Append("A"));
                h.Subscribe(subscriber, "y", () => subscriber.Append("B"));

                return(h);
            }

            var hub = createHub();

            Check(hub, subscriber, h => h.Publish("x"), 1, "A");
            Check(hub, subscriber, h => h.Publish("y"), 1, "B");
            Check(hub, subscriber, h => h.Publish("z"), 0);
            Check(hub, subscriber, h => h.PublishObject(new DateTime()), 0);
            Check(hub, subscriber, h => h.PublishObject("x", new DateTime()), 1, "A");

            hub = createHub();

            hub.Unsubscribe(subscriber, "x");

            Check(hub, subscriber, h => h.Publish("x"), 0);
            Check(hub, subscriber, h => h.Publish("y"), 1, "B");
            Check(hub, subscriber, h => h.Publish("z"), 0);
            Check(hub, subscriber, h => h.PublishObject(new DateTime()), 0);
            Check(hub, subscriber, h => h.PublishObject("x", new DateTime()), 0);

            hub = createHub();

            hub.Unsubscribe(subscriber);

            Check(hub, subscriber, h => h.Publish("x"), 0);
            Check(hub, subscriber, h => h.Publish("y"), 0);
            Check(hub, subscriber, h => h.Publish("z"), 0);
            Check(hub, subscriber, h => h.PublishObject(new DateTime()), 0);
            Check(hub, subscriber, h => h.PublishObject("x", new DateTime()), 0);
        }
コード例 #9
0
        public void RegexNoParam()
        {
            var subscriber = new TestSubscriber();

            var hub = new MsgBroker();

            hub.Subscribe(subscriber, "x", () => subscriber.Append("A"));
            hub.Subscribe(subscriber, "y", () => subscriber.Append("B"));
            hub.Subscribe(subscriber, new Regex("x|y"), () => subscriber.Append("C"));

            Check(hub, subscriber, h => h.Publish("x"), 2, "AC");
            Check(hub, subscriber, h => h.Publish("y"), 2, "BC");
            Check(hub, subscriber, h => h.Publish("z"), 0);
            Check(hub, subscriber, h => h.PublishObject(new DateTime()), 0);
            Check(hub, subscriber, h => h.PublishObject("x", new DateTime()), 2, "AC");

            hub.Unsubscribe(subscriber, new Regex("x|y"));

            Check(hub, subscriber, h => h.Publish("x"), 1, "A");
            Check(hub, subscriber, h => h.Publish("y"), 1, "B");
            Check(hub, subscriber, h => h.Publish("z"), 0);
            Check(hub, subscriber, h => h.PublishObject(new DateTime()), 0);
            Check(hub, subscriber, h => h.PublishObject("x", new DateTime()), 1, "A");
        }
コード例 #10
0
        void msgBroker_MessageReceived(object sender, MsgBroker.MsgBrokerEventArgs e)
        {
            switch(e.Message.MsgOPCode)
            {
                case MESSAGE_MAP.UPLOAD_PLAYLIST:

                    uploadplaylist((string)e.Message.MsgBody);

                    break;
                case MESSAGE_MAP.CREATE_FAVORITE_PLAYLIST:

                    Create_favorite_playlist((string)e.Message.MsgBody);

                    break;

                case MESSAGE_MAP.LOAD_ITEMS_IN_FAVORITE_PLAYLIST:

                    Load_favorite_playlist((string)e.Message.MsgBody);

                    break;
                case UI_CONTROL.PROGRESS_SHOW:
                      if (IsLeftPanelState)
                      {
                          HideLeftPanelStoryboard.Begin();
                          IsLeftPanelState = false;
                      }
                      main_page.Visibility = Visibility.Visible;
                      main_page.SetProgressRing(true, 0);
                    break;

                case UI_CONTROL.PROGRESS_HIDE:
                     main_page.SetProgressRing(false, 0);
                     main_page.Visibility = Visibility.Collapsed;

                     Search_ScrollViewer.ScrollToHome();
                        
                    if(UI_Flag.IsChart)
                    {
                        morebtn.Visibility = Visibility.Collapsed;
                    }
                    

                    break;

                case UI_CONTROL.SHOW_TOP_GRID:
                    if (!UI_Flag.IsShowingTopGrid)
                    {

                        webBrowser.Visibility = Visibility.Hidden;
                                      
                        top_content.Children.Clear();
                        top_content.Children.Add((UserControl)e.Message.MsgBody);
                        ShowTopGridStoryboard.Begin();

                        UI_Flag.IsShowingTopGrid = true;
                    }                   
                    
                    break;
                case UI_CONTROL.HIDE_TOP_GRID:
                    if (UI_Flag.IsShowingTopGrid)
                    {
                        HideTopGridStoryboard.Begin();
                        UI_Flag.IsShowingTopGrid = false;

                        if(UI_Flag.IsShowingVideo && Player_State.IsPlaying && !main_menu.IsFavoritePanel)
                        {
                            webBrowser.Visibility = Visibility.Visible;   
                        }
                    }
                    break;

                case UI_CONTROL.SetTopmost:
                    this.Topmost = true;
                    this.Activate();
                    break;

                case UI_CONTROL.DisableTopmost:
                    this.Topmost = false;
                    this.Activate();
                    break;
                case UI_CONTROL.RefreshMyplayList:
                    myPlayList.DataContext= null;
                    myPlayList.DataContext = myPlayListCollection;
                    break;
                case UI_CONTROL.SET_INIT_AFTER_TUTORIAL:
                    initLanguage();
                    Properties.Settings.Default.IsFirst = false;
                    Showvideodt.Start();
                    tutorialgrid.Children.Clear();
                    tutorialgrid.Visibility = Visibility.Collapsed;
                    
                    break;
                case UI_CONTROL.SET_LANGUAGE:
                    initLanguage();
                    break;
                case UI_CONTROL.ACTIVEMOREBTN:
                    morebtn.Visibility = Visibility.Visible;
                    break;
                case UI_CONTROL.SHOW_VIDEO:
                    if (UI_Flag.IsShowingVideo && Player_State.IsPlaying)
                    {
                        webBrowser.Visibility = Visibility.Visible;
                    }
                    
                    break;
                case UI_CONTROL.HIDE_VIDEO:
                    webBrowser.Visibility = Visibility.Hidden;
                    break;

                case UI_CONTROL.OPEN_DRAWERMENU:
                    DrawerMenu();
                    break;

                case UI_CONTROL.ACTIVETRAY:
                    notify.Visible = true;
                    setBalloonTip(LanguagePack.TrayActivateText());
                    break;
                case UI_CONTROL.DEACTIVETRAY:
                    notify.Visible = false;
                    break;
            }
        }