Пример #1
0
        public async System.Threading.Tasks.Task <List <int> > Create(CreateTask createTask)
        {
            if (!this.IsAuth())
            {
                return(null);
            }
            var user = this.GetUserByToken(this.Token());
            List <CommonLibrary.DatabaseModels.Task> tasks = new List <CommonLibrary.DatabaseModels.Task>();

            using (var client = new HttpClient())
            {
                try
                {
                    var res = await client.GetAsync($"{consulWrapper["recognition-api"]["Recognition"]}/ChoiceCategory?data={createTask.Data}");

                    ChoiceCategory choice = await res.Content.ReadAsAsync <ChoiceCategory>();

                    tasks.AddRange(await GenerateTrack(choice, client, createTask, user));
                }
                catch (Exception) { }

                client.DefaultRequestHeaders.Add("token", this.Login("qwer"));
                var userRes = await client.GetAsync("http://172.20.10.6:8000/api/Users?role=worker");

                var users = await userRes.Content.ReadAsAsync <List <CommonLibrary.Clients.Model.User> >();

                foreach (var task in tasks)
                {
                    int actionID = task.ChangeLogs.First().Action;
                    var action   = await NetworkMethodModel.Get <CommonLibrary.DatabaseModels.Action>(consulWrapper["track-api"]["Actions"], actionID);

                    if (action.IsAuto)
                    {
                        if (AutoWorker.HandlerTask(task, action, users))
                        {
                            await Save(task);
                            await ToNextState(task.ID, true);
                        }
                    }
                }

                return(tasks.Select(x => x.ID).ToList());
            }
        }
Пример #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            lbltime.Text = DateTime.Now.ToString();

            if (!AutoWorker.IsBusy)
            {
                count++;
                if (count > SleepTime)
                {
                    count            = 0;
                    btnStart.Enabled = false;
                    WorkArgs args = new WorkArgs()
                    {
                        Type = "开始", Item = null
                    };
                    AutoWorker.RunWorkerAsync(args);
                }
            }
            else
            {
                //MessageBox.Show("后台线程正在工作,请等待上一个工作完成");
            }
        }
Пример #3
0
        private async Task <List <string> > ToNextState(int id, bool ignore)
        {
            if (!this.IsAuth())
            {
                return(null);
            }
            var user = this.GetUserByToken(this.Token());

            var valid = IsValid(id);
            var task  = await context.Tasks.FirstOrDefaultAsync(x => x.ID == id);

            var actionID = task.ChangeLogs.OrderByDescending(x => x.DateTime).First().Action;
            var action   = await NetworkMethodModel.Get <CommonLibrary.DatabaseModels.Action>(consulWrapper["track-api"]["Actions"], actionID);

            if (!ignore && ((UserType)action.UserType).ToString().ToLower() != user.Role.ToLower())
            {
                return(null);
            }

            var validResult = await valid;

            if (validResult.Count > 0)
            {
                return(validResult);
            }

            using (HttpClient client = new HttpClient())
            {
                var res = await client.GetAsync($"{consulWrapper["track-api"]["Actions"]}/nextaction?id={actionID}");

                List <CommonLibrary.DatabaseModels.Action> actions =
                    await res.Content.ReadAsAsync <List <CommonLibrary.DatabaseModels.Action> >();

                CommonLibrary.DatabaseModels.Action newAct = null;
                if (actions.Count != 0)
                {
                    newAct = actions[0];
                }
                else
                {
                    newAct = null;
                }
                context.ChangeLogs.Add(new ChangeLog
                {
                    Action   = newAct?.ID ?? -1,
                    Creator  = user.ID,
                    DateTime = DateTime.Now,
                    Task     = task,
                });
                context.SaveChanges();

                if (newAct != null && newAct.ID != -1 && newAct.IsAuto)
                {
                    var userRes = await client.GetAsync("http://172.20.10.6:8000/api/Users?role=worker");

                    var users = await userRes.Content.ReadAsAsync <List <CommonLibrary.Clients.Model.User> >();

                    if (AutoWorker.HandlerTask(task, action, users))
                    {
                        await Save(task);
                        await ToNextState(task.ID, true);
                    }
                }
            }

            await SendEmail(task, action, AdressType.State);

            return(new List <string>());
        }
Пример #4
0
 public void HireEmployee(AutoWorker employee)
 {
     employees.Add(employee);
 }