示例#1
0
        public void testAddAndFetchWeatherStation()
        {
            WeatherThreshold testThreshold = new WeatherThreshold(10, 120);

            DatabaseOperations.AddWeatherThreshold(testThreshold);
            int time = DatabaseOperations.FetchWeatherThreshold().SnowDumpTime;

            Assert.AreEqual(120, time);
        }
        /// <summary>
        /// Adds a selected weather Threshold to the database
        /// </summary>
        /// <param name="weatherThreshold"></param>
        public static void AddWeatherThreshold(WeatherThreshold weatherThreshold)
        {
            using (RTDbContext Context = InitializeDatabaseContext())
            {
                Context.WeatherThreshold.Add(weatherThreshold);
                SaveContext(Context);

                logger.Info(Utilities.GetTimeStamp() + ": Added WeatherThreshold to database");
            }
        }
        /// <summary>
        /// Routine to retrieve the time interval for dumping snow off of the dish (in minutes) from the database
        /// </summary>
        public static WeatherThreshold FetchWeatherThreshold()
        {
            using (RTDbContext Context = InitializeDatabaseContext())
            {
                var threshold = Context.WeatherThreshold.FirstOrDefault();


                if (threshold == null)
                {
                    logger.Info(Utilities.GetTimeStamp() + ": The WeatherThreshold data could not be found. Creating a new one with default values...");
                    // default values of 0 windSpeed and 2 hours for snow dump time. If the table is empty, add it
                    threshold = new WeatherThreshold(0, 120);
                    AddWeatherThreshold(threshold);
                }
                return(threshold);
            }
        }