public static IForecastStrategy GetForecastStrategy(
            ForecastTypeEnum forecastType,
            WeatherForecast weatherForecast)
        {
            switch (forecastType)
            {
            default:
            {
                return(new EasyForecastStrategy(weatherForecast));
            }

            case ForecastTypeEnum.hourly:
            {
                return(new HourlyForecastStrategy(weatherForecast));
            }

            case ForecastTypeEnum.threeDays:
            {
                return(new ThreeDayForecastStrategy(weatherForecast));
            }

            case ForecastTypeEnum.fourteenDays:
            {
                return(new FourteenDayForecastStrategy(weatherForecast));
            }
            }
        }
예제 #2
0
        private ForecastTypeEnum GetForecastTypeFromSettings()
        {
            ForecastTypeEnum type = ForecastTypeEnum.easy;

            switch (Properties.Settings.Default.userForecastPreference)
            {
            case 0:
            {
                type = ForecastTypeEnum.easy;
                break;
            }

            case 1:
            {
                type = ForecastTypeEnum.hourly;
                break;
            }

            case 2:
            {
                type = ForecastTypeEnum.threeDays;
                break;
            }

            case 3:
            {
                type = ForecastTypeEnum.fourteenDays;
                break;
            }
            }
            return(type);
        }
예제 #3
0
        public List <string> GetForecast(
            int zipcode,
            DateTime date,
            TemperatureTypeEnum temperatureType,
            ForecastTypeEnum forecastType)
        {
            try
            {
                CheckParametersValid(zipcode, date, temperatureType, forecastType);
            }
            catch (ArgumentException ae)
            {
                //ToDo Fehlermeldung an UI
            }

            // = "Orchestrierung", ruft Methoden auf ohne zu wissen, woher bspw. Parameter herkommen
            // Funktionales Programmieren
            _temperatureStrategy = TemperatureStrategyFactory.GetTemperatureStrategy(temperatureType);
            // Exercise: New Provider (e.g. Random) and change next Line to see if it still work
            IWeatherForecastProvider weatherForecastProvider = new OpenWeatherAPI(HttpClientFactory.CreateClient(), "a1fcc507923163ff1bae113a80d8f82a");
            WeatherForecast          weatherForecast         = new WeatherForecast(weatherForecastProvider);

            _forecastStrategy = ForecastStrategyFactory.GetForecastStrategy(forecastType, weatherForecast);
            List <string> result = new List <string>();

            try
            {
                result = _forecastStrategy.GetForecast(zipcode, _temperatureStrategy, date);
            }
            catch (ZipNotFoundException ex)
            {
                result.Add(ex.Message);
            }
            catch (Exception ex)
            {
                result.Add($"Exception: {ex.Message}");
            }
            return(result);
        }
예제 #4
0
        private void CheckParametersValid(int zipcode, DateTime date, TemperatureTypeEnum temperatureType, ForecastTypeEnum forecastType)
        {
            //ToDo Validation for Enums
            var validation = new UiValidation();

            if (validation.IsZipcode(zipcode) && validation.IsStringADate(date.ToString()))
            {
            }
            else
            {
                throw new ArgumentException("Invalid Arguments");
            }
        }