public IActionResult Compile([FromBody] ShaderCompilationRequestViewModel model)
        {
            try
            {
                var compilationResult = Compiler.Compile(
                    new ShaderCode(model.Language, model.Code),
                    model.CompilationSteps
                    .Select(x => new CompilationStep(x.Compiler, x.Arguments))
                    .ToArray());

                var binaryOutput = compilationResult.PipeableOutput?.Binary != null
                    ? Convert.ToBase64String(compilationResult.PipeableOutput.Binary)
                    : null;

                var viewModel = new ShaderCompilerResultViewModel(
                    binaryOutput,
                    compilationResult.SelectedOutputIndex,
                    compilationResult.Outputs);

                return(Json(viewModel));
            }
            catch (Exception ex)
            {
                return(Json(new ShaderCompilerResultViewModel(
                                null,
                                0,
                                new ShaderCompilerOutput(
                                    "Site error",
                                    null,
                                    ex.ToString()))));
            }
        }
Exemple #2
0
        public IActionResult Compile([FromBody] ShaderCompilationRequestViewModel model)
        {
            try
            {
                var compilationResults = Compiler.Compile(
                    new ShaderCode(model.Language, model.Code),
                    model.CompilationSteps
                    .Select(x => new CompilationStep(x.Compiler, x.Arguments))
                    .ToArray());

                var viewModels = compilationResults
                                 .Select(x =>
                {
                    var binaryOutput = x.PipeableOutput?.Binary != null
                            ? Convert.ToBase64String(x.PipeableOutput.Binary)
                            : null;

                    string outputSize = null;
                    if (x.PipeableOutput?.Binary != null)
                    {
                        outputSize = x.PipeableOutput.Binary.Length + " bytes";
                    }
                    else if (x.PipeableOutput?.Text != null)
                    {
                        outputSize = x.PipeableOutput.Text.Length + " characters";
                    }

                    return(new ShaderCompilerResultViewModel(
                               x.Success,
                               binaryOutput,
                               outputSize,
                               x.SelectedOutputIndex,
                               x.Outputs));
                })
                                 .ToArray();

                return(Json(new ShaderCompilerResultsViewModel(viewModels)));
            }
            catch (Exception ex)
            {
                return(Json(new ShaderCompilerResultsViewModel(
                                new[]
                {
                    new ShaderCompilerResultViewModel(
                        false,
                        null,
                        null,
                        0,
                        new ShaderCompilerOutput(
                            "Site error",
                            null,
                            ex.ToString()))
                })));
            }
        }
        public async Task <IActionResult> CreateGist([FromBody] ShaderCompilationRequestViewModel model)
        {
            var gistId = await GitHubUtility.CreateGistId(model);

            return(Json(gistId));
        }