-
Notifications
You must be signed in to change notification settings - Fork 4
/
TaskHelper.cs
106 lines (95 loc) · 3.68 KB
/
TaskHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HPMSdk;
namespace Hansoft.ObjectWrapper
{
internal static class TaskHelper
{
internal static bool HasChildren(HPMUniqueID uniqueID)
{
// Work around for SDK bug in TaskRefUtilHasChildren when uniqueID is the product backlog
return Session.TaskRefUtilEnumChildren(uniqueID, false).m_Tasks.Length >0 ;
}
internal static List<HansoftItem> GetChildren(HPMUniqueID uniqueID, bool deep)
{
List<HansoftItem> children = new List<HansoftItem>();
if (HasChildren(uniqueID))
{
HPMTaskEnum tasks = Session.TaskRefUtilEnumChildren(uniqueID, deep);
foreach (HPMUniqueID id in tasks.m_Tasks)
children.Add(Task.GetTask(id));
}
return children;
}
internal static List<HansoftItem> GetChildren(HPMUniqueID uniqueID)
{
return GetChildren(uniqueID, false);
}
internal static List<HansoftItem> GetDeepChildren(HPMUniqueID uniqueID)
{
return GetChildren(uniqueID, true);
}
internal static string AssignedAsString(Task task)
{
StringBuilder sb = new StringBuilder();
HPMTaskResourceAllocationResource[] allocations = SessionManager.Session.TaskGetResourceAllocation(task.UniqueTaskID).m_Resources;
for (int i = 0; i < allocations.Length; i += 1)
{
HPMUniqueID resourceId = allocations[i].m_ResourceID;
int percentage = allocations[i].m_PercentAllocated;
sb.Append(User.GetUser(resourceId).Name);
if (percentage != 100)
{
sb.Append('[');
sb.Append(percentage.ToString());
sb.Append("]");
}
if (i < allocations.Length - 1)
sb.Append(", ");
}
return sb.ToString();
}
private static HPMSdkSession Session
{
get
{
return SessionManager.Session;
}
}
internal static Sprint GetCommittedToSprint(Task task)
{
HPMUniqueID uid = Session.TaskGetLinkedToSprint(task.UniqueTaskID);
if (uid.m_ID != -1)
return (Sprint) Task.GetTask(uid);
else
return null;
}
internal static List<User> GetAssignees(Task task)
{
List<User> assignees = new List<User>();
HPMTaskResourceAllocationResource[] allocations = Session.TaskGetResourceAllocation(task.UniqueTaskID).m_Resources;
foreach (HPMTaskResourceAllocationResource ra in allocations)
assignees.Add(User.GetUser(ra.m_ResourceID));
return assignees;
}
internal static int GetAssignmentPercentage(Task task, User user)
{
HPMTaskResourceAllocationResource[] allocations = Session.TaskGetResourceAllocation(task.UniqueTaskID).m_Resources;
foreach (HPMTaskResourceAllocationResource ra in allocations)
if (ra.m_ResourceID.m_ID == user.UniqueID.m_ID)
return ra.m_PercentAllocated;
return 0;
}
internal static bool IsAssigned(Task task)
{
HPMTaskResourceAllocationResource[] allocations = Session.TaskGetResourceAllocation(task.UniqueTaskID).m_Resources;
if (allocations.Length == 0)
return false;
else
return (allocations[0].m_ResourceID.m_ID != -1);
}
}
}