public TaskItemModel GetTaskByStatus(StatusTask status)
 {
     foreach (var task in _tasks)
     {
         if (task.Status.Equals(status))
         {
             return(task);
         }
     }
     throw new ValueNotFoundException("Указанная задача не найдена");
 }
Exemplo n.º 2
0
        private void display_tasks(StatusTask s, ListView list)
        {
            var user = ctx.Angajats.Find(userId);
            List <TaskerModel.Task> items = new List <TaskerModel.Task>();
            var sortedPriority            = from t in s.Tasks
                                            orderby t.Prioritate descending
                                            select t;

            foreach (TaskerModel.Task t in sortedPriority)
            {
                if (t.IdAngajat == userId || user.IsManager == true)
                {
                    var    findNume = ctx.Angajats.Find(t.IdAngajat);
                    string nume     = null;
                    if (findNume != null)
                    {
                        nume = findNume.Nume;
                    }
                    string b1 = t.Denumire.ToString();
                    string b2;
                    if (t.Descriere != null)
                    {
                        b2 = t.Descriere.ToString() + Environment.NewLine + "Assigned to: " + nume;
                    }
                    else
                    {
                        b2 = Environment.NewLine + "Assigned to: " + nume;
                    }
                    string b3 = t.Deadline.ToString();
                    string b4 = t.Id.ToString();
                    string b5 = t.IdAngajat.ToString();
                    items.Add(new TaskerModel.Task()
                    {
                        Id = Convert.ToInt32(b4), Denumire = b1, Descriere = b2, Deadline = Convert.ToDateTime(b3).Date, IdAngajat = Convert.ToInt32(b5)
                    });

                    //checking if the deadline has passed
                    if (Convert.ToDateTime(b3).Date < DateTime.Now && (s.Cod == 1 || s.Cod == 2) && !showedNotif)
                    {
                        MessageBox.Show("The deadline for the Task '" + b1 + "' has passed!", "The task is overdue", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }

                    //sending reminders
                    TimeSpan d = (TimeSpan)(Convert.ToDateTime(b3).Date - DateTime.Now);
                    if (d.TotalDays <= 3 && d.TotalDays > 0 && (s.Cod == 1 || s.Cod == 2) && !showedNotif)
                    {
                        MessageBox.Show("The deadline for the Task '" + b1 + "' is in " + Convert.ToInt32(d.TotalDays) + "days.", "Reminder", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
            list.ItemsSource = items;
        }
        void ReleaseDesignerOutlets()
        {
            if (StatusTask != null)
            {
                StatusTask.Dispose();
                StatusTask = null;
            }

            if (TitleTask != null)
            {
                TitleTask.Dispose();
                TitleTask = null;
            }
        }
Exemplo n.º 4
0
 public StatusTaskModel(StatusTask status)
 {
     Id   = (int)status;
     Name = status.ToString();
 }
Exemplo n.º 5
0
        private void InstanceTripped(SchedulingEventArg arg)
        {
            lock (_heart)
            {
                Sheduler sheduler = null;
                using (
                    ISession session =
                        NHibernateHelper.SessionManager.GetSessionFor <WebEnvironmentFiact>().SessionFactory.OpenSession()
                    )
                {
                    try
                    {
                        sheduler = session.Get <TSheduler>(_id);
                        if (sheduler == null)
                        {
                            arg.Interval = -1;
                            return;
                        }
                        if (_cancelTokSource != null)
                        {
                            arg.Interval = -1;
                            return;
                        }
                        State              = TaskExecutionType.Running;
                        sheduler.LastRun   = _heart.LastRun;
                        sheduler.Iteration = _heart.CountLaunches;
                        _cancelTokSource   = new CancellationTokenSource();

                        _status = new StatusTask
                        {
                            StartRun     = DateTime.Now,
                            EndRun       = null,
                            Error        = null,
                            Sheduler     = session.Get <Sheduler>(Id),
                            TaskExecType = TaskExecType.Running
                        };

                        session.Save(_status);
                        _recId = _status.Id;
                        var  keyPair = new KeyValuePair <int, CancellationToken>(_status.Id, _cancelTokSource.Token);
                        Task task    = null;
                        try
                        {
                            task = Task.Factory.StartNew(x =>
                            {
                                var key =
                                    (KeyValuePair <int, CancellationToken>)x;
                                if (!key.Value.IsCancellationRequested)
                                {
                                    var t = new Thread(DoWork);
                                    t.Start(key.Key);
                                    while (t.IsAlive &&
                                           !key.Value.IsCancellationRequested)
                                    {
                                    }
                                    if (t.IsAlive)
                                    {
                                        t.Abort();
                                    }
                                }
                            }, keyPair, _cancelTokSource.Token);
                            if (sheduler.IsKill && sheduler.Runtime.HasValue)
                            {
                                task.Wait(new TimeSpan(0, sheduler.Runtime.Value, 0));
                                if (task.IsCompleted && _cancelTokSource != null &&
                                    !_cancelTokSource.IsCancellationRequested)
                                {
                                    State = TaskExecutionType.Succeed;
                                }
                                else if (task.Status != TaskStatus.Canceled && task.Status != TaskStatus.RanToCompletion &&
                                         task.Status != TaskStatus.Faulted)
                                {
                                    _cancelTokSource.Cancel();
                                    State = TaskExecutionType.Failure;
                                }
                                else
                                {
                                    State = TaskExecutionType.Failure;
                                }
                            }
                            else
                            {
                                task.Wait();
                                if (task.IsCompleted && _cancelTokSource != null &&
                                    !_cancelTokSource.IsCancellationRequested)
                                {
                                    State = TaskExecutionType.Succeed;
                                }
                                else
                                {
                                    State = TaskExecutionType.Failure;
                                }
                            }
                            Task.WaitAll(new[] { task });
                            if (task.Status != TaskStatus.Canceled && task.Status != TaskStatus.RanToCompletion &&
                                task.Status != TaskStatus.Faulted)
                            {
                                task.Dispose();
                            }
                        }
                        catch (InvalidOperationException)
                        {
                            State = TaskExecutionType.Failure;
                            if (task != null)
                            {
                                Task.WaitAll(new[] { task });
                            }
                        }
                        catch (AggregateException)
                        {
                            State = TaskExecutionType.Failure;
                            if (task != null)
                            {
                                Task.WaitAll(new[] { task });
                            }
                        }
                        catch (OperationCanceledException)
                        {
                            State = TaskExecutionType.Failure;
                            if (task != null)
                            {
                                Task.WaitAll(new[] { task });
                            }
                        }
                        catch (ThreadAbortException)
                        {
                            State = TaskExecutionType.Failure;
                            Thread.ResetAbort();
                            if (task != null)
                            {
                                Task.WaitAll(new[] { task });
                            }
                        }
                        finally
                        {
                            if (task != null && task.Status != TaskStatus.RanToCompletion)
                            {
                                Task.WaitAll(new[] { task });
                                if (task.Status != TaskStatus.Canceled &&
                                    task.Status != TaskStatus.Faulted)
                                {
                                    task.Dispose();
                                }
                            }
                        }
                    }
                    catch
                    {
                        State = TaskExecutionType.Failure;
                    }

                    finally
                    {
                        if (sheduler != null)
                        {
                            if (_status != null)
                            {
                                session.Refresh(_status);
                                _status = session.Get <StatusTask>(_recId);
                                if (_status.TaskExecType != TaskExecType.Failure)
                                {
                                    _status.TaskExecType =
                                        (TaskExecType)Enum.Parse(typeof(TaskExecType), ((int)State).ToString());
                                    _status.EndRun = DateTime.Now;
                                    session.Save(_status);
                                }
                            }
                            sheduler.Duration = _heart.LastDuration;
                            sheduler.UpdateShedule();

                            DateTime?next = sheduler.NextRun;
                            arg.Interval = !next.HasValue
                                               ? -1
                                               : (long)next.Value.Subtract(DateTime.Now).TotalMilliseconds;
                            if (IsRemove)
                            {
                                arg.Interval = -1;
                            }
                            sheduler.IsEnabled = next.HasValue;
                            session.Save(sheduler);
                            session.Flush();
                            _cancelTokSource = null;
                            _status          = null;
                        }
                    }
                }
            }
        }
        public async Task <ResponseEntity> getProjectById(int?idProject)
        {
            var pro = await _projectRepository.GetSingleByConditionAsync("id", idProject);

            if (pro == null)
            {
                return(new ResponseEntity(StatusCodeConstants.NOT_FOUND, "Project is not found", MessageConstants.MESSAGE_ERROR_404));
            }


            var lstUser = _projectUserRepository.GetMultiByConditionAsync("projectId", idProject).Result;
            List <Repository.Models.Member> members = new List <Repository.Models.Member>();

            foreach (var item in lstUser)
            {
                var user = _userJira.GetSingleByConditionAsync("id", item.userId).Result;
                Repository.Models.Member mem = new Repository.Models.Member();
                mem.userId = user.id;
                mem.name   = user.name;

                mem.avatar = user.avatar;
                members.Add(mem);
            }

            ProjectCategory projectCategory = await _projectCategoryRepository.GetSingleByConditionAsync("id", pro.categoryId);

            ProjectDetail projectDetail = new ProjectDetail();

            projectDetail.alias           = pro.alias;
            projectDetail.projectName     = pro.projectName;
            projectDetail.projectCategory = new ProjectCategoryDetail()
            {
                id = projectCategory.id, name = projectCategory.projectCategoryName
            };
            projectDetail.description = FuncUtilities.Base64Decode(pro.description);
            projectDetail.id          = pro.id;
            projectDetail.projectName = pro.projectName;
            projectDetail.members     = members;
            CreatorModel creator = new CreatorModel();

            if (pro.id != null)
            {
                creator.id = pro.creator;

                creator.name = _userJira.GetSingleByIdAsync(pro.creator).Result.name;
            }

            projectDetail.creator = creator;

            //List<ProjectDetail> lstResult = new List<ProjectDetail>();
            var lstStatus = await _statusRepository.GetAllAsync();

            //Lấy list priority
            IEnumerable <Priority> lstPriority = await _priorityRepository.GetAllAsync();

            //Lấy list task
            var lstTask = await _taskRepository.GetAllAsync();

            foreach (var status in lstStatus)
            {
                var statusTask = new StatusTask {
                    statusId = status.statusId, statusName = status.statusName, alias = status.alias
                };

                List <TaskDetail> task = lstTask.Where(n => n.projectId == projectDetail.id && n.statusId == status.statusId).Select(n => new TaskDetail {
                    taskId = n.taskId, taskName = n.taskName, alias = n.alias, description = FuncUtilities.Base64Decode(n.description), statusId = n.statusId, priorityTask = getTaskPriority(n.priorityId, lstPriority), originalEstimate = n.originalEstimate, timeTrackingSpent = n.timeTrackingSpent, timeTrackingRemaining = n.timeTrackingRemaining, assigness = getListUserAsign(n.taskId).ToList(), taskTypeDetail = getTaskType(n.typeId), lstComment = getListComment(n.taskId).ToList(), projectId = n.projectId
                }).ToList();

                statusTask.lstTaskDeTail.AddRange(task);

                projectDetail.lstTask.Add(statusTask);
            }


            return(new ResponseEntity(StatusCodeConstants.OK, projectDetail, MessageConstants.MESSAGE_SUCCESS_200));
        }
Exemplo n.º 7
0
        public JsonResult SavaTaskManager(long id, string name, string date, string description, StatusTask status)
        {
            DateTime taskDate;

            DateTime.TryParse(date, out taskDate);
            if (id == 0)
            {
                var task = new TaskManager()
                {
                    Name        = name.Trim(),
                    Description = description.Trim(),
                    Status      = status,
                    TaskDate    = taskDate,
                    Deleted     = false,
                };
                _taskManagerService.Add(task);
                return(Json(task.Id));
            }
            else
            {
                var task = _taskManagerService.GetById(id);
                if (task != null)
                {
                    task.Name        = name.Trim();
                    task.Description = description.Trim();
                    task.Status      = status;
                    task.TaskDate    = taskDate;
                    task.UpdatedOn   = DateTime.Now;
                    _taskManagerService.Update(task);
                }
                return(Json(id));
            }
        }