public override void CompileExecute(
            string _program,
            ref string _compilationOutput,
            ref bool _compilationPassed,
            ref bool _executionPassed,
            ref int _returnCode,
            ref string _executionOutput,
            ref string _sessionKey,
            ref Exception ServiceException
            )
        {
            // Генерация GUID-а
            _sessionKey = Guid.NewGuid().ToString();
            Logger.WriteLine(DateTime.Now.ToString() + " " + _sessionKey + " << income");
            try
            {
                string sessionPath = FileSystemInspector.getSessionPath(_sessionKey);

                // Запускаем компиляцию
                Compiler _compiler = new Compiler(sessionPath, _program);
                // Компиляция присланной программы выполняется в конструкторе класса Compiler, поэтому в этой точке мы уже можем получить информацию о том как прошла компиляция и вывод компилятора
                _compilationOutput = _compiler.Output;
                if (_compiler.Success)
                {
                    Logger.WriteLine(DateTime.Now.ToString() + " " + _sessionKey + " compilation passed successfully");
                    _compilationPassed = true;

                    // Исполнение
                    Executor _executor = new Executor(sessionPath, _compiler.name);
                    // Выполнение программы также происходит в конструкторе класса Executor,
                    //    поэтому после отработки его конструктора мы уже можем получить информацию о том как прошло выполнение программы
                    _executionOutput = _executor.Output;
                    _returnCode      = _executor.returnCode;
                    if (_executor.Success)
                    {
                        Logger.WriteLine(DateTime.Now.ToString() + " " + _sessionKey + " execution passed successfully");
                        _executionPassed = true;
                    }
                    else
                    {
                        Logger.WriteLine(DateTime.Now.ToString() + " " + _sessionKey + " execution failed");
                    }
                }
                else
                {
                    Logger.WriteLine(DateTime.Now.ToString() + " " + _sessionKey + " compilation failed");
                }
            }
            catch (System.Exception e)
            {
                // Произошло исключение - мы должны записать его чтобы вернуть клиенту
                Logger.WriteLine(DateTime.Now.ToString() + " " + _sessionKey + " Exception: " + e.ToString());
                ServiceException = e;
                return;
            }
            Logger.WriteLine(DateTime.Now.ToString() + " " + _sessionKey + " >> completed");
        }
Esempio n. 2
0
        /// <summary>
        /// Выполнить программу и сохранить результаты выполнения
        /// </summary>
        /// <param name="path">Путь к директории, в которой находится exe-файл</param>
        /// <param name="exeName">Имя исполняемого файла, который нужно исполнить</param>
        public Executor(string path, string exeName)
        {
            string _fullPathDirectory = FileSystemInspector.getFullPathDirectory(path);
            string _fullPathExe       = _fullPathDirectory + Settings.delimiter + exeName;

            // Исполняем exe-файл
            using (ProcessDriver pd = new ProcessDriver(_fullPathExe))
            {
                pd.execute();
                _output     = pd.standardOutput;
                _returnCode = pd.returnCode;
            }

            // Записываем  вывод программы в файл
            File.WriteAllText(_fullPathDirectory + Settings.delimiter + executionLogName, _output);
            _operationCompleted = true;
        }
Esempio n. 3
0
        public Compiler(string path, string programm)
        {
            _path     = path;
            _fullPath = FileSystemInspector.getFullPathDirectory(_path);

            // Записываем текст программы в файл
            File.WriteAllText(_path + Settings.delimiter + textOfProgrammName, programm);

            // Делаем компиляцию
            using (ProcessDriver pd = new ProcessDriver(Settings.compilerPath, _fullPath, textOfProgrammName))
            {
                pd.execute();
                _output = pd.standardOutput;
            }

            // Записываем в compilation log логи компиляции
            File.WriteAllText(_path + Settings.delimiter + compilationNameLog, _output);

            if (File.Exists(_path + Settings.delimiter + exeName))
            {
                _name = exeName;
                _operationCompleted = true;
            }
        }
Esempio n. 4
0
            public FileLogger()
            {
                string path = Settings.rootPath;

                fullLogfilename = FileSystemInspector.getFullPathDirectory(path) + Settings.delimiter + logFilename;
            }