-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultValueBehavior.cs
179 lines (163 loc) · 7.87 KB
/
DefaultValueBehavior.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using HPMSdk;
using Hansoft.Jean.Behavior;
using Hansoft.ObjectWrapper;
namespace Hansoft.Jean.Behavior.DefaultValueBehavior
{
public class DefaultValueBehavior : AbstractBehavior
{
// TODO: Consider to add default (or simply a hash with additional attributes), perhaps by sending in a string array of attributes
// to the general ColumnDefinition class (to be...) in the behavior namespace.
class ColumnDefault
{
private bool isCustomColumn;
private string defaultValue;
private string customColumnName;
private HPMProjectCustomColumnsColumn customColumn;
private EHPMProjectDefaultColumn defaultColumnType;
internal ColumnDefault(bool isCustomColumn, string customColumnName, EHPMProjectDefaultColumn defaultColumnType, string defaultValue )
{
this.isCustomColumn = isCustomColumn;
this.customColumnName = customColumnName;
this.defaultColumnType = defaultColumnType;
this.defaultValue = defaultValue;
}
internal void Initialize(ProjectView projectView)
{
if (isCustomColumn)
{
customColumn = projectView.GetCustomColumn(customColumnName);
if (customColumn == null)
throw new ArgumentException("Could not find custom column:" + customColumnName);
}
}
internal void Apply(Task task)
{
if (isCustomColumn)
task.SetCustomColumnValue(customColumn, defaultValue);
else
{
task.SetDefaultColumnValue(defaultColumnType, defaultValue);
}
}
}
private string projectName;
private EHPMReportViewType viewType;
private Project project;
private ProjectView projectView;
private List<ColumnDefault> columnDefaults;
string title;
public DefaultValueBehavior(XmlElement configuration)
: base(configuration)
{
projectName = GetParameter("HansoftProject");
columnDefaults = GetColumnDefaults(configuration);
viewType = GetViewType(GetParameter("View"));
title = "DefaultValueBehavior: " + configuration.InnerText;
}
public override string Title
{
get { return title; }
}
// TODO: Subject to refactoting
private List<ColumnDefault> GetColumnDefaults(XmlElement parent)
{
List<ColumnDefault> columnDefaults = new List<ColumnDefault>();
foreach (XmlNode node in parent.ChildNodes)
{
if (node is XmlElement)
{
XmlElement el = (XmlElement)node;
switch (el.Name)
{
case ("CustomColumn"):
columnDefaults.Add(new ColumnDefault(true, el.GetAttribute("Name"), EHPMProjectDefaultColumn.NewVersionOfSDKRequired, el.GetAttribute("DefaultValue")));
break;
case ("Risk"):
columnDefaults.Add(new ColumnDefault(false, null, EHPMProjectDefaultColumn.Risk, el.GetAttribute("DefaultValue")));
break;
case ("Priority"):
columnDefaults.Add(new ColumnDefault(false, null, EHPMProjectDefaultColumn.BacklogPriority, el.GetAttribute("DefaultValue")));
break;
case ("EstimatedDays"):
columnDefaults.Add(new ColumnDefault(false, null, EHPMProjectDefaultColumn.EstimatedIdealDays, el.GetAttribute("DefaultValue")));
break;
case ("Category"):
columnDefaults.Add(new ColumnDefault(false, null, EHPMProjectDefaultColumn.BacklogCategory, el.GetAttribute("DefaultValue")));
break;
case ("Points"):
columnDefaults.Add(new ColumnDefault(false, null, EHPMProjectDefaultColumn.ComplexityPoints, el.GetAttribute("DefaultValue")));
break;
case ("Status"):
columnDefaults.Add(new ColumnDefault(false, null, EHPMProjectDefaultColumn.ItemStatus, el.GetAttribute("DefaultValue")));
break;
case ("Confidence"):
columnDefaults.Add(new ColumnDefault(false, null, EHPMProjectDefaultColumn.Confidence, el.GetAttribute("DefaultValue")));
break;
case ("Hyperlink"):
columnDefaults.Add(new ColumnDefault(false, null, EHPMProjectDefaultColumn.Hyperlink, el.GetAttribute("DefaultValue")));
break;
case ("Name"):
columnDefaults.Add(new ColumnDefault(false, null, EHPMProjectDefaultColumn.ItemName, el.GetAttribute("DefaultValue")));
break;
case ("WorkRemaining"):
columnDefaults.Add(new ColumnDefault(false, null, EHPMProjectDefaultColumn.WorkRemaining, el.GetAttribute("DefaultValue")));
break;
default:
throw new ArgumentException("Unknown column type specified in Default Value behavior : " + el.Name);
}
}
}
return columnDefaults;
}
// TODO: Subject to refactoting
private EHPMReportViewType GetViewType(string viewType)
{
switch (viewType)
{
case ("Agile"):
return EHPMReportViewType.AgileMainProject;
case ("Scheduled"):
return EHPMReportViewType.ScheduleMainProject;
case ("Bugs"):
return EHPMReportViewType.AllBugsInProject;
case ("Backlog"):
return EHPMReportViewType.AgileBacklog;
default:
throw new ArgumentException("Unsupported View Type: " + viewType);
}
}
public override void Initialize()
{
project = HPMUtilities.FindProject(projectName);
if (project == null)
throw new ArgumentException("Could not find project:" + projectName);
if (viewType == EHPMReportViewType.AgileBacklog)
projectView = project.ProductBacklog;
else if (viewType == EHPMReportViewType.AllBugsInProject)
projectView = project.BugTracker;
foreach (ColumnDefault columnDefault in columnDefaults)
columnDefault.Initialize(projectView);
}
private void DoSetDefault(HPMChangeCallbackData_TaskCreateUnifiedTask[] createdTasks)
{
foreach (HPMChangeCallbackData_TaskCreateUnifiedTask createdTask in createdTasks)
{
Task task = Task.GetTask(createdTask.m_TaskRefID);
// We should not set the default when a proxy item is created as this would overwrite the values on the underlying backlog item.
if (!(task is ProductBacklogItemInSchedule) && !(task is ProductBacklogItemInSprint))
foreach (ColumnDefault columnDefault in columnDefaults)
columnDefault.Apply(task);
}
}
public override void OnTaskCreate(TaskCreateEventArgs e)
{
if (e.Data.m_ProjectID.m_ID == projectView.Id)
DoSetDefault(e.Data.m_Tasks);
}
}
}