示例#1
0
        /// <summary>
        /// Compileaza un text
        /// </summary>
        /// <param name="sourceText">Textul care trebuie compilat</param>
        /// <param name="compiler">Compilatorul folosit</param>
        /// <returns></returns>
        public bool CompileText(string sourceText, CompilerData compiler)
        {
            if (compiler == null)
            {
                Messages.ShowMessageBox(Messages.INVALID_COMPILER_SELECTED, "warn");
                return false;
            }

            try
            {
                string tmpFileName = "tmpFile.";
                tmpFileName += compiler.SourceFileExtension;
                using (StreamWriter sw = new StreamWriter(Path.GetTempPath()+ tmpFileName,
                    false, System.Text.Encoding.ASCII))
                {
                    sw.WriteLine(sourceText);
                    sw.Flush();
                    return CompileFile(tmpFileName, compiler);
                }
            }
            catch (Exception e)
            {
                ExceptionsHandler.Instance.AddException(e, Messages.ERROR_COMPILE);
                return false;
            }
        }
示例#2
0
        /// <summary>
        /// Executa ultimul fisier compilat
        /// </summary>
        /// <returns></returns>
        public bool ExecuteCompiledFile(CompilerData compilerData)
        {
            try
            {
                const string fileName = "tmpFile.exe";
                string workPath = compilerData.WorkingPath;
                if (!File.Exists(workPath + fileName))
                    return false;

                Process proces = CreateProcess(workPath + fileName, workPath, "");
                proces.Start();
                proces.StandardInput.WriteLine(ConsoleInputText);
                proces.WaitForExit(5000); // maxim 5 secunde
                if (!proces.HasExited) // daca nu a iesit il terminam
                {
                    proces.Kill();
                    ExceptionsHandler.Instance.AddException(new TimeoutException(Messages.PROGRAM_TERMINATED_TOO_LONG),
                        Messages.PROGRAM_TERMINATED_TOO_LONG);
                }
                ConsoleOutputText = proces.StandardOutput.ReadToEnd();
                return true;
            }
            catch (Exception e)
            {
                ExceptionsHandler.Instance.AddException(e, "");
                return false;
            }
        }
示例#3
0
        /// <summary>
        /// Compileaza fisierul cu cod sursa
        /// </summary>
        /// <param name="fileName">Numele fisierului</param>
        /// <param name="compiler">Compilatorul folosit</param>
        /// <returns></returns>
        public bool CompileFile(string fileName, CompilerData compiler)
        {
            if (!compiler.HasValidPath)
            {
                Messages.ShowMessageBox(Messages.COMPILER_EXE_NOT_FOUND, "");
                return false;
            }

            try
            {
                // sterge si copiaza noul cod sursa
                if (File.Exists(compiler.WorkingPath + fileName))
                    File.Delete(compiler.WorkingPath + fileName);
                File.Copy(Path.GetTempPath() + fileName, compiler.WorkingPath + fileName);

                string exeFileName = Path.GetFileNameWithoutExtension(fileName) + ".exe";
                // sterge programul compilat anterior, daca exista
                //if (File.Exists(Path.Combine(compiler.WorkingPath,exeFileName)))
                //    File.Delete(Path.Combine(compiler.WorkingPath,exeFileName));

                // adauga ghilimele in cazul ca path-ul are spatii (eg: Program Files devine: "Program Files" )
                //compiler.FullPath = "\"" + compiler.FullPath + "\"";
                //compiler.WorkingPath = compiler.WorkingPath;

                Process proces = CreateProcess(compiler.FullPath, compiler.WorkingPath,
                    compiler.GetArguments(fileName, exeFileName));
                proces.Start();
                proces.WaitForExit(5000);
                if (!proces.HasExited)
                    proces.Kill();

                LastOutput = proces.StandardOutput.ReadToEnd();
                LastError = proces.StandardError.ReadToEnd();
                return true;
            }
            catch (Exception e)
            {
                ExceptionsHandler.Instance.AddException(e, Messages.ERROR_COMPILE);
                return false;
            }
        }