Пример #1
0
        private void btn_taskadd_Click(object sender, EventArgs e)
        {
            var    selected_tasks   = list_taskitem.SelectedItems;
            var    selected_tasks_e = selected_tasks.GetEnumerator();
            string message          = "Want to add" + Environment.NewLine;

            while (selected_tasks_e.MoveNext())
            {
                message += new FileInfo(selected_tasks_e.Current.ToString()).Name + Environment.NewLine;
            }
            message += " in task ?";
            var dialogret = MessageBox.Show(message, "Add Task", MessageBoxButtons.YesNo);

            Console.WriteLine($"Dialog ret {dialogret}");
            if (dialogret == DialogResult.Yes)
            {
                Console.WriteLine("Comfirm add task");
                selected_tasks_e = selected_tasks.GetEnumerator();
                while (selected_tasks_e.MoveNext())
                {
                    cat_local.task task = new cat_local.task();
                    task.task1 = new FileInfo(selected_tasks_e.Current.ToString()).Name;
                    task.state = CatStatus.taskStatus.PENDING.ToString();
                    CatData.localtaskAdd(task);
                }
            }
            gd_taskRefresh();
        }
Пример #2
0
        private void dg_task_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            var taskid = (int)dg_task.Rows[e.RowIndex].Cells["local_id"].Value;

            CatData.taskDelete(taskid);
            gd_taskRefresh();
        }
Пример #3
0
 private void dg_task_DragDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         string[] fileList = (string[])e.Data.GetData(DataFormats.FileDrop);
         string   message  = "Want to add" + Environment.NewLine;
         foreach (var v in fileList)
         {
             message += new FileInfo(v).Name + Environment.NewLine;
         }
         message += " in task ?";
         if (MessageBox.Show(message, "Add Task", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             foreach (var v in fileList)
             {
                 cat_local.task task = new cat_local.task();
                 task.task1 = new FileInfo(v).Name;
                 task.state = CatStatus.taskStatus.PENDING.ToString();
                 CatData.localtaskAdd(task);
             }
             gd_taskRefresh();
         }
     }
 }
Пример #4
0
        public async void gd_taskRefresh()
        {
            dg_task.DataSource = await Task.Factory.StartNew(() => CatData.getlocaltasksByDesc());

            dg_task.Refresh();
        }
Пример #5
0
        public async void Execute()
        {
            try
            {
                CatData.databaseCheck();

                while (device != null && device.sn != "NA")
                {
                    await Task.Delay(new TimeSpan(0, 0, new Random().Next(5, 11)));

                    CatNet.check();

                    if (CatData.databaseConnection)
                    {
                        if (!CatData.catinfoEnroll(device))
                        {
                            continue;
                        }
                        CatData.sync();
                        CatData.pull();
                        CatReg.connect = true;
                    }

                    Console.WriteLine($"CatReg.status {CatReg.status}");
                    if (CatReg.status == CatStatus.uutStatus.STANDBY)
                    {
                        var next_task = CatData.getNexttask();
                        if (next_task != null)
                        {
                            oldlogCheck(next_task.task1);
                            if (executeTest(next_task.task1))
                            {
                                next_task.state = CatStatus.taskStatus.RUNNING.ToString();
                                next_task.start = DateTime.Now;
                                if (CatData.taskUpdate(next_task))
                                {
                                    CatReg.task_name       = next_task.task1;
                                    CatReg.task_status     = CatStatus.taskStatus.RUNNING.ToString();
                                    CatReg.task_id         = next_task.server_id.ToString();
                                    CatReg.task_start_time = DateTime.Now.ToString();
                                    CatReg.task_ap         = next_task.ap;

                                    var catinfo = CatData.getCatInfo();
                                    if (catinfo != null)
                                    {
                                        catinfo.STATUS       = CatStatus.taskStatus.RUNNING.ToString();
                                        catinfo.LastUsedTime = DateTime.Now;
                                        CatData.catinfoUpdate(catinfo);
                                        if (next_task.ap != CatNet.currentssid)
                                        {
                                            CatNet.connectwifi(next_task.ap);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                next_task.state = CatStatus.taskStatus.SCRIPT_ERROR.ToString();
                                next_task.start = DateTime.Now;
                                CatData.taskUpdate(next_task);
                            }
                        }
                        else
                        {
                            Console.WriteLine("task null"); continue;
                        }
                    }
                    else if (CatReg.status == CatStatus.uutStatus.RUNNING)
                    {
                        var current_task = CatData.getCurrenttask();
                        if (current_task != null)
                        {
                            if (!haltOnErrorFind())
                            {
                                var summary = resultFind(current_task.task1);
                                if (summary != null)
                                {
                                    current_task.finish = DateTime.Now;
                                    processKill();
                                    CatNet.ConnectServer();
                                    if (logSummarize(summary, ref current_task))
                                    {
                                        current_task.state        = CatStatus.taskStatus.DONE.ToString();
                                        CatReg.task_status        = CatStatus.taskStatus.DONE.ToString();
                                        CatReg.task_name          = CatStatus.taskName.NO_TASK.ToString();
                                        CatReg.task_id            = "";
                                        CatReg.task_start_time    = "";
                                        CatReg.task_result_folder = "";
                                        CatReg.task_path          = "";
                                        CatReg.task_ap            = CatNet.serverSsid;

                                        CatData.taskUpdate(current_task);
                                    }
                                }
                            }
                            else
                            {
                                current_task.state = CatStatus.taskStatus.HALT.ToString();
                                CatReg.task_status = CatStatus.taskStatus.HALT.ToString();
                                CatData.taskUpdate(current_task);
                            }
                        }
                    }
                    else if (CatReg.status == CatStatus.uutStatus.HALT)
                    {
                        if (!haltOnErrorFind())
                        {
                            var current_task = CatData.getCurrenttask();
                            if (current_task.state != CatStatus.taskStatus.RUNNING.ToString())
                            {
                                Console.WriteLine($"current_task.state {current_task.state}"); current_task.state = CatStatus.taskStatus.RUNNING.ToString();
                            }
                            if (CatReg.task_status != CatStatus.taskStatus.RUNNING.ToString())
                            {
                                Console.WriteLine($"CatReg.task_status {CatReg.task_status}"); CatReg.task_status = CatStatus.taskStatus.RUNNING.ToString();
                            }
                            CatData.taskUpdate(current_task);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log(e.ToString());
            }
        }