Exemplo n.º 1
0
        /// =======================================================================================================
        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 { }
            }
        }
Exemplo n.º 2
0
        /// =======================================================================================================
        public static bool Run(string auto_alias, string binary_name, string number = null, bool new_form = false)
        {
            int        commandnumber = Convert.ToInt32(number);
            int        batchnumber   = 0;                          // Default
            AutoReport autoreport    = new AutoReport(auto_alias); // Always something to report

            autoreport.Enabled = (bool)FormAccess(FormDelegates.ReportEnabled, null, auto_alias);
            List <Control> interactivecontrols = new List <Control>();

            if (!Running) // Not allowed to run while running
            {
                string autovars = (string)FormAccess(FormDelegates.GetAutoVars, null, auto_alias);
                if (!autovars.Contains(COMMAND_MODE_DIRTY_RUN))
                {
                    CleanRun(auto_alias);
                }
                AutoTasks    = new List <Task>();
                BatchTasks   = new List <Task>();
                CommandTasks = new List <Task>();
                Running      = true;
                RunMode      = RunType.Command;
                string       binary_path = DISK.AutoAddBaseDirectory(auto_alias + @"\" + binary_name);
                DataGridView batchdata   = Data.BlankDgv((int)CAT.BatchFields.NumberOfColumns);
                DataGridView autodata    = Data.BlankDgv((int)CAT.AutoFields.NumberOfColumns);
                if (File.Exists(binary_path))
                {
                    if (Regex.IsMatch(binary_path, "auto.bin"))
                    {
                        Data.LoadDataGrid(binary_path, ref autodata);
                        RunMode = number == null ? RunType.Auto : RunType.Batch;
                        if (RunMode == RunType.Batch)
                        {
                            Data.LoadDataGrid(new FileInfo(binary_path).Directory.FullName + @"\batch" + number + ".bin", ref batchdata);
                        }
                    }
                    else if (Regex.IsMatch(binary_path, @"batch\d*.bin"))
                    {
                        Data.LoadDataGrid(new FileInfo(binary_path).Directory.FullName + @"\auto.bin", ref autodata);
                        RunMode = number == null ? RunType.Batch : RunType.Command;
                        Data.LoadDataGrid(binary_path, ref batchdata);
                        string subvalue = Regex.Match(binary_path, @"batch\d*.bin").Value;
                        string newvalue = Regex.Match(subvalue, @"[0-9]+").Value;
                        batchnumber = Convert.ToInt32(newvalue);
                    }
                    else
                    {
                        Running = false; throw new Exception("Binary " + binary_path + " is invalid - thus did not start automation");
                    }
                }
                else
                {
                    Running = false; throw new Exception("Binary " + binary_path + " does not exist - thus did not start automation");
                }
                switch (RunMode)
                {
                case RunType.Command:
                    if (Regex.IsMatch(Data.GetCell(batchdata, (int)CAT.BatchFields.Mode, commandnumber), "-nr"))
                    {
                        autoreport.Enabled = false;
                    }
                    autoreport.AddBatch(new BatchReport(batchnumber, Data.GetCell(autodata, (int)CAT.AutoFields.Name, batchnumber)));
                    RunCommand(autoreport, new Map(auto_alias, batchnumber, commandnumber), batchdata, out interactivecontrols, GetAutoVars(autodata, batchnumber, auto_alias));
                    autoreport.WaitForBatch(batchnumber);
                    Running = false;
                    break;

                case RunType.Batch:
                    if (Regex.IsMatch(Data.GetCell(autodata, (int)CAT.AutoFields.Mode, batchnumber), "-nr"))
                    {
                        autoreport.Enabled = false;
                    }
                    RunBatch(autoreport, auto_alias, batchnumber, autodata, batchdata, out interactivecontrols);
                    Running = false;
                    break;

                case RunType.Auto:
                    RunAuto(autoreport, auto_alias, binary_name, out interactivecontrols);
                    Running = false;
                    break;
                }
                autoreport.WaitForAuto();
                if (autoreport.Enabled)
                {
                    ShowReport(autoreport);
                }
                if (interactivecontrols != null && interactivecontrols.Count > 0)
                {
                    InteractiveShowControls(interactivecontrols);
                }
                return(true);
            }
            else
            {
                autoreport.AddOverlay("Busy running automation - thus did not start new automation - please wait (or click abort then retry run)...", Status.BUSY);
                return(false);
            }
        }
Exemplo n.º 3
0
        /// =======================================================================================================
        private static void RunBatch(AutoReport auto_report, string auto_alias, int batch_number,
                                     DataGridView auto_data, DataGridView batch_data, out List <Control> interactive_controls, int?command_number = null)
        {
            List <Control> interactivecontrols = new List <Control>();
            int            rep = 1;

            if (Regex.IsMatch(Data.GetCell(auto_data, (int)CAT.AutoFields.Mode, batch_number), COMMAND_MODE_REPEAT))
            {
                rep = Convert.ToInt16(Regex.Match(Data.GetCell(auto_data, (int)CAT.AutoFields.Mode, batch_number), COMMAND_MODE_REPEAT).Value.Substring(1));
            }
            for (int i = 0; i < rep; i++)
            {
                Action runbatch = new Action(() =>
                {
                    FormAccess(FormDelegates.SelectAutoRow, new object[] { batch_number }, auto_alias);
                    FormAccess(FormDelegates.LoadBatchData, new object[] { batch_number }, auto_alias);
                    FormAccess(FormDelegates.ClearBatchStatuses, new object[] { }, auto_alias);
                    auto_report.AddBatch(new BatchReport(batch_number, Data.GetCell(auto_data, (int)CAT.AutoFields.Name, batch_number)));
                    Status?status = null;
                    if (Data.IsBatchEnabled(auto_data, batch_number) || command_number != null)
                    {
                        CAT.FormAccess(CAT.FormDelegates.SetBatchStatus, new object[] { Status.BUSY, batch_number }, auto_alias);
                        foreach (DataGridViewRow commandrow in batch_data.Rows)
                        {
                            if (!AbortAll && ((command_number != null && command_number == commandrow.Index) || command_number == null) && commandrow.Index < batch_data.RowCount - 1)
                            {
                                FormAccess(FormDelegates.SelectBatchRow, new object[] { commandrow.Index }, auto_alias);
                                List <Control> ctrls;
                                RunCommand(auto_report, new Map(auto_alias, batch_number, commandrow.Index), batch_data, out ctrls, GetAutoVars(auto_data, batch_number, auto_alias));
                                if (ctrls != null)
                                {
                                    foreach (Control ctrl in ctrls)
                                    {
                                        interactivecontrols.Add(ctrl);
                                    }
                                }
                            }
                        }
                        status = auto_report.CalculatedBatchResult(batch_number);
                    }
                    else
                    {
                        status = Status.SKIP;
                    }

                    CAT.FormAccess(CAT.FormDelegates.SetBatchStatus, new object[] { status, batch_number }, auto_alias);
                    auto_report.BatchComplete(batch_number, status);
                });
                if (Regex.IsMatch(Data.GetCell(auto_data, (int)CAT.AutoFields.Mode, batch_number), "-t"))
                {
                    Task t = new Task(() => { runbatch(); });
                    BatchTasks.Add(t);
                    t.Start();
                }
                else
                {
                    runbatch();
                    CAT.FormAccess(CAT.FormDelegates.SaveSelectedBatch, new object[] { }, auto_alias);
                }
            }
            interactive_controls = interactivecontrols;
        }