public List <WeatherTestDTO> GetWeather(List <WebServiceDataSourceDTO> collWeatherDataSources, string location) { var collWeatherResults = new List <WeatherTestDTO>(); WeatherTestDTO dto = null; foreach (WebServiceDataSourceDTO datasource in collWeatherDataSources) { switch (datasource.ResponseDataType) { case ResponseDataType.JSON: dto = GetJSONWeatherFromUrl(datasource.Url + location); break; /*case ResponseDataType.XML: * //not yet implemented * break; * case ResponseDataType.OTHER: * //not yet implemented * break;*/ } if (dto != null) { dto = AddConvertedValues(dto); collWeatherResults.Add(dto); } } return(collWeatherResults); }
public WeatherTestDTO GetWeather(string location) { List <WeatherTestDTO> collWeatherTests = new List <WeatherTestDTO>(); var webServiceDatasources = new List <WebServiceDataSourceDTO>(); // ***this code could be improved by loading this data from an xml config file var dataSource = new WebServiceDataSourceDTO(); dataSource.Name = "BBC"; dataSource.ResponseDataType = ResponseDataType.JSON; dataSource.Url = "http://localhost:60827/weather/{0}"; var dataSourceProps = new WeatherTestProperties(); dataSourceProps.Location = "Location"; dataSourceProps.TemperatureCelsius = "TemperatureFahrenheit"; dataSourceProps.WindSpeedKph = "WindSpeedMph"; dataSource.ParamMapping = dataSourceProps; webServiceDatasources.Add(dataSource); dataSource = new WebServiceDataSourceDTO(); dataSource.Name = "Accu"; dataSource.ResponseDataType = ResponseDataType.JSON; dataSource.Url = "http://localhost:60819/weather/{0}"; dataSourceProps = new WeatherTestProperties(); dataSourceProps.Location = "Location"; dataSourceProps.TemperatureCelsius = "TemperatureCelsius"; dataSourceProps.WindSpeedKph = "WindSpeedKph"; dataSource.ParamMapping = dataSourceProps; webServiceDatasources.Add(dataSource); //**** WeatherData weatherData = new WeatherData(); collWeatherTests = weatherData.GetWeather(webServiceDatasources, location); var weatherTestDTO = new WeatherTestDTO(); foreach (WeatherTestDTO dto in collWeatherTests) { weatherTestDTO.TemperatureCelsius = GetAverageValue(collWeatherTests, nameof(WeatherTestDTO.TemperatureCelsius)); weatherTestDTO.TemperatureFahrenheit = GetAverageValue(collWeatherTests, nameof(WeatherTestDTO.TemperatureFahrenheit)); weatherTestDTO.WindSpeedKph = GetAverageValue(collWeatherTests, nameof(WeatherTestDTO.WindSpeedKph)); weatherTestDTO.WindSpeedMph = GetAverageValue(collWeatherTests, nameof(WeatherTestDTO.WindSpeedMph)); } return(weatherTestDTO); }
public WeatherTestDTO AddConvertedValues(WeatherTestDTO dto) { dto.TemperatureCelsius = dto.TemperatureCelsius == null && dto.TemperatureFahrenheit != null? Converters.ConvertCelsiusToFahrenheit((double)dto.TemperatureFahrenheit) : dto.TemperatureCelsius; dto.TemperatureFahrenheit = dto.TemperatureFahrenheit == null && dto.TemperatureCelsius != null? Converters.ConvertCelsiusToFahrenheit((double)dto.TemperatureCelsius) : dto.TemperatureFahrenheit; dto.WindSpeedKph = dto.WindSpeedKph == null && dto.WindSpeedMph != null? Converters.ConvertMphToKph((double)dto.WindSpeedMph) : dto.WindSpeedKph; dto.WindSpeedMph = dto.WindSpeedMph == null && dto.WindSpeedKph != null? Converters.ConvertKphToMph((double)dto.WindSpeedKph) : dto.WindSpeedMph; return(dto); }