示例#1
0
文件: Job.cs 项目: Anders-H/JobRunner
        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}");
                }
            }
        }
示例#2
0
文件: Job.cs 项目: Anders-H/JobRunner
        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;
            }
        }
示例#3
0
文件: Job.cs 项目: Anders-H/JobRunner
        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;
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
                }
            }
        }
示例#8
0
        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);
                }
            }
        }
示例#9
0
        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);
                }
            }
        }
示例#10
0
 public ArgumentDecoder(IVariableList variables)
 {
     _variables = variables;
 }
示例#11
0
 public static VariableValue Create(IVariableList list) => CreateReference(VariableType.List, list ?? new VariableList());
示例#12
0
 public VariableListener(IVariableListener listener, IVariableList list)
 {
     _listener = listener;
     _list     = list;
 }