Ejemplo n.º 1
0
        public Task GenerateClassFromDocument()
        {
            var id   = GetStringQueryString("id");
            var lang = (GetStringQueryString("lang", required: false) ?? "csharp")
                       .Trim().ToLowerInvariant();

            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (context.OpenReadTransaction())
                {
                    var document = Database.DocumentsStorage.Get(context, id);
                    if (document == null)
                    {
                        HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                        return(Task.CompletedTask);
                    }

                    switch (lang)
                    {
                    case "csharp":
                        break;

                    default:
                        throw new NotImplementedException($"Document code generator isn't implemented for {lang}");
                    }

                    using (var writer = new StreamWriter(ResponseBodyStream()))
                    {
                        var codeGenerator = new JsonClassGenerator(lang);
                        var code          = codeGenerator.Execute(document);
                        writer.Write(code);
                    }

                    return(Task.CompletedTask);
                }
        }