internal void FillBlockerInfo(
			DataGridViewRow blockerRow,
			WorkItem blocker,
			Dictionary<int, string> planningAssignments)
        {
            blockerRow.Cells[m_viewColumnsIndexes.IdColumnIndex].Value = m_blockersPrefix;
            blockerRow.Cells[m_viewColumnsIndexes.DocsColumnIndex].Value = blocker.Type.Name;
            blockerRow.Cells[m_viewColumnsIndexes.TitleColumnIndex].Value = blocker.Id + " " + blocker.Title;
            blockerRow.Cells[m_viewColumnsIndexes.BlockersColumnIndex].Value = blocker.State;
            blockerRow.Cells[m_viewColumnsIndexes.AssignedToColumnIndex].Value = planningAssignments.GetAssignee(blocker);
            blockerRow.Visible = false;
        }
        internal void FillTaskInfo(
			ViewFiltersBuilder viewFiltersBuilder,
			WorkItem task,
			List<WorkItem> siblings,
			WorkItem leadTask,
			DataGridViewRow taskRow,
			DataContainer data,
			Dictionary<int, string> planningAssignments,
			List<string> allUsers,
			List<int> blockerIds)
        {
            var priorityCell = taskRow.Cells[m_viewColumnsIndexes.PriorityColumnIndex];
            priorityCell.Value = task.Priority();
            priorityCell.SetColorByState(task);
            priorityCell.ToolTipText = task.State;

            var idCell = taskRow.Cells[m_viewColumnsIndexes.IdColumnIndex];
            idCell.Value = task.Id;
            var verificationResult = WorkItemVerifier.VerifyTaskPriority(task, leadTask.Priority());
            if (verificationResult.Result != VerificationResult.Ok)
            {
                idCell.SetColorByVerification(verificationResult.Result);
                idCell.ToolTipText = verificationResult.AllMessagesString;
            }
            else
            {
                verificationResult = WorkItemVerifier.VerifyTaskWithParentOnSameIteration(task, leadTask);
                if (verificationResult.Result != VerificationResult.Ok)
                {
                    idCell.SetColorByVerification(verificationResult.Result);
                    idCell.ToolTipText = verificationResult.AllMessagesString;
                }
            }

            var titleCell = taskRow.Cells[m_viewColumnsIndexes.TitleColumnIndex];
            titleCell.Value = task.Title;
            titleCell.ToolTipText = task.Discipline() + " " + task.Title;
            titleCell.Style.BackColor = priorityCell.Style.BackColor;

            var blockersCell = taskRow.Cells[m_viewColumnsIndexes.BlockersColumnIndex];
            if (blockerIds != null)
            {
                string blockerIdsStr = string.Join(",", blockerIds);
                blockersCell.Value = blockerIdsStr;

                verificationResult = WorkItemVerifier.VerifyNonChildBlockerExistance(blockerIds, siblings);
                if (verificationResult.Result == VerificationResult.Ok)
                    verificationResult = WorkItemVerifier.VerifyActiveTaskBlocking(task, blockerIds);
                if (verificationResult.Result == VerificationResult.Ok)
                {
                    blockerIdsStr = string.Join(Environment.NewLine, blockerIds.Select(b => data.WiDict[b].Title));
                    blockersCell.ToolTipText = blockerIdsStr;
                }
                else
                {
                    blockersCell.SetColorByVerification(verificationResult.Result);
                    blockersCell.ToolTipText = verificationResult.AllMessagesString;
                }
            }
            if (!string.IsNullOrEmpty(task.BlockingReason()))
            {
                if (!string.IsNullOrEmpty(blockersCell.ToolTipText))
                    blockersCell.ToolTipText += Environment.NewLine;
                else
                    blockersCell.Value = task.BlockingReason();
                blockersCell.ToolTipText += "Blocking Reason: " + task.BlockingReason();
            }

            var assignedCell = taskRow.Cells[m_viewColumnsIndexes.AssignedToColumnIndex];
            var comboBoxCell = assignedCell as DataGridViewComboBoxCell;
            if (comboBoxCell != null)
                comboBoxCell.DataSource = allUsers;
            assignedCell.Value = planningAssignments.GetAssignee(task);
            verificationResult = WorkItemVerifier.VerifyAssignation(task);
            if (verificationResult.Result != VerificationResult.Ok)
            {

                assignedCell.SetColorByVerification(verificationResult.Result);
                assignedCell.ToolTipText = verificationResult.AllMessagesString;
            }

            var workCell = taskRow.Cells[m_viewColumnsIndexes.WorkColumnIndex];
            workCell.Value = task.IsActive()
                ? task.Remaining()
                : task.Estimate();
            workCell.Style.BackColor = priorityCell.Style.BackColor;
        }
        private static void AppendBlockedTasks(
			IEnumerable<Tuple<WorkItem, WorkItem>> blockedTasks,
			List<Tuple<Tuple<WorkItem, WorkItem>, int>> schedule,
			DataContainer dataContainer,
			Dictionary<int, string> planningAssignments,
			FocusFactorCalculator focusFactorCalculator,
			Dictionary<int, Tuple<int?, int>> scheduledTasksDict,
			Dictionary<string, HashSet<int>> usersBlockers)
        {
            var comparer = new TaskPriorityComparer();
            foreach (var tuple in blockedTasks)
            {
                WorkItem blockedTask = tuple.Item1;
                var finishData = GetFinishDateForBlockedTask(
                    blockedTask,
                    dataContainer,
                    planningAssignments,
                    focusFactorCalculator,
                    scheduledTasksDict);
                if (finishData.Item1 == null)
                {
                    schedule.Add(new Tuple<Tuple<WorkItem, WorkItem>, int>(tuple, 0));
                }
                else
                {
                    double? remaining = tuple.Item1.IsActive()
                        ? blockedTask.Remaining()
                        : blockedTask.Estimate();
                    int taskDaysCount = remaining == null
                        ? 0
                        : focusFactorCalculator.CalculateDaysByTime(
                            remaining.Value,
                            planningAssignments.GetAssignee(tuple.Item1));
                    int startDay = 0;
                    bool added = false;
                    for (int i = 0; i < schedule.Count; i++)
                    {
                        var taskData = schedule[i];
                        if (taskData.Item1.Item1.IsActive())
                            continue;
                        if (startDay > finishData.Item1.Value && comparer.Compare(tuple, taskData.Item1) < 0)
                        {
                            schedule.Insert(i, new Tuple<Tuple<WorkItem, WorkItem>, int>(tuple, taskDaysCount));
                            added = true;
                            break;
                        }
                        startDay += taskData.Item1.Item1.IsActive()
                            ? Math.Max(taskData.Item2 - startDay, 0)
                            : taskData.Item2;
                    }
                    if (!added)
                        schedule.Add(new Tuple<Tuple<WorkItem, WorkItem>, int>(tuple, taskDaysCount));
                }

                foreach (var userBlockersPair in finishData.Item2)
                {
                    HashSet<int> blockers;
                    if (usersBlockers.ContainsKey(userBlockersPair.Key))
                    {
                        blockers = usersBlockers[userBlockersPair.Key];
                    }
                    else
                    {
                        blockers = new HashSet<int>();
                        usersBlockers.Add(userBlockersPair.Key, blockers);
                    }
                    foreach (int blockerId in userBlockersPair.Value)
                    {
                        blockers.Add(blockerId);
                    }
                }
            }
        }
        private static Dictionary<string, List<Tuple<WorkItem, WorkItem>>> SeparateByUser(
			DataContainer dataContainer,
			Dictionary<int, string> planningAssignments)
        {
            var result = new Dictionary<string, List<Tuple<WorkItem, WorkItem>>>();
            foreach (var ltChildrenPair in dataContainer.LeadTaskChildrenDict)
            {
                WorkItem lt = dataContainer.WiDict[ltChildrenPair.Key];
                foreach (int childId in ltChildrenPair.Value)
                {
                    WorkItem child = dataContainer.WiDict[childId];
                    string assignee = planningAssignments.GetAssignee(child);
                    var childTuple = new Tuple<WorkItem, WorkItem>(child, lt);
                    if (!result.ContainsKey(assignee))
                        result.Add(assignee, new List<Tuple<WorkItem, WorkItem>> { childTuple });
                    else
                        result[assignee].Add(childTuple);
                }
            }
            return result;
        }
        private static int? GetFinishDay(
			WorkItem task,
			Dictionary<int, string> planningAssignments,
			FocusFactorCalculator focusFactorCalculator,
			Dictionary<int, Tuple<int?, int>> scheduledTasksDict)
        {
            int? result = null;
            if (scheduledTasksDict.ContainsKey(task.Id))
            {
                var blockerSchedule = scheduledTasksDict[task.Id];
                if (blockerSchedule.Item1 != null)
                    result = blockerSchedule.Item1.Value + blockerSchedule.Item2;
            }
            else
            {
                double? remaining = task.IsProposed()
                    ? task.Estimate()
                    : task.Remaining();
                if (remaining != null)
                    result = focusFactorCalculator.CalculateDaysByTime(
                        remaining.Value,
                        planningAssignments.GetAssignee(task));
            }
            return result;
        }
        private static Tuple<int?, Dictionary<string, HashSet<int>>> GetFinishDateForBlockedTask(
			WorkItem blockedTask,
			DataContainer dataContainer,
			Dictionary<int, string> planningAssignments,
			FocusFactorCalculator focusFactorCalculator,
			Dictionary<int, Tuple<int?, int>> scheduledTasksDict)
        {
            int? finish = GetFinishDay(
                blockedTask,
                planningAssignments,
                focusFactorCalculator,
                scheduledTasksDict);

            Dictionary<string, HashSet<int>> userBlockersDict;

            if (dataContainer.BlockersDict.ContainsKey(blockedTask.Id))
            {
                userBlockersDict = new Dictionary<string, HashSet<int>>();
                foreach (int blockerId in dataContainer.BlockersDict[blockedTask.Id])
                {
                    WorkItem blocker = dataContainer.WiDict[blockerId];
                    var blockerData = GetFinishDateForBlockedTask(
                        blocker,
                        dataContainer,
                        planningAssignments,
                        focusFactorCalculator,
                        scheduledTasksDict);

                    int? currentFinish = GetFinishDay(
                        blocker,
                        planningAssignments,
                        focusFactorCalculator,
                        scheduledTasksDict);
                    currentFinish = MaxDay(currentFinish, blockerData.Item1);
                    finish = MaxDay(finish, currentFinish);

                    foreach (var blockerAssignData in blockerData.Item2)
                    {
                        if (!userBlockersDict.ContainsKey(blockerAssignData.Key))
                            userBlockersDict.Add(blockerAssignData.Key, new HashSet<int>());
                        var ids = userBlockersDict[blockerAssignData.Key];
                        foreach (int parentBlockerId in blockerAssignData.Value)
                        {
                            ids.Add(parentBlockerId);
                        }
                    }

                    string blockerAssignee = planningAssignments.GetAssignee(blocker);
                    if (userBlockersDict.ContainsKey(blockerAssignee))
                        userBlockersDict[blockerAssignee].Add(blockerId);
                    else
                        userBlockersDict.Add(blockerAssignee, new HashSet<int> {blockerId});
                }
            }
            else
            {
                userBlockersDict = new Dictionary<string, HashSet<int>>(0);
            }

            var result = new Tuple<int?, Dictionary<string, HashSet<int>>>(finish, userBlockersDict);

            return result;
        }
