Пример #1
0
        /// <summary>
        /// Sets the airco status to On of Off
        /// </summary>
        /// <param name="status">The status.</param>
        /// <exception cref="AircoTemperatureTooHighException">Not allowed / needed to turn Airco off: temparature is too high.</exception>
        /// <exception cref="AircoTemperatureTooLowException">Not allowed / needed to turn Airco on: temperature is too low.</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">null</exception>
        public virtual void SetAircoStatus(AircoStatus status)
        {
            // Based on current temparature, the Airco can be turned on / off
            CurrentWeather weather = CurrentWeather.GetCurrentWeather();
            decimal        temperatureInCelsius = weather.GetTemperatureInCelcius();

            switch (status)
            {
            case AircoStatus.Off:
            {
                if (temperatureInCelsius > 10)
                {
                    // Not allowed / needed to turn Airco off
                    throw new AircoTemperatureTooHighException("Not allowed / needed to turn Airco off: temparature is too high.");
                }
                break;
            }

            case AircoStatus.On:
            {
                if (temperatureInCelsius < 5)
                {
                    // Not allowed / needed to turn Airco on
                    throw new AircoTemperatureTooLowException("Not allowed / needed to turn Airco on: temperature is too low.");
                }
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(status), status, null);
            }
            }
            this.Airco.SetAircoStatus(status);
        }
Пример #2
0
        private void SetAircoStatus(AircoStatus aircoStatus)
        {
            try
            {
                _building.SetAircoStatus(aircoStatus);

                using (var t = Session.BeginTransaction())
                {
                    try
                    {
                        Session.Update(_building.Airco);
                        t.Commit();
                    }
                    catch
                    {
                        t.Rollback();
                    }
                }

                //OF
                //Session.Update(_building.Airco);
                //Session.Flush();

                ResponseHandler.WriteLine($"Airco is turned {aircoStatus}");
            }
            catch (AircoTemperatureTooHighException)
            {
                ResponseHandler.WriteLine("The outside temparature is too high: don't turn off the airco!");
            }
            catch (AircoTemperatureTooLowException)
            {
                ResponseHandler.WriteLine("The outside temparature is too low: no need to turn on the arico.");
            }
            finally
            {
                RequestHandler.ReadLine();
                Show();
            }
        }
Пример #3
0
 public virtual void SetAircoStatus(AircoStatus status)
 {
     AircoStatus = status;
 }