Exemple #1
0
        public CompilerResult Compile(Solution solution, string directory)
        {
            if (string.IsNullOrEmpty(solution.FileLocation))
            {
                throw new ArgumentNullException(nameof(solution.FileLocation));
            }
            if (string.IsNullOrEmpty(solution.File))
            {
                throw new ArgumentNullException(nameof(solution.File));
            }
            if (!File.Exists(Path.Combine(solution.FileLocation, solution.File)))
            {
                if (Directory.Exists(solution.FileLocation))
                {
                    Directory.Delete(solution.FileLocation, true);
                }
                return(CompilerResult.Fail("Something has gone wrong. Please notify the site administrators."));
            }
            File.Copy(Path.Combine(solution.FileLocation, solution.File), Path.Combine(directory, solution.File));
            var process = Process.Start(new ProcessStartInfo
            {
                FileName               = "exec",
                Arguments              = $"g++ {solution.File}",
                CreateNoWindow         = true,
                RedirectStandardOutput = true,
                RedirectStandardError  = true
            });

            process.WaitForExit();
            var line = process.StandardOutput.ReadLine();

            return(!string.IsNullOrEmpty(line) ? CompilerResult.Fail(line + "\r\n" + process.StandardOutput.ReadToEnd()) : CompilerResult.Succeed());
        }
 public CompilerResult Compile(Solution solution, string directory)
 {
     if (!File.Exists(Path.Combine(solution.FileLocation, solution.File)))
     {
         CompilerResult.Fail("Something has gone wrong.Please notify the site administrators.");
     }
     File.Copy(Path.Combine(solution.FileLocation, solution.File), Path.Combine(directory, solution.File));
     return(CompilerResult.Succeed());
 }