-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmWizard.cs
203 lines (184 loc) · 4.98 KB
/
frmWizard.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using PIVOTAL_API;
using PivotalTFS_GENERAL;
using TFS_API.TFS;
using Project = PivotalTFS_GENERAL.Project;
namespace PivotalTFSSync
{
public partial class frmWizard : Form
{
private readonly IList<Panel> wizardsteps;
private int currentStepIndex;
public frmWizard()
{
InitializeComponent();
wizardsteps = new List<Panel>
{
pnlStep_PivotalLogin,
pnlStep_PivotalDetails,
pnlStep_TFSLogins,
pnlStep_TFSDetails,
pnlStep_Summary
};
currentStepIndex = 0;
InitializeAndShowStep(wizardsteps[currentStepIndex]);
}
private void btnNext_Click(object sender, EventArgs e)
{
MoveNext();
}
private void MoveNext()
{
if (currentStepIndex < wizardsteps.Count)
{
currentStepIndex++;
InitializeAndShowStep(wizardsteps[currentStepIndex]);
}
else
{
SyncCheckedItems();
MessageBox.Show("Done!", "Sync completed.");
}
}
private void SyncCheckedItems()
{
Cursor = Cursors.WaitCursor;
var currentPriority = int.Parse(txtStartPriority.Text);
var priorityStep = int.Parse(txtPriorityStep.Text);
ITFS tfs = new TFS(txtTFSServerURL.Text, txtDomain.Text, txtTFSUsername.Text,
txtTFSPassword.Text);
var projectname =
((Microsoft.TeamFoundation.WorkItemTracking.Client.Project) cboTFSProjects.SelectedItem).Name;
foreach (var story in from TreeNode node in tvwDetails.Nodes where node.Checked select (Story) node.Tag)
{
story.Priority = currentPriority;
tfs.AddPivotalStoryToTFS(story, projectname, ((Node) cboTFSIterations.SelectedItem).Name,
((Node) cboTFSSubPath.SelectedItem).Name, null, true);
currentPriority = currentPriority + priorityStep;
}
Cursor = Cursors.Arrow;
}
private void InitializeAndShowStep(Control wizardstep)
{
wizardstep.SetBounds(0, 0, pnlMain.Width, pnlMain.Height);
HideAllSteps();
btnNext.Text = "&Next";
switch (wizardstep.Name)
{
case "pnlStep_PivotalLogin":
{
break;
}
case "pnlStep_PivotalDetails":
{
PopulatePivotalIterationsCombo();
PopulatePivotalProjectsCombo();
break;
}
case "pnlStep_TFSLogins":
{
break;
}
case "pnlStep_TFSDetails":
{
PopulateTfsIterationsCombo(cboTFSProjects.SelectedText);
break;
}
case "pnlStep_Summary":
{
btnNext.Text = "&Finish";
break;
}
}
wizardstep.Show();
}
private void PopulateTfsIterationsCombo(string projectname)
{
try
{
ITFS tfs = new TFS(txtTFSServerURL.Text, txtDomain.Text, txtTFSUsername.Text,
txtTFSPassword.Text);
cboTFSIterations.DataSource = tfs.GetIterationPaths(projectname);
cboTFSIterations.DisplayMember = "Name";
}
catch (Exception exception)
{
//LogError(exception);
}
}
private void PopulatePivotalProjectsCombo()
{
IPivotal p = new Pivotal(txtStep_PivotalUsername.Text, txtStep_PiovtalPassword.Text);
cboPivotalProjects.DataSource = p.GetAllProjects();
cboPivotalProjects.DisplayMember = "Name";
}
private void PopulatePivotalIterationsCombo()
{
cboPivotalIteration.Items.Clear();
cboPivotalIteration.Items.Add(Pivotal.IterationVersion.All);
cboPivotalIteration.Items.Add(Pivotal.IterationVersion.Backlog);
cboPivotalIteration.Items.Add(Pivotal.IterationVersion.Current);
cboPivotalIteration.Items.Add(Pivotal.IterationVersion.Done);
}
private void HideAllSteps()
{
foreach (var step in wizardsteps)
{
step.Hide();
}
}
private void cboPivotalIteration_DropDownClosed(object sender, EventArgs e)
{
var stories = GetPivotalStories();
PopulateTreeview(stories);
}
private Story[] GetPivotalStories()
{
Cursor = Cursors.WaitCursor;
IPivotal p = new Pivotal(txtStep_PivotalUsername.Text, txtStep_PiovtalPassword.Text);
try
{
var iterations = p.GetIteration((Project) cboPivotalProjects.SelectedItem,
((Pivotal.IterationVersion) cboPivotalIteration.SelectedItem));
return iterations.First().Stories.stories;
}
catch (Exception ex)
{
//LogError(ex);
}
Cursor = Cursors.Arrow;
return new Story[] {};
}
private void PopulateTreeview(IEnumerable<Story> stories)
{
tvwDetails.Nodes.Clear();
foreach (var story in stories)
{
var key = story.Id.ToString(CultureInfo.InvariantCulture);
var node = tvwDetails.Nodes.Add(key, story.Name, story.Type);
node.Tag = story;
if (story.Description.Trim().Length > 0)
{
node.Nodes.Add(string.Concat(key, "-2"), story.Description.Trim(), "empty");
}
}
}
private void btnPrev_Click(object sender, EventArgs e)
{
MovePrevious();
}
private void MovePrevious()
{
if (currentStepIndex > 0)
{
currentStepIndex--;
InitializeAndShowStep(wizardsteps[currentStepIndex]);
}
}
}
}