Example #7
0
        internal static int AddTaskRow(
			DataGridView dgv,
			ViewFiltersBuilder viewFiltersBuilder,
			WorkItemInfoFiller workItemInfoFiller,
			ViewColumnsIndexes viewColumnsIndexes,
			FreeDaysCalculator freeDaysCalculator,
			FocusFactorCalculator focusFactorCalculator,
			WorkItem task,
			List<WorkItem> siblings,
			WorkItem leadTask,
			DataContainer data,
			Dictionary<int, string> planningAssignments,
			List<string> allUsers,
			Dictionary<int, int> alreadyAdded,
			Dictionary<string, int> tasksByUser,
			Dictionary<int, Tuple<int?, int>> tasksSchedule)
        {
            if (alreadyAdded.ContainsKey(task.Id))
                return viewColumnsIndexes.FirstDateColumnIndex;

            var nextInds = new List<int>();

            List<int> blockerIds = ProcessBlockers(
                dgv,
                viewFiltersBuilder,
                workItemInfoFiller,
                viewColumnsIndexes,
                freeDaysCalculator,
                focusFactorCalculator,
                data,
                planningAssignments,
                allUsers,
                task,
                siblings,
                leadTask,
                alreadyAdded,
                nextInds,
                tasksByUser,
                tasksSchedule);

            dgv.Rows.Add(new DataGridViewRow());
            var taskRow = dgv.Rows[dgv.Rows.Count - 1];

            workItemInfoFiller.FillTaskInfo(
                viewFiltersBuilder,
                task,
                siblings,
                leadTask,
                taskRow,
                data,
                planningAssignments,
                allUsers,
                blockerIds);

            viewFiltersBuilder.MarkTaskRow(taskRow);

            if (blockerIds != null)
                foreach (int blockerId in blockerIds)
                {
                    AddBlockerRow(
                        dgv,
                        viewFiltersBuilder,
                        workItemInfoFiller,
                        data,
                        planningAssignments,
                        blockerId);
                }

            if (task.IsResolved())
            {
                alreadyAdded.Add(task.Id, viewColumnsIndexes.FirstDateColumnIndex);
                return viewColumnsIndexes.FirstDateColumnIndex;
            }

            string assignedTo = planningAssignments.GetAssignee(task);
            if (!assignedTo.IsUnassigned() && tasksByUser.ContainsKey(assignedTo))
                nextInds.Add(tasksByUser[assignedTo]);

            int maxNextInd = viewColumnsIndexes.FirstDateColumnIndex;
            if (nextInds.Count > 0)
                maxNextInd = nextInds.Max();

            string userMark = GetUserMark(assignedTo);

            Tuple<int?, int> taskSchedule = null;
            int nextInd;

            if (tasksSchedule != null && tasksSchedule.ContainsKey(task.Id))
                taskSchedule = tasksSchedule[task.Id];

            if (taskSchedule != null && taskSchedule.Item1 != null)
            {
                nextInd = ScheduleFiller.AddDatesFromSchedule(
                    viewColumnsIndexes,
                    freeDaysCalculator,
                    taskRow,
                    taskSchedule.Item1.Value,
                    taskSchedule.Item2,
                    assignedTo,
                    userMark);
            }
            else
            {
                nextInd = task.IsProposed()
                    ? ScheduleFiller.AddDatesProposed(
                        viewColumnsIndexes,
                        freeDaysCalculator,
                        focusFactorCalculator,
                        task,
                        taskRow,
                        maxNextInd,
                        assignedTo,
                        userMark,
                        true)
                    : ScheduleFiller.AddDatesActive(
                        viewColumnsIndexes,
                        freeDaysCalculator,
                        focusFactorCalculator,
                        task,
                        taskRow,
                        maxNextInd,
                        assignedTo,
                        userMark);
            }
            alreadyAdded.Add(task.Id, nextInd);
            tasksByUser[assignedTo] = nextInd;
            return nextInd;
        }