private void ReloadData()
        {
            // if date and time difference from the last time is more than 30 seconds
            if ((DateTime.Now - lastRefreshTime).TotalSeconds >= 30)
            {
                // redo all the data
                data.outsideTemp     = (float)GetRandomValue(58.44, (91 - 58.44) / 6);
                data.insideTemp      = (float)GetRandomValue(70, (80 - 70) / 6);
                data.dewPoint        = (float)GetRandomValue(48.43, (69 - 48.43) / 6);
                data.outsideHumidity = (int)GetRandomValue(50, (100 - 50) / 6);
                data.totalRain       = (float)GetRandomValue(42, (54 - 42) / 6);
                data.dailyRain       = (float)GetRandomValue(3.5, (4.5 - 3.5) / 6);
                data.monthlyRain     = (float)GetRandomValue(3.5, (4.5 - 3.5) / 6);
                data.rainRate        = (float)GetRandomValue(0.2, (1 - 0.2) / 6);
                data.heatIndex       = (int)GetRandomValue(74.6, (84.6 - 74.6) / 6);
                data.windSpeed       = (float)GetRandomValue(MiscellaneousHardwareConstants.SIMULATION_WEATHER_STATION_AVERAGE_WIND_SPEED_MPH, MiscellaneousHardwareConstants.SIMULATION_WEATHER_STATION_MAXIMUM_ALLOWABLE_WIND_SPEED_MPH_STD_DEV);
                data.baromPressure   = (float)GetRandomValue(30, (40 - 30) / 6);
                data.windChill       = (float)GetRandomValue(30, (40 - 30) / 6);

                data.windDirection = windDirections[windDirectionCounter];
                if (++windDirectionCounter >= 16)
                {
                    windDirectionCounter = 0;
                }

                DatabaseOperations.AddWeatherData(WeatherData.Generate(data));

                // change the successfull date and time
                lastRefreshTime = DateTime.Now;
            }
        }
Ejemplo n.º 2
0
        private void ReloadWeatherDataRoutine()
        {
            bool retrySave = false;

            while (KeepReloadWeatherDataThreadAlive)
            {
                if (LoadCurrentVantageData_V() != COM_ERROR)
                {
                    data.windSpeed            = GetWindSpeed_V();
                    data.windDirectionDegrees = GetWindDir_V();
                    data.windDirection        = ConvertWindDirDegreesToStr(data.windDirectionDegrees);
                    data.dailyRain            = GetDailyRain_V();
                    data.rainRate             = GetRainRate_V();
                    data.outsideTemp          = GetOutsideTemp_V();
                    data.insideTemp           = GetInsideTemp_V();
                    data.baromPressure        = GetBarometer_V();
                    data.dewPoint             = GetDewPt_V();
                    data.windChill            = GetWindChill_V();
                    data.outsideHumidity      = GetOutsideHumidity_V();
                    data.totalRain            = GetTotalRain_V();
                    data.monthlyRain          = GetMonthlyRain_V();
                    data.heatIndex            = GetHeatIndex_V();

                    // This is here for a workaround to issue #360. We will occasionally get a "Connection failed on open" Entity exception
                    // We have this used to simply retry the database update if the exception occurs. It always (while I was testing, at least) succeeds after the retry.
                    // We may need to remove this in production if we find a different solution for actually eliminating the bug insetad of this workaround

                    do
                    {
                        try
                        {
                            DatabaseOperations.AddWeatherData(WeatherData.Generate(data));
                            retrySave = false;
                            count     = 0;
                        }
                        catch (EntityException e)
                        {
                            count++;
                            retrySave = true;

                            // We want to retry 4 times, after which we will abandon the update.
                            if (count == 4)
                            {
                                retrySave = false;
                                count     = 0;
                                logger.Info(Utilities.GetTimeStamp() + " : Failed to update weather station data after 4 tries. Abandoning update...");
                            }
                        }
                    }while (retrySave);
                }


                Thread.Sleep(1000);
            }
        }