Exemple #1
0
 /// <summary>
 /// Copy-constructor
 /// </summary>
 /// <param name="toCopy"></param>
 public WeatherCondition(WeatherCondition toCopy)
 {
     this.Temperature           = toCopy.Temperature;
     this.TemperatureMin        = toCopy.TemperatureMin;
     this.TemperatureMax        = toCopy.TemperatureMax;
     this.FullDescription       = toCopy.FullDescription;
     this.ShortDescription      = toCopy.ShortDescription;
     this.WindSpeed             = toCopy.WindSpeed;
     this.WindDirection         = toCopy.WindDirection;
     this.AthmosphereHumidity   = toCopy.AthmosphereHumidity;
     this.AthmospherePressure   = toCopy.AthmospherePressure;
     this.AthmosphereVisibility = toCopy.AthmosphereVisibility;
     this.AthmosphereRising     = toCopy.AthmosphereRising;
     this.Precipitation         = toCopy.Precipitation;
     this.Condition             = toCopy.Condition;
     this.GenereationDate       = toCopy.GenereationDate;
     this.GenerationDateString  = toCopy.GenerationDateString;
     this.IsForecast            = toCopy.IsForecast;
     this.ForecastGuid          = toCopy.ForecastGuid;
     this.ForecastDate          = toCopy.ForecastDate;
     this.ForecastDateString    = toCopy.ForecastDateString;
     this.Sunrise          = toCopy.Sunrise;
     this.Sunset           = toCopy.Sunset;
     this.GroundLevel      = toCopy.GroundLevel;
     this.DistanceUnits    = toCopy.DistanceUnits;
     this.PressureUnits    = toCopy.PressureUnits;
     this.SpeedUnits       = toCopy.SpeedUnits;
     this.TemperatureUnits = toCopy.TemperatureUnits;
     this.Language         = toCopy.Language;
     this.City             = toCopy.City;
     this.Region           = toCopy.Region;
     this.Country          = toCopy.Country;
     this.SeaLevel         = toCopy.SeaLevel;
     this.IsPrecalculatedEffectiveTemperature = toCopy.IsPrecalculatedEffectiveTemperature;
     this.EffectiveTemperature = toCopy.EffectiveTemperature;
 }
Exemple #2
0
        /// <summary>
        /// Converts to database conditions.
        /// </summary>
        /// <param name="condition">External condition.</param>
        /// <returns></returns>
        public static WeatherCondition ConvertTo(External.WeatherCondition condition)
        {
            var result = new WeatherCondition();

            result.Temperature    = condition.Temperature;
            result.TemperatureMax = condition.TemperatureMax;
            result.TemperatureMin = condition.TemperatureMin;

            // If no, get middle.
            if (result.Temperature == null && result.TemperatureMax != null && result.TemperatureMin != null)
            {
                result.Temperature = result.TemperatureMin + ((result.TemperatureMax - result.TemperatureMin) / 2);
            }

            result.IsPrecalculatedEffectiveTemperature = condition.IsPrecalculatedEffectiveTemperature;
            result.EffectiveTemperature  = condition.EffectiveTemperature;
            result.ShortDescription      = condition.ShortDescription;
            result.WindSpeed             = condition.WindSpeed;
            result.WindDirection         = condition.WindDirection;
            result.AthmosphereHumidity   = condition.AthmosphereHumidity;
            result.AthmospherePressure   = condition.AthmospherePressure;
            result.AthmosphereVisibility = condition.AthmosphereVisibility;
            result.AthmosphereRising     = condition.AthmosphereRising;
            result.IsForecast            = condition.IsForecast;
            result.ForecastDate          = condition.ForecastDate;
            result.ForecastDateString    = condition.ForecastDateString;
            result.ForecastGuid          = condition.ForecastGuid;
            result.GenereationDate       = condition.GenereationDate ?? DateTime.UtcNow;
            result.GenerationDateString  = condition.GenerationDateString;
            result.FullDescription       = condition.FullDescription;
            result.Precipitation         = condition.Precipitation;
            result.Condition             = condition.Condition;
            result.SeaLevel    = condition.SeaLevel;
            result.GroundLevel = condition.GroundLevel;
            result.Sunrise     = condition.Sunrise;
            result.Sunset      = condition.Sunset;

            var dataStore = ModelContainer.Instance.GetInstance <IDataStore>();

            var lang = dataStore.GetLanguageByCode((condition.Language != null && condition.Language.Length > 2) ? condition.Language.Substring(0, 2) : condition.Language);

            if (lang != null)
            {
                result.LanguageId = lang.Id;

                var unit = dataStore.GetUnitByName(UnitSystems.Metric.ToString(), lang.Id);
                if (unit != null)
                {
                    result.UnitsId = unit.Id;
                }
            }

            var location = DataHelper.TryToGetLocation(condition.Woeid, condition.Country, condition.City, condition.Region, dataStore);

            if (location != null)
            {
                result.LocationId = location.Id;
            }
            else
            {
                Debug.Assert(false);
            }

            return(result);
        }