public static IEnumerable<IResponseVisualizer> GetVisualizers(ApiResponseModel model) { var contentType = model.ContentType; if (contentType != null) { contentType = contentType.Split(';').First(); List<Type> list; if (visualizersByContentType.TryGetValue(contentType, out list)) { foreach (var type in list) { var visualizer = (IResponseVisualizer)Activator.CreateInstance(type); visualizer.Model = model; yield return visualizer; } } } foreach (var item in visualizersWithPredicate) { var isVisible = item.Item1(model); if (isVisible) { var visualizer = (IResponseVisualizer)Activator.CreateInstance(item.Item2); visualizer.Model = model; yield return visualizer; } } }
protected static int? GetTotalCount(ApiResponseModel response) { var output = response.Api.Outputs.SingleOrDefault(x => x.Name == "total"); if (output?.Value == null) return null; return int.Parse(output.Value.ToString()); }
protected static int? GetLimit(ApiResponseModel response) { var input = response.Api.Inputs.SingleOrDefault(x => x.Name == "limit"); if (input == null) return null; return int.Parse(input.Value); }
protected static int? GetOffset(ApiResponseModel response) { var input = GetOffsetInput(response); if (input == null) return null; return int.Parse(input.Value); }
public Task ProcessOutput(ApiResponseModel response, ApiOutputModel output) { var expression = JsonPathGrammar.Parse(output.Expression); var value = expression.Evaluate(response.JsonResponse); output.Value = value; return TaskConstants.Completed; }
public static ResponseActionState IsActionApplicableToResponse(ApiResponseModel response) { var totalCount = GetTotalCount(response); var offset = GetOffset(response); var limit = GetLimit(response); if (totalCount == null || offset == null || limit == null) return ResponseActionState.Hidden; return offset + limit < totalCount ? ResponseActionState.Enabled : ResponseActionState.Disabled; }
public Task PerformAction(ApiResponseModel response) { var limit = int.Parse(response.Api.Inputs.Single(x => x.Name == "limit").Value); var offsetInput = response.Api.Inputs.Single(x => x.Name == "offset"); var offset = int.Parse(offsetInput.Value); offset = AdjustOffset(offset, limit); offsetInput.Value = offset.ToString(); return response.Api.Send.InvokeAsync(); }
public Task ProcessOutput(ApiResponseModel response, ApiOutputModel output) { switch (response.ContentType) { case ContentTypes.ApplicationJson: return OutputProcessorRegistry.GetProcessor(ApiOutputType.JsonPath).ProcessOutput(response, output); default: throw new Exception($"No output processor defined for Content-Type: {response.ContentType}"); } }
public static IEnumerable<Tuple<IResponseAction, ResponseActionState>> GetActions(ApiResponseModel model) { var contentType = model.ContentType; if (contentType != null) { contentType = contentType.Split(';').First(); List<Type> list; if (actionsByContentType.TryGetValue(contentType, out list)) { foreach (var type in list) { var action = (IResponseAction)Activator.CreateInstance(type); yield return Tuple.Create(action, ResponseActionState.Enabled); } } } foreach (var item in actionsWithPredicate) { var responseActionState = item.Item1(model); var action = (IResponseAction)Activator.CreateInstance(item.Item2); yield return Tuple.Create(action, responseActionState); } }
protected static ApiInputModel GetOffsetInput(ApiResponseModel response) { var offsetInput = response.Api.Inputs.SingleOrDefault(x => x.Name == "offset"); return offsetInput; }