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); } }
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(); }
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(); }
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); } }