Example #1
0
		/// <summary>
		///   Initializes a new instance.
		/// </summary>
		/// <param name="sensor">The sensor that is used to sense the pressure level within the tank.</param>
		/// <param name="pump">The pump that is used to fill the tank.</param>
		/// <param name="timer">The timer that is used to determine whether the pump should be disabled.</param>
		public Controller(Sensor sensor, Pump pump, Timer timer)
		{
			_pump = pump;
			_sensor = sensor;
			_timer = timer;

			Transition(
				from: States.Filling,
				to: States.StoppedByTimer,
				guard: _timer.HasElapsed,
				action: _pump.Disable);

			Transition(
				from: States.Filling,
				to: States.StoppedBySensor,
				guard: _sensor.IsFull,
				action: () =>
				{
					_pump.Disable();
					_timer.Stop();
				});

			Transition(
				from: States.StoppedByTimer | States.StoppedBySensor | States.Inactive,
				to: States.Filling,
				guard: _sensor.IsEmpty,
				action: () =>
				{
					_timer.Start();
					_pump.Enable();
				});

			InitialState(States.Inactive);
		}
		/// <summary>
		///   Initializes a new instance.
		/// </summary>
		/// <param name="positionDetector">The sensor that detects overheight vehicles on any lane.</param>
		/// <param name="leftDetector">The sensor that detects high vehicles on the left lane.</param>
		/// <param name="rightDetector">The sensor that detects high vehicles on the right lane.</param>
		/// <param name="timeout">The amount of time after which the main-control is deactivated.</param>
		public OriginalMainControl(IVehicleDetector positionDetector, IVehicleDetector leftDetector, IVehicleDetector rightDetector,
								   int timeout)
		{
			_timer = new Timer(timeout);
			_positionDetector = positionDetector;
			_leftDetector = leftDetector;
			_rightDetector = rightDetector;
		}
		/// <summary>
		///   Initializes a new instance.
		/// </summary>
		/// <param name="detector">The sensor that should be used to detect vehicles in the end-control area.</param>
		/// <param name="timeout">The amount of time after which the end-control is deactivated.</param>
		public OriginalEndControl(IVehicleDetector detector, int timeout)
		{
			_timer = new Timer(timeout);
			_detector = detector;
		}