コード例 #1
0
        private static void InvokeNotificationHub()
        {
            SignalRCreateConnection notificationHub = new SignalRCreateConnection(host, "NotificationHub");

            int totalInt = 0;

            while (true)
            {
                Task <Pessoa> pessoa = notificationHub.Invoke <Pessoa>("GetPessoa");

                notificationHub.Invoke("SendNewGuid");
                notificationHub.Invoke("SendInt", totalInt++);

                if (!notificationHub.ServerOnline)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"Server OffLine -> {(string.IsNullOrEmpty(pessoa.Result.Nome) ? "No Connection - Result [GetPessoa]: Null" : "Connected - Result [GetPessoa]: " + pessoa.Result.Nome)}");
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine($"Server OnLine -> {(string.IsNullOrEmpty(pessoa.Result.Nome) ? "No Connection - Result [GetPessoa]: Null" : "Connected - Result [GetPessoa]: " + pessoa.Result.Nome)}");
                }

                Thread.Sleep(1000);
            }
        }
コード例 #2
0
        private static void InvokeExempleHub()
        {
            SignalRCreateConnection exemploHub = new SignalRCreateConnection(host, "ExampleHub");

            while (true)
            {
                Task <string> date = exemploHub.Invoke <string>("GetDateTimeFormated");

                if (!exemploHub.ServerOnline)
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"Server OffLine -> {(string.IsNullOrEmpty(date.Result) ? "No Connection - Result [GetDateTimeFormated]: Null" : "Connected - Result [GetDateTimeFormated]: " + date.Result)}");
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine($"Server OnLine -> {(string.IsNullOrEmpty(date.Result) ? "No Connection - Result [GetDateTimeFormated]: Null" : "Connected - Result [GetDateTimeFormated]: " + date.Result)}");
                }

                Thread.Sleep(1000);
            }
        }