public static CompilerResultViewModel CompileCPlusPlusCode(CodeViewModel code)
        {
            var createRquestt = new RestRequest("Compile", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            createRquestt.AddHeader("Content-Type", "application/json");
            createRquestt.AddHeader("Accept", "application/json");
            createRquestt.AddBody(code);
            try
            {
                var createRestResponset = CompilerNetworkClient.Instance.Execute(createRquestt);
                var response            = createRestResponset.Content;
                var responseObject      = JsonConvert.DeserializeObject <CompilerResultViewModel>(response);
                return(responseObject);
            }
            catch (Exception ex)
            {
                CompilerResultViewModel compilerResult = new CompilerResultViewModel();
                compilerResult.Error      = ex.Message;
                compilerResult.Result     = ex.Message;
                compilerResult.StatusCode = 404;
                return(compilerResult);
            }
        }
Example #2
0
        public ActionResult Compile(CodeViewModel code)
        {
            CompilerResultViewModel result = null;
            string baseUrl = Directory.GetCurrentDirectory();
            string path    = Path.Combine(baseUrl, "Code.cpp");

            try
            {
                writeCodeInFile(path, code.Code);
                Process myProcess = new Process();
                myProcess.StartInfo.UseShellExecute = false;
                // You can start any process, HelloWorld is a do-nothing example.
                myProcess.StartInfo.FileName       = Path.Combine(baseUrl, "Batch.bat");
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();
                myProcess.WaitForExit();

                result        = new CompilerResultViewModel();
                result.Result = "";
                string testUrl = Path.Combine(baseUrl, "result.txt");
                using (StreamReader file = new StreamReader(testUrl))
                {
                    result.Result = file.ReadToEnd();
                }
            }
            catch { }
            return(Ok(result));
        }
Example #3
0
        public IActionResult compileCode(CodeViewModel code)
        {
            var res = CompilerNetworkWebRequest.CompileCPlusPlusCode(code);

            if (res != null)
            {
                res.Success    = true;
                res.StatusCode = 200;
            }
            else
            {
                res            = new CompilerResultViewModel();
                res.Result     = "Api does not working";
                res.Success    = true;
                res.StatusCode = 200;
            }
            return(Ok(res));
        }