public static void SetLightColorFromBuildState(Build buildFromSource, Light light) { switch (buildFromSource.State) { case Build.BuildState.Success: { light.LightColor = Light.Color.Green; light.TurnOn(buildFromSource.IsBuilding); break; } case Build.BuildState.Unstable: { light.LightColor = Light.Color.Yellow; light.TurnOn(buildFromSource.IsBuilding); break; } case Build.BuildState.Failure: { light.LightColor = Light.Color.Red; light.TurnOn(buildFromSource.IsBuilding); break; } case Build.BuildState.Aborted: case Build.BuildState.Unknown: { light.TurnOff(); break; } default: { throw new UnknownBuildStateException(buildFromSource.State.ToString()); } } }
public void TurnOff(Light.Color color) { var userSource = new User { Build = new Build {IsBuilding = false, State = Build.BuildState.Unknown} }; _manager.BuildSource = userSource; }
public BuildServiceManager(ISource source, ILightFactory lightFactory) { _lightFactory = lightFactory; _light = _lightFactory.CreateLight(); _buildStatusSource = source; UnPause(); }
public void SetDeviceColor(Light.Color color) { _ledPin = LightColors[color]; }
private static Mock<ILightFactory> SetupMockLightFactory(Light mockLight) { var mockLightFactory = new Mock<ILightFactory>(MockBehavior.Strict); mockLightFactory.Setup(p => p.CreateLight()).Returns(mockLight); return mockLightFactory; }
public void TurnOn(Light.Color color) { var userSource = new User { Build = new Build {IsBuilding = false, State = MapState(color)} }; _manager.BuildSource = userSource; }
private static Build.BuildState MapState(Light.Color color) { var state = Build.BuildState.Unknown; switch (color) { case Light.Color.Green: state = Build.BuildState.Success; break; case Light.Color.Yellow: state = Build.BuildState.Unstable; break; case Light.Color.Red: state = Build.BuildState.Failure; break; } return state; }
public static void HandleException(Exception exception, BuildServiceManager manager, Light buildLight) { if (exception is UnknownBuildStateException) { buildLight.LightColor = Light.Color.Yellow; buildLight.TurnOn(); Thread.Sleep(250); buildLight.LightColor = Light.Color.Green; buildLight.TurnOn(); Thread.Sleep(3000); buildLight.LightColor = Light.Color.Yellow; manager.Reset(); buildLight.LightColor = Light.Color.Green; manager.Reset(); return; } if (exception is BuildNotFoundException) { buildLight.LightColor = Light.Color.Yellow; buildLight.TurnOn(); Thread.Sleep(250); buildLight.LightColor = Light.Color.Red; buildLight.TurnOn(true); Thread.Sleep(3000); buildLight.LightColor = Light.Color.Yellow; manager.Reset(); buildLight.LightColor = Light.Color.Red; manager.Reset(); return; } if (exception is DeviceNotConnectedException) { //have to ignore return; } //default buildLight.LightColor = Light.Color.Yellow; buildLight.TurnOn(true); Thread.Sleep(250); buildLight.LightColor = Light.Color.Green; buildLight.TurnOn(true); Thread.Sleep(250); buildLight.LightColor = Light.Color.Red; buildLight.TurnOn(true); Thread.Sleep(3000); buildLight.LightColor = Light.Color.Red; manager.Reset(); buildLight.LightColor = Light.Color.Yellow; manager.Reset(); buildLight.LightColor = Light.Color.Green; manager.Reset(); }