コード例 #1
0
        public ActionResult Index()
        {
            logger.Debug("User " + WebSecurity.GetUserId(User.Identity.Name) +
                         " \"" + User.Identity.Name + "\" visited TestersManagement/Compilers/Index");

            ManageCompilersViewModel viewModel = new ManageCompilersViewModel();

            viewModel.Compilers = new List <Compiler>();
            repository.ProgrammingLanguages.Each(c =>
            {
                if (c.ProgrammingLanguageID != ProgrammingLanguages.Open)
                {
                    viewModel.Compilers.Add(new Compiler()
                    {
                        CompilerID = c.ProgrammingLanguageID,
                        Name       = c.Title,
                        Command    = Compilers.GetCommand(c.ProgrammingLanguageID),
                        Options    = Compilers.GetOptions(c.ProgrammingLanguageID),
                        Available  = c.Available,
                        Enable     = c.Enable
                    });
                }
            });

            return(View(viewModel));
        }
コード例 #2
0
        private void CompilePascal(string SourceFile, string OutputFile, ProgrammingLanguages PL, string WorkingDirectory = null)
        {
            if (PL != ProgrammingLanguages.Pascal &&
                PL != ProgrammingLanguages.Delphi &&
                PL != ProgrammingLanguages.ObjPas &&
                PL != ProgrammingLanguages.TurboPas)
            {
                throw new NotSupportedException();
            }

            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.UseShellExecute        = false;
            startInfo.RedirectStandardError  = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.FileName       = Compilers.GetPath(PL);
            startInfo.Arguments      = Compilers.GetOptions(PL) + " \"" + SourceFile + "\" -o\"" + OutputFile + "\"";
            startInfo.CreateNoWindow = true;
            if (WorkingDirectory != null)
            {
                startInfo.WorkingDirectory = WorkingDirectory;
            }

            string error = "";

            using (Process proc = Process.Start(startInfo))
            {
                error += proc.StandardError.ReadToEnd();
                error += proc.StandardOutput.ReadToEnd();

                proc.WaitForExit();

                logger.Debug("Compilation of file \"{0}\" end", Path.GetFileName(SourceFile));
                if (logger.IsDebugEnabled)
                {
                    Console.WriteLine(DateTime.Now.ToString(culture) + " - Compilation of file \"{0}\" end", Path.GetFileName(SourceFile));
                }

                if (proc.ExitCode != 0)
                {
                    throw new InvalidDataException(error);
                }
            }
        }