public async Task <IActionResult> RunAsync( [HttpTrigger(AuthorizationLevel.Function, "GET", Route = "enumerations/{name}")] HttpRequest httpRequest, string name, CancellationToken cancellationToken) { IActionResult toReturn = null; if (httpRequest == null) { throw new ArgumentNullException(nameof(httpRequest)); } IHeaderDictionary headerDictionary = httpRequest.Headers; this.httpSpiExecutionContextManager.SetContext(headerDictionary); GetEnumerationValuesRequest getEnumerationValuesRequest = new GetEnumerationValuesRequest() { Name = name, }; toReturn = await this.ProcessWellFormedRequestAsync( getEnumerationValuesRequest, cancellationToken) .ConfigureAwait(false); return(toReturn); }
private async Task <IActionResult> ProcessWellFormedRequestAsync( GetEnumerationValuesRequest getEnumerationValuesRequest, CancellationToken cancellationToken) { IActionResult toReturn = null; this.loggerWrapper.Debug( $"Invoking {nameof(IGetEnumerationValuesProcessor)} with " + $"{getEnumerationValuesRequest}..."); GetEnumerationValuesResponse getEnumerationValuesResponse = await this.getEnumerationsProcessor.GetEnumerationValuesAsync( getEnumerationValuesRequest, cancellationToken) .ConfigureAwait(false); this.loggerWrapper.Info( $"{nameof(IGetEnumerationMappingsProcessor)} invoked with " + $"success: {getEnumerationValuesResponse}."); IEnumerable <string> enumerationValues = getEnumerationValuesResponse .EnumerationValuesResult .EnumerationValues; if (enumerationValues.Any()) { this.loggerWrapper.Debug( $"Looks like we got some results: " + $"{getEnumerationValuesResponse}. Returning as JSON."); toReturn = new JsonResult(getEnumerationValuesResponse); } else { string name = getEnumerationValuesRequest.Name; this.loggerWrapper.Info( $"No results found for enumeration {nameof(name)} " + $"\"{name}\"!"); toReturn = this.httpErrorBodyResultProvider.GetHttpErrorBodyResult( HttpStatusCode.NotFound, 2, name); } return(toReturn); }
/// <inheritdoc /> public async Task <GetEnumerationValuesResponse> GetEnumerationValuesAsync( GetEnumerationValuesRequest getEnumerationValuesRequest, CancellationToken cancellationToken) { GetEnumerationValuesResponse toReturn = null; if (getEnumerationValuesRequest == null) { throw new ArgumentNullException( nameof(getEnumerationValuesRequest)); } string name = getEnumerationValuesRequest.Name; this.loggerWrapper.Debug( $"Pulling back {nameof(EnumerationValuesResult)} for " + $"{nameof(name)} \"{name}\" from the " + $"{nameof(ICacheManager)}..."); object unboxedEnumerationValuesResult = await this.cacheManager.GetAsync(name, cancellationToken) .ConfigureAwait(false); EnumerationValuesResult enumerationValuesResult = unboxedEnumerationValuesResult as EnumerationValuesResult; // Result will be non-null. this.loggerWrapper.Info( $"{nameof(EnumerationValuesResult)} pulled back from the " + $"{nameof(ICacheManager)}: {enumerationValuesResult}."); toReturn = new GetEnumerationValuesResponse() { EnumerationValuesResult = enumerationValuesResult, }; return(toReturn); }