public static string GetContent(ApiRequest request, string configuration, TransformalizeResponse response) { var builder = new StringBuilder(); var processes = "[]"; var environments = "[]"; var results = "[]"; const string content = "{}"; var tfl = new TflRoot(configuration); var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; switch (request.RequestType) { case ApiRequestType.MetaData: processes = JsonConvert.SerializeObject(tfl.Processes, Formatting.None, settings); builder.AppendFormat(JSON_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, environments, processes, results, LogsToJson(response.Log), content); return(builder.ToString()); case ApiRequestType.Configuration: processes = JsonConvert.SerializeObject(tfl.Processes, Formatting.None, settings); environments = JsonConvert.SerializeObject(tfl.Environments, Formatting.None, settings); builder.AppendFormat(JSON_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, environments, processes, results, LogsToJson(response.Log), content); return(builder.ToString()); case ApiRequestType.Enqueue: builder.AppendFormat(JSON_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, environments, processes, results, LogsToJson(response.Log), content); return(builder.ToString()); case ApiRequestType.Execute: foreach (var process in tfl.Processes) { process.Connections = new List <TflConnection>(); } processes = JsonConvert.SerializeObject(tfl.Processes, Formatting.None, settings); switch (request.Flavor) { case "arrays": results = new JsonResultsToArrayHandler().Handle(response.Processes); break; case "array": goto case "arrays"; case "dictionaries": results = new JsonResultsToDictionaryHandler().Handle(response.Processes); break; case "dictionary": goto case "dictionaries"; default: results = new JsonResultsToObjectHandler().Handle(response.Processes); break; } builder.AppendFormat(JSON_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, environments, processes, results, LogsToJson(response.Log), content); return(builder.ToString()); default: if (request.Status == 200) { request.Status = 400; request.Message = "Bad Request"; } builder.AppendFormat(JSON_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, environments, processes, results, LogsToJson(response.Log), content); return(builder.ToString()); } }
public static string GetContent(ApiRequest request, string configuration, TransformalizeResponse response) { var builder = new StringBuilder(); var processes = "[]"; var environments = "[]"; var results = "[]"; const string content = "{}"; var tfl = new TflRoot(configuration); var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; switch (request.RequestType) { case ApiRequestType.MetaData: processes = JsonConvert.SerializeObject(tfl.Processes, Formatting.None, settings); builder.AppendFormat(JSON_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, environments, processes, results, LogsToJson(response.Log), content); return builder.ToString(); case ApiRequestType.Configuration: processes = JsonConvert.SerializeObject(tfl.Processes, Formatting.None, settings); environments = JsonConvert.SerializeObject(tfl.Environments, Formatting.None, settings); builder.AppendFormat(JSON_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, environments, processes, results, LogsToJson(response.Log), content); return builder.ToString(); case ApiRequestType.Enqueue: builder.AppendFormat(JSON_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, environments, processes, results, LogsToJson(response.Log), content); return builder.ToString(); case ApiRequestType.Execute: foreach (var process in tfl.Processes) { process.Connections = new List<TflConnection>(); } processes = JsonConvert.SerializeObject(tfl.Processes, Formatting.None, settings); switch (request.Flavor) { case "arrays": results = new JsonResultsToArrayHandler().Handle(response.Processes); break; case "array": goto case "arrays"; case "dictionaries": results = new JsonResultsToDictionaryHandler().Handle(response.Processes); break; case "dictionary": goto case "dictionaries"; default: results = new JsonResultsToObjectHandler().Handle(response.Processes); break; } builder.AppendFormat(JSON_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, environments, processes, results, LogsToJson(response.Log), content); return builder.ToString(); default: if (request.Status == 200) { request.Status = 400; request.Message = "Bad Request"; } builder.AppendFormat(JSON_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, environments, processes, results, LogsToJson(response.Log), content); return builder.ToString(); } }