コード例 #1
0
        private static void OnExempleHub(ConsoleTable table)
        {
            Task.Factory.StartNew(() =>
            {
                SignalRCreateConnection conn = new SignalRCreateConnection(host, "ExampleHub");
                conn.On <string>("listenDateTime", d =>
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Gray;
                    table = WriteTableRow(table, "listenDateTime", d);
                });


                do
                {
                    if (!conn.ServerOnline)
                    {
                        Console.Clear();
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Server SignalR OffLine.");
                        OnExempleHub(table);
                    }

                    Thread.Sleep(2000);
                } while (true);
            });

            Console.ReadKey();
        }
コード例 #2
0
        private static void OnNotificationHub(ConsoleTable table)
        {
            Task.Factory.StartNew(() =>
            {
                SignalRCreateConnection notificationHub = new SignalRCreateConnection(host, "NotificationHub");
                notificationHub.On <string>("getNewGuid", d =>
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Gray;
                    table = WriteTableRow(table, "getNewGuid", d);
                });

                notificationHub.On <int>("getInt", i =>
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Gray;
                    table = WriteTableRow(table, "getInt", i);
                });

                notificationHub.On("onMethodWithoutReturnValue", () =>
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Gray;
                    table = WriteTableRow(table, "onMethodWithoutReturnValue", "Método sem valor de retorno -> " + DateTime.Now);
                });

                do
                {
                    if (!notificationHub.ServerOnline)
                    {
                        Console.Clear();
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Server SignalR OffLine.");
                        OnNotificationHub(table);
                    }

                    Thread.Sleep(2000);
                } while (true);
            });

            Console.ReadKey();
        }