コード例 #1
0
ファイル: InteractiveControls.cs プロジェクト: BrettJohn/CAT
        /// =======================================================================================================
        public static void InteractiveShowReport(Func <Return> returndatafunction, double y_scale)
        {
            CAT.FormAccess(CAT.FormDelegates.FormClose, null, "Report");
            AutoReport autoreport = new AutoReport(CAT.InteractiveControlsFormName);
            Map        map        = new Map(CAT.InteractiveControlsFormName, 0, 0);

            try
            {
                DateTime start    = DateTime.Now;
                bool     complete = false;
                InteractiveAddNamedOverlay("InteractiveProgress", "Started", Status.BUSY);
                new Thread(() =>
                {
                    while (!complete)
                    {
                        InteractiveUpdateNamedOverlay("InteractiveProgress", "Processing " + (DateTime.Now - start).TotalMilliseconds + "ms", Status.BUSY);
                        Thread.Sleep(10);
                    }
                    InteractiveUpdateNamedOverlay("InteractiveProgress", "Complete " + (DateTime.Now - start).TotalMilliseconds + "ms", Status.PASS);
                }).Start();
                autoreport.AddBatch(new BatchReport(0, "Batch"));
                autoreport.AddCommand(new CommandReport(map, "Command"));
                Return returndata = returndatafunction();
                if (returndata.Charts != null)
                {
                    autoreport.AddChartList(map, returndata.Charts);
                }
                if (returndata.Messages != null)
                {
                    foreach (CATMessage msg in returndata.Messages)
                    {
                        autoreport.AddOverlayedMessage(map, msg.Text, msg.Status);
                    }
                }
                autoreport.CommandComplete(map, CAT.Status.PASS);
                autoreport.BatchComplete(0);
                autoreport.AutoComplete();
                CAT.ShowReport(autoreport, y_scale);
                complete = true;
            }
            catch (Exception ex)
            {
                InteractiveUpdateNamedOverlay("InteractiveProgress", "Failed control", Status.PASS);
                autoreport.AddOverlayedMessage(map, CAT.ErrorMsg(ex), CAT.Status.FAIL);
                try { CAT.ShowReport(autoreport, y_scale); } catch { }
            }
        }
コード例 #2
0
ファイル: RunCommand.cs プロジェクト: BrettJohn/CAT
        /// =======================================================================================================
        private static void RunCommand(AutoReport auto_report, Map map, DataGridView batch_data,
                                       out List <Control> interactive_controls,
                                       List <Var> vars = null)
        {
            List <Control> interactivecontrols = null;
            int            rep = 1;

            if (Regex.IsMatch(Data.GetCell(batch_data, (int)CAT.BatchFields.Mode, map.C), COMMAND_MODE_REPEAT))
            {
                rep = Convert.ToInt16(Regex.Match(Data.GetCell(batch_data, (int)CAT.BatchFields.Mode, map.C), COMMAND_MODE_REPEAT).Value.Substring(1));
            }
            if (Regex.IsMatch(Data.GetCell(batch_data, (int)CAT.BatchFields.Mode, map.C), COMMAND_MODE_THREAD_CATCH))
            {
                auto_report.WaitForPreviousBatches(map);
            }
            Action runcommand = new Action(() =>
            {
                for (int i = 1; i <= rep; i++)
                {
                    DataGridViewRow cmd = batch_data.Rows[map.C];
                    string workdir      = Data.GetCell(cmd, (int)CAT.BatchFields.Path);
                    string command      = Data.GetCell(cmd, (int)CAT.BatchFields.Command);
                    Map newmap          = new Map(map.A, map.B, map.C, rep > 1 ? i : 0);
                    auto_report.AddCommand(new CommandReport(newmap, workdir + ">" + command));
                    Status status = Status.START;
                    if (Data.IsCommandEnabled(cmd))
                    {
                        if (vars != null)
                        {
                            string initialcommand = command;
                            string initialworkdir = workdir;
                            foreach (Var vartoinsert in vars)
                            {
                                command = command.Replace("{" + vartoinsert.Name + "}", vartoinsert.Value);
                                workdir = workdir.Replace("{" + vartoinsert.Name + "}", vartoinsert.Value);
                            }
                            command = BasicArithmetic(command);
                            if (initialcommand != command || initialworkdir != workdir)
                            {
                                auto_report.AddOverlayedMessage(newmap, "Variable updates (Workdir>Command): " + workdir + ">" + command, Status.WARN);
                            }
                        }
                        if (string.IsNullOrWhiteSpace(Data.GetCell(cmd, (int)CAT.BatchFields.Command)))
                        {
                            auto_report.AddOverlayedMessage(newmap, "Command is null", Status.FAIL);
                            status = Status.FAIL;
                        }
                        else if (string.IsNullOrWhiteSpace(Data.GetCell(cmd, (int)CAT.BatchFields.Timeout)))
                        {
                            auto_report.AddOverlayedMessage(newmap, "Timeout is null", Status.FAIL);
                            status = Status.FAIL;
                        }
                        else
                        {
                            CAT.FormAccess(CAT.FormDelegates.SetCommandStatus, new object[] { Status.BUSY, newmap.C }, newmap.A);
                            if (Regex.IsMatch(Data.GetCell(cmd, (int)CAT.BatchFields.Path), @".*\.dll"))
                            {
                                status = RunDll(newmap, workdir, command, Data.GetCmdTimeout(cmd), out interactivecontrols, auto_report);
                            }
                            else
                            {
                                status = RunCmd(auto_report, newmap, "cmd.exe", workdir, command, Data.GetCmdTimeout(cmd), "/C");
                            }
                        }
                    }
                    else
                    {
                        status = Status.SKIP;
                    }
                    auto_report.CommandComplete(newmap, status);
                    CAT.FormAccess(CAT.FormDelegates.SetCommandStatus, new object[] { status, newmap.C }, newmap.A);
                }
            });

            if (Regex.IsMatch(Data.GetCell(batch_data, (int)CAT.BatchFields.Mode, map.C), "-t"))
            {
                Task t = new Task(() => { runcommand(); });
                CommandTasks.Add(t);
                t.Start();
            }
            else
            {
                runcommand();
            }
            interactive_controls = interactivecontrols;
        }