public void Run(ILogger log, IGridVisualFeedback grid, IVariableList variableList) { try { StartTime = DateTime.Now; if (Config.EnableLogging) { var s = StartTime.Value; var h = Hidden ? " (hidden)" : ""; var n = Name.Trim(); if (string.IsNullOrEmpty(n)) { n = Command; } var result = log.AppendLog($"{s.Year:0000}-{s.Month:00}-{s.Day:00} {s.Hour:00}:{s.Minute:00}:{s.Second:00}{h}: {n}"); if (!result && Config.TreatLoggingErrorsAsStepErrors) { throw new SystemException("Logging failed."); } } if (Command.StartsWith("@")) { InProcess(grid, variableList); } else { OutOfProcess(grid, variableList); } EndTime = DateTime.Now; if (Config.EnableLogging) { var s = EndTime.Value; var result = log.AppendLog($"Ended at {s.Year:0000}-{s.Month:00}-{s.Day:00} {s.Hour:00}:{s.Minute:00}:{s.Second:00} with exit code: {ExitCode}."); if (!result && Config.TreatLoggingErrorsAsStepErrors) { throw new SystemException("Logging failed."); } } } catch (Exception e) { EndTime = DateTime.Now; Status = JobStatus.Failed; FailMessage = e.Message; if (string.IsNullOrWhiteSpace(FailMessage)) { FailMessage = e.GetType().Name; } if (Config.EnableLogging) { var s = EndTime.Value; log.AppendLog($"System error at {s.Year:0000}-{s.Month:00}-{s.Day:00} {s.Hour:00}:{s.Minute:00}:{s.Second:00}: {FailMessage}"); } } }
private void InProcess(IGridVisualFeedback grid, IVariableList variableList) { var inProcessJobIdentifyerHelper = new InProcessJobIdentifyerHelper(); var jobId = inProcessJobIdentifyerHelper.GetIdentifyerFromString(Command); var job = inProcessJobIdentifyerHelper.GetJob(jobId); var args = new ArgumentList(Arguments); args = args.Decode(variableList); job.Begin(args); while (!job.HasExited) { grid.CursorBlink = !grid.CursorBlink; grid.Invalidate(); Thread.Sleep(1000); if (DateTime.Now.Subtract(StartTime !.Value) <= Timeout) { continue; } EndTime = DateTime.Now; Status = JobStatus.Timeout; FailMessage = "Timeout"; ExitCode = -1; return; } ExitCode = job.ExitCode; Status = ExitCode == 0 ? JobStatus.Completed : JobStatus.Failed; if (Status == JobStatus.Failed && job.Exception != null) { FailMessage = job.Exception.Message; } }
private void OutOfProcess(IGridVisualFeedback grid, IVariableList variableList) { var start = new ProcessStartInfo(Command) { Arguments = new ArgumentDecoder(variableList).GetDecodedText(Arguments), WindowStyle = Hidden ? ProcessWindowStyle.Hidden : ProcessWindowStyle.Normal }; var process = Process.Start(start); if (process == null) { Status = JobStatus.Failed; return; } while (!process.HasExited) { grid.CursorBlink = !grid.CursorBlink; grid.Invalidate(); Thread.Sleep(1000); if (DateTime.Now.Subtract(StartTime !.Value) <= Timeout) { continue; } process.Kill(); EndTime = DateTime.Now; Status = JobStatus.Timeout; FailMessage = "Timeout"; return; } ExitCode = process.ExitCode; Status = ExitCode == 0 ? JobStatus.Completed : JobStatus.Failed; }
public bool Resolve(IVariableStore variables, ListVariableSource source, out IVariableList result) { if (source.Type == VariableSourceType.Reference) { return(Resolve(variables, source.Reference, out result)); } result = source.Value; return(true); }
public ArgumentList Decode(IVariableList variableList) { var result = new ArgumentList(); var argumentDecoder = new ArgumentDecoder(variableList); result.AddRange( this.Select(a => a.StartsWith("-") ? a : argumentDecoder.GetDecodedText(a)) ); return(result); }
public bool Resolve(IVariableStore variables, VariableReference reference, out IVariableList result) { var value = reference.GetValue(variables); if (value.TryGetList(out result)) { return(true); } LogResolveWarning(value, reference, VariableType.List); return(false); }
private void ExtractProcedure(Procedure procedure) { IStatementList children = procedure.Body; for (int i = 0; i < children.GetSize(); i++) { Statement child = children[i]; ExtractStatement(child, procedure); if (i > 0) { Statement previousChild = children[i - 1]; FollowsTable.SetFollows(previousChild, child); if (!(previousChild is If)) { NextTable.SetNext(previousChild, child); } else { ExtractIfNext(previousChild as If, child); } } IVariableList modifiedVariables = ModifiesTable.GetModifiedBy(child); IVariableList usedVariables = UsesTable.GetUsedBy(child); foreach (Variable variable in modifiedVariables) { ModifiesTable.SetModifies(procedure, variable); } foreach (Variable variable in usedVariables) { UsesTable.SetUses(procedure, variable); } } }
private void ExtractProcedureCalls(Procedure procedure) { IProcedureList callingProcedures = CallsTable.GetCalling(procedure); foreach (Procedure callingProcedure in callingProcedures) { List <Call> procedureCalls = calls[callingProcedure].Where(x => x.Procedure == procedure).ToList(); foreach (Call call in procedureCalls) { IStatementList callParents = ParentTable.GetParentT(call); IVariableList modifiedVariables = ModifiesTable.GetModifiedBy(procedure); IVariableList usedVariables = UsesTable.GetUsedBy(procedure); foreach (Variable variable in modifiedVariables) { ModifiesTable.SetModifies(call, variable); ModifiesTable.SetModifies(callingProcedure, variable); foreach (Statement parent in callParents) { ModifiesTable.SetModifies(parent, variable); } } foreach (Variable variable in usedVariables) { UsesTable.SetUses(call, variable); UsesTable.SetUses(callingProcedure, variable); foreach (Statement parent in callParents) { UsesTable.SetUses(parent, variable); } } ExtractProcedureCalls(callingProcedure); } } }
private void ExtractBody(Container container, IStatementList body, Procedure procedureContext) { for (int i = 0; i < body.GetSize(); i++) { Statement child = body[i]; ExtractStatement(child, procedureContext); ParentTable.SetParent(container, child); if (i > 0) { Statement previousChild = body[i - 1]; FollowsTable.SetFollows(previousChild, child); if (!(previousChild is If)) { NextTable.SetNext(previousChild, child); } else { ExtractIfNext(previousChild as If, child); } } IVariableList modifiedVariables = ModifiesTable.GetModifiedBy(child); IVariableList usedVariables = UsesTable.GetUsedBy(child); foreach (Variable variable in modifiedVariables) { ModifiesTable.SetModifies(container, variable); } foreach (Variable variable in usedVariables) { UsesTable.SetUses(container, variable); } } }
public ArgumentDecoder(IVariableList variables) { _variables = variables; }
public static VariableValue Create(IVariableList list) => CreateReference(VariableType.List, list ?? new VariableList());
public VariableListener(IVariableListener listener, IVariableList list) { _listener = listener; _list = list; }