public ExecTaskResult Perform(SourceDrop sourceDrop) { var allLines = ReadAllLines(sourceDrop); foreach (var line in allLines) { OnTerminalOutputUpdate("S>" + line + "\r\n"); } var execStatus = ExecutionStatus.Success; if (allLines.Length > 0) { allLines.Where(s => s.StartsWith("exec")).ToList().ForEach(s => { var parsed = Regex.Match(s, @"^exec (\S+) (.*)$"); var tasks = execTaskGenerator. GimeTasks( new ShellTaskDescription { Command = parsed.Groups[1]. Value, Arguments = parsed.Groups[2]. Value }); var task = tasks[0]; task.OnTerminalOutputUpdate += OnTaskOnOnTerminalOutputUpdate; task.Perform(sourceDrop); task.OnTerminalOutputUpdate -= OnTaskOnOnTerminalOutputUpdate; }); var exits = new Dictionary<string, ExecutionStatus> { {"OK", ExecutionStatus.Success}, {"ERROR", ExecutionStatus.Failure} }; var lastItem = allLines.LastItem().ToUpper(); if (lastItem == "EXCEPTION") throw new Exception("Bad things happened here"); if (exits.ContainsKey(lastItem)) { execStatus = exits[lastItem]; } } return new ExecTaskResult(execStatus, 0); }
public ExecTaskResult Perform(SourceDrop sourceDrop) { process = processWrapperFactory(app, arguments, sourceDrop.SourceDropLocation); process.OnErrorOutput += s => { if (s != null) OnTerminalOutputUpdate("E>" + s + "\r\n"); }; process.OnStdOutput += s => { if (s != null) OnTerminalOutputUpdate("S>" + s + "\r\n"); }; OnTerminalOutputUpdate(string.Format("Runz>> Launching {0} with arguments {1} with currentFolder {2}", app, arguments, sourceDrop.SourceDropLocation) + "\r\n"); var exitCode = -100000; try { process.Execute(); OnTaskStarted(process.Id); ObserveTaskPerformance(); exitCode = process.Dispose(); } catch (HangingProcessDetectedException) { var exitcode = process.Dispose(); OnTerminalOutputUpdate(string.Format( "Runz>> It looks like task is hanging without doing much. Task was killed. Exit code: {0}", exitcode) + "\r\n"); return new ExecTaskResult(ExecutionStatus.Failure, exitcode); } catch (TaskQuotaConsumedException) { var exitcode = process.Dispose(); OnTerminalOutputUpdate(string.Format( "Runz>> Task has consumed all its quota. Task was killed. Exit code: {0}", exitcode) + "\r\n"); return new ExecTaskResult(ExecutionStatus.Failure, exitcode); } catch (ApplicationNotFoundException e) { OnTerminalOutputUpdate(string.Format("E> Task has exited with error: {0}", e)); return new ExecTaskResult(ExecutionStatus.Failure, -1); } OnTerminalOutputUpdate(string.Format("Runz>> Task has exited with exitcode {0}", exitCode) + "\r\n"); return new ExecTaskResult(ExecutionStatus.Success, exitCode); }
protected override string[] ReadAllLines(SourceDrop sourceDrop) { return File.ReadAllLines(Path.Combine(sourceDrop.SourceDropLocation, path)); }
protected abstract string[] ReadAllLines(SourceDrop sourceDrop);
protected override string[] ReadAllLines(SourceDrop sourceDrop) { return tasks; }