Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pauloanalista/utilssignalr
Solução contendo um serviço SignalR Self-Hosted, com Topshelf, SimpleInjector e Log4Net, e classe para encapsular a conexão com SignalR
https://github.com/pauloanalista/utilssignalr
Last synced: about 1 month ago
JSON representation
Solução contendo um serviço SignalR Self-Hosted, com Topshelf, SimpleInjector e Log4Net, e classe para encapsular a conexão com SignalR
- Host: GitHub
- URL: https://github.com/pauloanalista/utilssignalr
- Owner: pauloanalista
- Created: 2017-12-21T15:32:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-06-23T00:14:40.000Z (over 2 years ago)
- Last Synced: 2023-02-28T22:36:32.509Z (almost 2 years ago)
- Language: C#
- Homepage:
- Size: 9.32 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# UtilsSignalR
### SignalRConnection
- Encapsula a criação de conexões e chamada aos métodos de um serviço SignalR.
### Exemplo
- SignalRCreateConnection
```csharp
class Pessoa
{
public string Nome { get; set; }
public string Endereco { get; set; }
public string Telefone { get; set; }
public int CartaoCredito { get; set; }
}class Program
{
private static string host = "http://localhost:8082/signalr";static void Main()
{
Task.Factory.StartNew(() => OnExempleHub());
Task.Factory.StartNew(() => InvokeExempleHub());
Task.Factory.StartNew(() => InvokeNotificationHub());
Console.ReadKey();
}private static void OnExempleHub()
{Task.Factory.StartNew(() =>
{
SignalRCreateConnection notificationHub = new SignalRCreateConnection(host, "ExampleHub");
notificationHub.On("listenDateTime", d =>
{
Console.WriteLine(d);
});notificationHub.On("getNewGuid", g =>
{
Console.WriteLine(g);
});do
{
//executar alguma ação caso o serviço esteja indisponível
if (!notificationHub.ServerOnline)
{
Console.WriteLine("Server SignalR OffLine.");
}Thread.Sleep(2000);
} while (true);});
Console.ReadKey();
}
private static void InvokeNotificationHub()
{
SignalRCreateConnection notificationHub = new SignalRCreateConnection(host, "NotificationHub");while (true)
{
notificationHub.Invoke("SendNewGuid");
Task pessoa = notificationHub.Invoke("GetPessoa");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 InvokeExempleHub()
{
SignalRCreateConnection exemploHub = new SignalRCreateConnection(host, "ExampleHub");while (true)
{
Task date = exemploHub.Invoke("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);
}
}
}
```
### Referências
- SignalR (https://www.asp.net/signalr)
- Topshelf (http://topshelf-project.com/index.html)
- Log4net (https://logging.apache.org/log4net/)
- SimpleInjector (https://simpleinjector.readthedocs.io/en/latest/webapiintegration.html)
- Serviço SignalR SelfHosted com Topshelf (https://github.com/RobertoCamara/SignalRSelfHosted)# VEJA TAMBÉM
## Grupo de Estudo no Telegram
- [Participe gratuitamente do grupo de estudo](https://t.me/blogilovecode)## Cursos baratos!
- [Meus cursos](https://olha.la/udemy)## Novidades, cupons de descontos e cursos gratuitos
https://olha.la/ilovecode-receber-cupons-novidades