public void SwitchNextColor(object?o) { if (CurrentTrafficLight.Color == Colors.Red) { CurrentTrafficLight.Color = Colors.Yellow; // CurrentTrafficLight.ColorSwitchTimer.Change(1000, Timeout.Infinite); CurrentTrafficLight.IsSwitchingDown = true; } else if (CurrentTrafficLight.Color == Colors.Yellow && CurrentTrafficLight.IsSwitchingDown) { // CurrentTrafficLight.ColorSwitchTimer.Change(2000, Timeout.Infinite); CurrentTrafficLight.Color = Colors.Green; CurrentTrafficLight.IsSwitchingDown = false; } else if (CurrentTrafficLight.Color == Colors.Yellow && !CurrentTrafficLight.IsSwitchingDown) { // CurrentTrafficLight.ColorSwitchTimer.Change(2000, Timeout.Infinite); CurrentTrafficLight.Color = Colors.Red; } else if (CurrentTrafficLight.Color == Colors.Green) { // CurrentTrafficLight.ColorSwitchTimer.Change(1000, Timeout.Infinite); CurrentTrafficLight.Color = Colors.Yellow; } try {//TODO fix sending params TrafficLightEntity hubLight = new TrafficLightEntity() { Id = CurrentTrafficLight.Id, Color = CurrentTrafficLight.Color, Date = CurrentTrafficLight.Date }; _hubContext.Clients.All.SendAsync("ReceiveColor", hubLight); } catch (Exception ex) { Console.WriteLine(ex.Message); } Changes?.Invoke(); }
public void InvokeChanges() { Changes?.Invoke(); }