/// <summary> /// Identifies the team that has the least point difference. /// </summary> /// <param name="data"> The football data we are asking the question against. </param> /// <returns> The result of asking the question. </returns> public async Task <IReturnType> NotifyAsync(IList <IDataType> data) { _logger.Information($"{GetType().Name} (NotifyAsync): Starting to calculate the result."); // Contract requirements. if (data is null) { throw new ArgumentNullException(nameof(data), "The football data can not be null."); } if (data.Count < 1) { throw new ArgumentException("The football data must contain data."); } var result = await Task.Factory.StartNew(() => { var teamWithSmallestPointRange = string.Empty; var smallestRange = int.MaxValue; foreach (var type in data) { if (type.Data is Football football) { // Contract requirements. Duplicating the validation here. Should we? var footballValidationResult = football.IsValid(); if (!footballValidationResult.IsValid) { throw new ArgumentException(footballValidationResult.Errors.Select(m => m.ErrorMessage).ToString()); } var range = football.CalculatePointDifference(); if (range < smallestRange) { smallestRange = range; teamWithSmallestPointRange = football.TeamName; } } } IReturnType team = new ContainingResultType { ProcessResult = teamWithSmallestPointRange }; return(team); }).ConfigureAwait(false); _logger.Information($"{GetType().Name} (NotifyAsync): Notification complete."); return(result); }
public async Task <IReturnType> NotifyAsync(IList <IDataType> data) { _logger.Information($"{GetType().Name} (NotifyAsync): Starting to calculate the result."); // Contract requirements. if (data is null) { throw new ArgumentNullException(nameof(data), "The weather data can not be null."); } if (data.Count < 1) { throw new ArgumentException("The weather data must contain data."); } var result = await Task.Factory.StartNew(() => { var dayOfLeastChange = 0; var minimumTemperatureChange = float.MaxValue; foreach (var type in data) { if (type.Data is Weather weather) { // Contract requirements. Duplicating the validation here. Should we? var weatherValidationResult = weather.IsValid(); if (!weatherValidationResult.IsValid) { throw new ArgumentException(weatherValidationResult.Errors.Select(m => m.ErrorMessage).ToString()); } var temperatureChange = weather.CalculateWeatherChange(); _logger.Debug($"{GetType().Name} (NotifyAsync): Temperature change calculated: {temperatureChange}."); if (temperatureChange < minimumTemperatureChange) { minimumTemperatureChange = temperatureChange; dayOfLeastChange = weather.Day; } } } IReturnType day = new ContainingResultType { ProcessResult = dayOfLeastChange }; return(day); }).ConfigureAwait(false); _logger.Information($"{GetType().Name} (NotifyAsync): Notification complete."); return(result); }