/// <summary> /// The log invalid sample as error. /// </summary> /// <param name="apiModel"> /// The api model. /// </param> /// <param name="sample"> /// The sample. /// </param> private static void LogInvalidSampleAsError(HelpPageApiModel apiModel, object sample) { var invalidSample = sample as InvalidSample; if (invalidSample != null) { apiModel.ErrorMessages.Add(invalidSample.ErrorMessage); } }
private static HelpPageApiModel GenerateApiModel( ApiDescription apiDescription, HelpPageSampleGenerator sampleGenerator) { var apiModel = new HelpPageApiModel(); apiModel.ApiDescription = apiDescription; try { foreach (var item in sampleGenerator.GetSampleRequests(apiDescription)) { apiModel.SampleRequests.Add(item.Key, item.Value); LogInvalidSampleAsError(apiModel, item.Value); } foreach (var item in sampleGenerator.GetSampleResponses(apiDescription)) { apiModel.SampleResponses.Add(item.Key, item.Value); LogInvalidSampleAsError(apiModel, item.Value); } } catch (Exception e) { apiModel.ErrorMessages.Add( string.Format( CultureInfo.CurrentCulture, "An exception has occurred while generating the sample. Exception Message: {0}", e.Message)); } return apiModel; }