Beispiel #1
0
        static void Main(string[] args)
        {
            string name = "AA";

            var myHubClient  = new MyHubClient("test1");
            var myHubClient2 = new MyHubClient("test2");

            while (true)
            {
                string key = Console.ReadLine();


                if (key.ToUpper() == "H")
                {
                    if (myHubClient.State == ConnectionState.Connected)
                    {
                        myHubClient.Heartbeat();
                    }
                    else
                    {
                        Console.WriteLine("Can't send message, connectionState= " + myHubClient.State);
                    }
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            #region SLAB
            var ObservableEventListener = new ObservableEventListener();
            ObservableEventListener.EnableEvents(ControllerEvents.Log, EventLevel.LogAlways, Keywords.All);
            ObservableEventListener.EnableEvents(GlobalEvents.Log, EventLevel.LogAlways, Keywords.All);
            ObservableEventListener.EnableEvents(HubClientEvents.Log, EventLevel.LogAlways, Keywords.All);
            var formatter = new PrefixEventTextFormatter("-----------", null, "# ", @"yyyy-MM-dd hh\:mm\:ss\.fff");
            ObservableEventListener.LogToConsole(formatter);
            #endregion

            string name = "AA";

            var myHubClient = new MyHubClient();
            while (true)
            {
                string key = Console.ReadLine();
                if (key.ToUpper() == "A")
                {
                    if (myHubClient.State == ConnectionState.Connected)
                    {
                        myHubClient.SendAllClient(name, "hello all");
                    }
                    else
                    {
                        HubClientEvents.Log.Warning("Can't send message, connectionState= " + myHubClient.State);
                    }
                }
                if (key.ToUpper() == "B")
                {
                    if (myHubClient.State == ConnectionState.Connected)
                    {
                        myHubClient.SendToSingle(Console.ReadLine(), name, "hello world");
                    }
                    else
                    {
                        HubClientEvents.Log.Warning("Can't send message, connectionState= " + myHubClient.State);
                    }
                }
                if (key.ToUpper() == "H")
                {
                    if (myHubClient.State == ConnectionState.Connected)
                    {
                        myHubClient.Heartbeat();
                    }
                    else
                    {
                        HubClientEvents.Log.Warning("Can't send message, connectionState= " + myHubClient.State);
                    }
                }
                if (key.ToUpper() == "S")
                {
                    name = Console.ReadLine();
                    if (myHubClient.State == ConnectionState.Connected)
                    {
                        myHubClient.Subscribe(name);
                    }
                    else
                    {
                        HubClientEvents.Log.Warning("Can't send message, connectionState= " + myHubClient.State);
                    }
                }

                if (key.ToUpper() == "Q")
                {
                    if (myHubClient.State == ConnectionState.Connected)
                    {
                        myHubClient.Unsubscribe(name);
                    }
                    else
                    {
                        HubClientEvents.Log.Warning("Can't send message, connectionState= " + myHubClient.State);
                    }
                }

                if (key.ToUpper() == "C")
                {
                    myHubClient.CloseHub();
                    HubClientEvents.Log.Informational("Closed Hub");
                }
            }
        }