예제 #1
0
 void OnValidateClick()
 {
     if (ValidateForm())
     {
         BindItem();
         onValidate.Invoke(this);
     }
 }
예제 #2
0
 public void Submit()
 {
     if (_username.text.Length >= _minCharacters)
     {
         onSubmitForm?.Invoke(_username.text);
     }
     else
     {
         //Develop a validation system with interfaces?
         _feedBackText.text = "Username is too short (6-16)!";
     }
 }
예제 #3
0
 void OnCancelClick()
 {
     onCancel.Invoke(this);
 }
예제 #4
0
        private void DeployThread(object state)
        {
            while (start)
            {
                foreach (var item in userEntity)
                {
                    int rowNumber = item.Key;

                    object[]        entity = userEntity[item.Key];
                    DataGridViewRow row    = userRow[item.Key];

                    int dotimes  = (int)row.Cells[4].Value;
                    int left     = (int)row.Cells[3].Value;
                    int duration = (int)row.Cells[3].Value;


                    string usrname  = entity[1] as string;
                    string password = entity[2] as string;

                    if (!userRun.ContainsKey(item.Key) || !userRun[item.Key])
                    {
                        //标橙色
                        row.Cells[5].Style.BackColor = Color.Orange;
                        row.Cells[5].Value           = "不再运行";
                        continue;
                    }

                    //标绿色
                    row.Cells[5].Style.BackColor = Color.LawnGreen;
                    row.Selected = false;


                    try
                    {
                        //登陆
                        row.Cells[5].Value = "登陆中";
                        Processor processor = new Processor(usrname, password);
                        Dictionary <string, string> keyValuePairs = processor.Login();


                        while (userRun.ContainsKey(item.Key) && userRun[item.Key])
                        {
                            if (left == 0)
                            {
                                row.Cells[5].Value = "寻找受理中";
                                WorkTaskAcceptExecutor workTaskAccept = new WorkTaskAcceptExecutor(keyValuePairs);
                                Task <bool>            b = workTaskAccept.Login();

                                if (b.Result)//二次登陆成功
                                {
                                    List <WorkTask> workTasks = workTaskAccept.FetchTaskList().Result;
                                    if (workTasks.Count > 0)
                                    {
                                        List <WorkTask> needAccept = workTaskAccept.FetchPendingTaskList(workTasks);
                                        if (needAccept.Count > 0)
                                        {//
                                            Debug.WriteLine("受理" + needAccept.Count + "个");
                                            foreach (var task in needAccept)
                                            {
                                                if (workTaskAccept.AcceptOneTask(task).Result)
                                                {
                                                    Debug.WriteLine("受理成功");
                                                    row.Cells[5].Style.BackColor = Color.Green;
                                                    row.Cells[5].Value           = "受理成功";
                                                    dotimes++;
                                                    Thread.Sleep(3000);
                                                    row.Cells[5].Style.BackColor = Color.LawnGreen;

                                                    /**
                                                     * 带着break只说明这个账户只受理一个
                                                     */
                                                    break;
                                                }
                                                else
                                                {
                                                    Debug.WriteLine("受理失败");
                                                }
                                            }

                                            row.Cells[4].Value = dotimes;
                                            //通知入库
                                            FormEvent?.Invoke(rowNumber, row, 4, null);


                                            //下一个账户

                                            break;
                                        }
                                        else
                                        {
                                            Debug.WriteLine("没有待受理任务");
                                            row.Cells[5].Value = "无待受理任务";
                                            Thread.Sleep(1000);
                                        }
                                    }
                                    else
                                    {
                                        Debug.WriteLine("没有任何任务");
                                        row.Cells[5].Value = "无任务";
                                        Thread.Sleep(1000);
                                    }
                                }

                                left = duration + 1;
                            }



                            left--;

                            row.Cells[5].Value = left;//通知更改
                            Debug.WriteLine("DO:" + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString());
                            Thread.Sleep(1000);
                        }
                        //运行结束
                        row.Cells[5].Style.BackColor = Color.Yellow;
                        row.Cells[5].Value           = "等待运行";
                    }
                    catch (AggregateException e)
                    {
                        e.Handle((err) =>
                        {
                            switch (err.GetType().ToString())
                            {
                            case "Exception":
                                MessageEvent?.Invoke(rowNumber, row, err.Message, WorkerMessageType.ERROR);
                                row.ErrorText      = err.Message;
                                userRun[rowNumber] = false;

                                row.Cells[5].Value           = "错误";
                                row.Cells[5].Style.BackColor = Color.Red;

                                break;

                            default:
                                Debug.WriteLine(err.GetType().ToString());
                                MessageEvent?.Invoke(rowNumber, row, err.Message, WorkerMessageType.ERROR);
                                row.ErrorText                = err.Message;
                                userRun[rowNumber]           = false;
                                row.Cells[5].Value           = "错误";
                                row.Cells[5].Style.BackColor = Color.Red;
                                break;
                            }

                            return(true);
                        });
                    }
                }
                //主循环
                //Thread.Sleep(3000);
            }
            if (!start)
            {
                foreach (var i in userRow)
                {
                    i.Value.Cells[5].Value           = "停止执行";
                    i.Value.Cells[5].Style.BackColor = Color.Red;
                }
            }
        }