public async Task <IActionResult> RunAsync( [HttpTrigger(AuthorizationLevel.Function, "GET", Route = "enumerations/{name}/{adapter}")] HttpRequest httpRequest, string name, string adapter, CancellationToken cancellationToken) { IActionResult toReturn = null; if (httpRequest == null) { throw new ArgumentNullException(nameof(httpRequest)); } IHeaderDictionary headerDictionary = httpRequest.Headers; this.httpSpiExecutionContextManager.SetContext(headerDictionary); GetEnumerationMappingsRequest getEnumerationMappingsRequest = new GetEnumerationMappingsRequest() { EnumerationsKey = new EnumerationKey() { Adapter = adapter, Name = name, }, }; toReturn = await this.ProcessWellFormedRequestAsync( getEnumerationMappingsRequest, cancellationToken) .ConfigureAwait(false); return(toReturn); }
private async Task <IActionResult> ProcessWellFormedRequestAsync( GetEnumerationMappingsRequest getEnumerationMappingsRequest, CancellationToken cancellationToken) { IActionResult toReturn = null; this.loggerWrapper.Debug( $"Invoking {nameof(IGetEnumerationMappingsProcessor)} with " + $"{getEnumerationMappingsRequest}..."); GetEnumerationMappingsResponse getEnumerationMappingsResponse = await this.getEnumerationMappingsProcessor.GetEnumerationMappingsAsync( getEnumerationMappingsRequest, cancellationToken) .ConfigureAwait(false); this.loggerWrapper.Info( $"{nameof(IGetEnumerationMappingsProcessor)} invoked with " + $"success: {getEnumerationMappingsResponse}."); Dictionary <string, string[]> mappings = getEnumerationMappingsResponse.MappingsResult.Mappings; if (mappings.Any()) { this.loggerWrapper.Debug( $"Looks like we got some results: " + $"{getEnumerationMappingsResponse}. Returning as JSON."); toReturn = new JsonResult(getEnumerationMappingsResponse); } else { EnumerationKey enumerationsKey = getEnumerationMappingsRequest.EnumerationsKey; this.loggerWrapper.Info( $"No results found for {enumerationsKey}!"); string name = enumerationsKey.Name; string adapter = enumerationsKey.Adapter; toReturn = this.httpErrorBodyResultProvider.GetHttpErrorBodyResult( HttpStatusCode.NotFound, 1, name, adapter); } return(toReturn); }
/// <inheritdoc /> public async Task <GetEnumerationMappingsResponse> GetEnumerationMappingsAsync( GetEnumerationMappingsRequest getEnumerationMappingsRequest, CancellationToken cancellationToken) { GetEnumerationMappingsResponse toReturn = null; if (getEnumerationMappingsRequest == null) { throw new ArgumentNullException( nameof(getEnumerationMappingsRequest)); } EnumerationKey enumerationsKey = getEnumerationMappingsRequest.EnumerationsKey; string enumerationsKeyStr = enumerationsKey.ExportToString(); this.loggerWrapper.Debug( $"Pulling back {nameof(MappingsResult)} for " + $"{nameof(enumerationsKey)} {enumerationsKey} " + $"(\"{enumerationsKeyStr}\") from the " + $"{nameof(ICacheManager)}..."); object unboxedMappingsResult = await this.cacheManager.GetAsync( enumerationsKeyStr, cancellationToken) .ConfigureAwait(false); MappingsResult mappingsResult = unboxedMappingsResult as MappingsResult; // Result will be non-null. this.loggerWrapper.Info( $"{nameof(MappingsResult)} pulled back from the " + $"{nameof(ICacheManager)}: {mappingsResult}."); toReturn = new GetEnumerationMappingsResponse() { MappingsResult = mappingsResult, }; return(toReturn); }