Exemplo n.º 1
0
        public static string GetContent(ApiRequest request, string configuration, TransformalizeResponse response)
        {
            var content   = string.Empty;
            var results   = string.Empty;
            var builder   = new StringBuilder();
            var processes = string.Empty;

            switch (request.RequestType)
            {
            case ApiRequestType.MetaData:
                builder.Append(configuration);
                builder.InsertFormat(builder.LastIndexOf('<'), RESPONSE_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, string.Empty, LogsToXml(response.Log), content);
                return(builder.ToString());

            case ApiRequestType.Configuration:
                builder.Append(configuration);
                builder.InsertFormat(builder.LastIndexOf('<'), MINIMAL_RESPONSE_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds);
                return(builder.ToString());

            case ApiRequestType.Enqueue:
                builder.AppendFormat(XML_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, string.Empty, processes, results, LogsToXml(response.Log), content);
                return(builder.ToString());

            case ApiRequestType.Execute:

                switch (request.Flavor)
                {
                case "attributes":
                    processes = SecureConfiguration(configuration);
                    results   = new XmlResultsToAttributesHandler().Handle(response.Processes);
                    break;

                case "table":
                    content = new XmlResultsToHtmlTable().Handle(response.Processes);
                    break;

                default:
                    processes = SecureConfiguration(configuration);
                    results   = new XmlResultsToDictionaryHandler().Handle(response.Processes);
                    break;
                }
                builder.AppendFormat(XML_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, string.Empty, processes, results, LogsToXml(response.Log), content);
                return(builder.ToString());

            default:
                if (request.Status == 200)
                {
                    request.Status  = 400;
                    request.Message = "Bad Request";
                }
                builder.AppendFormat(XML_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, string.Empty, processes, results, LogsToXml(response.Log), content);
                return(builder.ToString());
            }
        }
        public static string GetContent(ApiRequest request, string configuration, TransformalizeResponse response) {

            var content = string.Empty;
            var results = string.Empty;
            var builder = new StringBuilder();
            var processes = string.Empty;

            switch (request.RequestType) {
                case ApiRequestType.MetaData:
                    builder.Append(configuration);
                    builder.InsertFormat(builder.LastIndexOf('<'), RESPONSE_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, string.Empty, LogsToXml(response.Log), content);
                    return builder.ToString();

                case ApiRequestType.Configuration:
                    builder.Append(configuration);
                    builder.InsertFormat(builder.LastIndexOf('<'), MINIMAL_RESPONSE_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds);
                    return builder.ToString();

                case ApiRequestType.Enqueue:
                    builder.AppendFormat(XML_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, string.Empty, processes, results, LogsToXml(response.Log), content);
                    return builder.ToString();

                case ApiRequestType.Execute:

                    switch (request.Flavor) {
                        case "attributes":
                            processes = SecureConfiguration(configuration);
                            results = new XmlResultsToAttributesHandler().Handle(response.Processes);
                            break;
                        case "table":
                            content = new XmlResultsToHtmlTable().Handle(response.Processes);
                            break;
                        default:
                            processes = SecureConfiguration(configuration);
                            results = new XmlResultsToDictionaryHandler().Handle(response.Processes);
                            break;
                    }
                    builder.AppendFormat(XML_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, string.Empty, processes, results, LogsToXml(response.Log), content);
                    return builder.ToString();

                default:
                    if (request.Status == 200) {
                        request.Status = 400;
                        request.Message = "Bad Request";
                    }
                    builder.AppendFormat(XML_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, string.Empty, processes, results, LogsToXml(response.Log), content);
                    return builder.ToString();
            }

        }