public static WeatherObject TryToGetWeather(WeatherType type, int time, double temperature) { var helper = new WeatherTypeHelper(); helper.SetParams(time, temperature); WeatherObject result = null; return(helper.TryToGetWeather(type, ref result) ? result : null); }
private void TryToSetWeather() { _weatherTypeHelper.SetParams(Time, Temperature); var weather = SelectedWeather; if (_weatherTypeHelper.TryToGetWeather(SelectedWeatherType, ref weather)) { SelectedWeather = weather; } }
private async Task UpdateConditions(bool reset) { _conditionsTokenSource?.Cancel(); var round = _acObject.CurrentRound; if (round == null) { return; } if (reset) { _weatherTypeHelper.Reset(); } if (!_currentSet || !_acObject.RealConditions || _acObject.RealConditionsManualTime) { _currentRoundTime = round.Time; } if (!_currentSet || !_acObject.RealConditions) { _currentSet = true; _currentRoundTemperature = round.Temperature; _currentRoundWeather = round.Weather; } if (!_acObject.RealConditions) { OnPropertyChanged(nameof(CurrentRoundWeather)); OnPropertyChanged(nameof(CurrentRoundTemperature)); return; } WeatherType?weatherType = null; ConditionsLoading = true; using (var cancellation = new CancellationTokenSource()) { _conditionsTokenSource = cancellation; try { await RealConditionsHelper.UpdateConditions(round.Track, false, true, _acObject.RealConditionsManualTime ?default(Action <int>) : t => { _currentRoundTime = t.Clamp(CommonAcConsts.TimeMinimum, CommonAcConsts.TimeMaximum); }, w => { _currentRoundTemperature = w.Temperature.Clamp(CommonAcConsts.TemperatureMinimum, CommonAcConsts.TemperatureMaximum); weatherType = w.Type; }, cancellation.Token); if (cancellation.Token.IsCancellationRequested) { return; } } finally { OnPropertyChanged(nameof(CurrentRoundTemperature)); OnPropertyChanged(nameof(CurrentRoundTime)); if (ReferenceEquals(_conditionsTokenSource, cancellation)) { _conditionsTokenSource = null; } } } ConditionsLoading = false; if (weatherType != null) { _weatherTypeHelper.SetParams(CurrentRoundTime, CurrentRoundTemperature); var weather = CurrentRoundWeather; if (_weatherTypeHelper.TryToGetWeather(weatherType.Value, ref weather)) { CurrentRoundWeather = weather; } else { OnPropertyChanged(nameof(CurrentRoundWeather)); } } }