static void Main(string[] args) { //HttpClient client = new HttpClient(); Console.WriteLine("Det kjører her: "); var connection = new HubConnectionBuilder() .WithUrl("https://localhost:44306/signalRmessage") .Build(); Console.WriteLine("Det kjører her etter Build "); connection.StartAsync().Wait(); Console.WriteLine("Det kjører her etter startconnection "); connection.InvokeCoreAsync("Send", args: new[] { "Hei hei fra Console app" }); Console.WriteLine("Det kjører her etter InvokeAsync "); connection.On("Start", (MyService service) => { Console.WriteLine("Beskjed fra web klient: TmsId: " + service.TmsId + " ServiceId:" + service.ServiceId + " Displayname: " + service.displayName + " Action: " + service.action); if (service.action == "restart") { Console.WriteLine("Action er : " + service.action); restartService(service); } else if (service.action == "stop") { Console.WriteLine("Action er : " + service.action); stopService(service); } else { Console.WriteLine("Action er : " + service.action); startService(service); } }); Console.ReadKey(); }
public async void HandleJob(IJobClient jobClient, IJob job) { // business logic var jobKey = job.Key; Console.WriteLine("Handling job: " + job); Thread.Sleep(3000); var connection = new HubConnectionBuilder() .WithUrl("https://localhost:5001/signalrhub", (opts) => { opts.HttpMessageHandlerFactory = (message) => { if (message is HttpClientHandler clientHandler) { // bypass SSL certificate clientHandler.ServerCertificateCustomValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { return(true); } } ; return(message); }; }) .Build(); await connection.StartAsync(); WorkflowData variables = JsonConvert.DeserializeObject <WorkflowData>(job.Variables); await connection.InvokeCoreAsync("WorkflowStepDone", typeof(void), new object[] { job.WorkflowInstanceKey.ToString(), variables.connectionid, job.Type.ToString() }); jobClient.NewCompleteJobCommand(jobKey) .Variables("") .Send() .GetAwaiter() .GetResult(); }
private void OnMessageReceived(object sender, OnMessageReceivedArgs e) { var fclient = new FaunaClient(endpoint: ENDPOINT, secret: Settings.Fauna_Secret); if (coders.Contains(e.ChatMessage.DisplayName)) { //string name = await GetVectorPronunciation(fclient, e.ChatMessage.DisplayName); _ = ("!so " + e.ChatMessage.DisplayName); new CommandAnnounce(client).Execute($"A live coder is in the chat, check out {e.ChatMessage.DisplayName}, stream at twitch dot tv/{e.ChatMessage.DisplayName}", e); coders.Remove(e.ChatMessage.DisplayName); } foreach (Match link in Regex.Matches(e.ChatMessage.Message, @"(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})")) { var protocollink = new UriBuilder(link.Value.ToString()).Uri.ToString(); if (!e.ChatMessage.DisplayName.StartsWith("StreamElements")) { Log.Information($"link : {DateTime.UtcNow.ToString()}, {protocollink}", "info"); Data.WriteLink(fclient, protocollink).Wait(); DiscordBot.PostMessage(e.ChatMessage.DisplayName, 729021058568421386, protocollink).Wait(); } } var connection = new HubConnectionBuilder() .WithUrl("http://localhost:53425/chathub") .Build(); connection.StartAsync().Wait(); connection.InvokeCoreAsync("SendMessage", args: new[] { e.ChatMessage.Message, e.ChatMessage.Username }); //Data.GetVectorPronunciation(fclient, e.ChatMessage.Username).Wait(); // Data.GetVectorPronunciationAll(fclient).Wait(); }
public async Task Clients_receive_messages_regardless_of_which_node_they_are_connected_to() { var hub1Connection = new HubConnectionBuilder() .WithUrl(TestResources.Configuration.GetConnectionString("hub1")) .Build(); var hub2Connection = new HubConnectionBuilder() .WithUrl(TestResources.Configuration.GetConnectionString("hub2")) .Build(); await hub1Connection.StartAsync(); await hub2Connection.StartAsync(); var hub1ConnectionReceivedDirectMessage = false; var hub1ConnectionReceivedGlobalMessage = false; var hub2ConnectionReceivedDirectMessage = false; var hub2ConnectionReceivedGlobalMessage = false; const string groupOnNode1 = "one"; const string groupOnNode2 = "two"; hub1Connection.On("greet", (string message) => { if (message == $"hello {groupOnNode1}") { hub1ConnectionReceivedDirectMessage = true; } if (message == "hello everyone") { hub1ConnectionReceivedGlobalMessage = true; } }); hub2Connection.On("greet", (string message) => { if (message == $"hello {groupOnNode2}") { hub2ConnectionReceivedDirectMessage = true; } if (message == "hello everyone") { hub2ConnectionReceivedGlobalMessage = true; } }); await hub1Connection.InvokeCoreAsync("joinGroup", new object[] { groupOnNode1 }); await hub2Connection.InvokeCoreAsync("joinGroup", new object[] { groupOnNode2 }); var url = TestResources.Configuration.GetConnectionString("hub1BaseUrl"); var hub1Client = new HubClient(new HttpClient { BaseAddress = new Uri(url) }); await hub1Client.GreetGroup(groupOnNode1); await hub1Client.GreetGroup(groupOnNode2); await hub1Client.GreetEveryone(); await Task.Delay(TimeSpan.FromSeconds(10)); Assert.True(hub1ConnectionReceivedDirectMessage); Assert.True(hub1ConnectionReceivedGlobalMessage); Assert.True(hub2ConnectionReceivedDirectMessage); Assert.True(hub2ConnectionReceivedGlobalMessage); await hub1Connection.DisposeAsync(); await hub2Connection.DisposeAsync(); }
public static async Task Main(string[] args) { var clientEventStore = ClientEventStore.Empty; var state = new CustomerState(clientEventStore); var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add <App>("#app"); builder.Services.AddScoped( sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); builder.Services.AddSingleton(sp => state); var viewState = new ViewState(); builder.Services.AddSingleton(sp => viewState); Console.WriteLine($"{builder.HostEnvironment.BaseAddress}synchronizationhub"); var synchronizationHub = new HubConnectionBuilder() .WithUrl($"{builder.HostEnvironment.BaseAddress}synchronizationhub") .WithAutomaticReconnect(new ForeverRetryPolicy()) .Build(); synchronizationHub.On <string>("ReceiveChangesFromServer", json => { var jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; var changes = JsonConvert.DeserializeObject <ImmutableList <DomainEvent> >(json, jsonSettings); clientEventStore.ApplyChangesFromServer(changes); Console.WriteLine("Received data from server " + json); }); var serverChangesAvailable = new Subject <long>(); synchronizationHub.On <int>("ChangesAvailable", count => { serverChangesAvailable.OnNext(count); }); // Push client changes to server state.Store.DomainEvents .Sample(TimeSpan.FromMilliseconds(500)) .Select(de => 1L) .Merge(Observable.Interval(TimeSpan.FromSeconds(5))) .Subscribe(async counter => { try { if (synchronizationHub.State != HubConnectionState.Connected || !clientEventStore.UnsyncedEvents.Any()) { return; } var jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; var json = JsonConvert.SerializeObject(clientEventStore.UnsyncedEvents, jsonSettings); Console.WriteLine("Writing data to server" + json); await synchronizationHub.InvokeCoreAsync("PushChangesToServer", new[] { json }); } catch (Exception e) { Console.WriteLine("PushChangesToServer: Unhandled exception " + e.Message); } }); // Get changes from server serverChangesAvailable.Merge(Observable.Interval(TimeSpan.FromSeconds(5))) .Subscribe(async counter => { try { if (synchronizationHub.State != HubConnectionState.Connected) { return; } await synchronizationHub.InvokeCoreAsync("GetChangesFromServer", new object[] { clientEventStore.Events.LastOrDefault()?.EventId }); } catch (Exception e) { Console.WriteLine("GetChangesFromServer: Unhandled exception " + e.Message); } }); synchronizationHub.Closed += async exception => { await Task.Run(() => { viewState.Connected = false; Console.WriteLine($"SignalRConnection Closed. {exception?.Message}"); }); }; synchronizationHub.Reconnecting += async exception => { await Task.Run(() => { viewState.Connected = false; Console.WriteLine($"SignalRConnection Reconnecting {exception?.Message}"); }); }; synchronizationHub.Reconnected += async s => { await Task.Run(() => { viewState.Connected = true; Console.WriteLine($"SignalRConnection Reconnected {s}"); serverChangesAvailable.OnNext(0); }); }; TryToStartSynchronizationHub(synchronizationHub, viewState, serverChangesAvailable); await builder.Build().RunAsync(); }
static async Task Main(string[] args) { var userList = new List <LoginModel> { new LoginModel("Quentin", "Admin145*"), new LoginModel("Martin", "Admin145*"), new LoginModel("David", "admin") }; var connection = new HubConnectionBuilder() .WithUrl("http://*****:*****@everyone"); Console.Write("Choose your credential\n{0} Quentin, {1} Martin, {2} David : "); var pickedCredential = Convert.ToInt32(Console.ReadLine()); var loginData = userList[pickedCredential]; var response = await connection.InvokeCoreAsync <LoginModel>("Login", new object[] { loginData.UserName, loginData.Password }); var nickname = loginData.UserName; try { string message; do { message = Console.ReadLine(); if (message?.ToLower() == "block") { Console.Write("Enter your chat mate's username: "******"BlockUser", new object[] { blockedUserName }); } else { await connection.InvokeCoreAsync("SendMessage", new object[] { nickname, message }); } } while (message?.ToLower() != "exit"); } catch (Exception exception) { Console.WriteLine(exception); throw; } Console.WriteLine("Press any key to exit."); Console.ReadLine(); await connection.DisposeAsync().ContinueWith(c => { GetClientStatus(c, "disconnected"); }); }