public async void StartListening() { _connection = new HubConnectionBuilder() .WithUrl("https://sandgatethapi.azurewebsites.net/api/") .Build(); _connection.Closed += async(error) => { await Task.Delay(new Random().Next(0, 5) * 1000); await _connection.StartAsync(); }; _connection.On <ClientMessage>("ClientMessage", (cm) => { if (cm.Direction == "SPA2Station" && cm.StationId == _hubDeviceID) { Debug.WriteLine(cm.Command); ClientCommandEventArgs args = new ClientCommandEventArgs(); GameCommand gc = new GameCommand(cm.Command, cm.Parameters); args.gameCommand = gc; OnCommandReceived(args); } }); try { await _connection.StartAsync(); // messagesList.Items.Add("Connection started"); // connectButton.IsEnabled = false; // sendButton.IsEnabled = true; } catch (Exception ex) { string s = ex.Message; // messagesList.Items.Add(ex.Message); } }
private void _signalClient_CommandReceived(object sender, ClientCommandEventArgs e) { Console.WriteLine("_signalClient_CommandReceived"); _gm.ProcessGameCommand(e.gameCommand); }
protected virtual void OnCommandReceived(ClientCommandEventArgs e) { CommandReceived?.Invoke(this, e); }