Skip to content

Commit 05a507c

Browse files
committed
PR 69: Fixed Memory leaks +semver:minor
- Updated messages to make a valid package -semver:minor - Fixed Memory leaks +semver:minor - Merge branch 'master' Related work items: #4908
2 parents b406381 + edc928d commit 05a507c

File tree

7 files changed

+46
-75
lines changed

7 files changed

+46
-75
lines changed

TfsWitMigrator.Console/Chocolatey/chocolateyInstall.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ try {
99
}
1010

1111
Install-ChocolateyZipPackage 'vstssyncmigration' 'https://github.com/nkdAgility/vsts-sync-migration/releases/download/#{GITVERSION.FULLSEMVER}#/vstsbulkeditor-#{GITVERSION.FULLSEMVER}#.zip' $vstssyncmigrationpath
12-
1312
write-host 'VSTS Sync Migration has been installed. Call `vstssyncmigration` from the command line to see options. You may need to close and reopen the command shell.'
14-
Write-ChocolateySuccess 'vstssyncmigration'
1513
} catch {
16-
Write-ChocolateyFailure 'vstssyncmigration' $($_.Exception.Message)
1714
throw
1815
}

TfsWitMigrator.Console/Chocolatey/chocolateyUninstall.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ try {
66
Uninstall-ChocolateyZipPackage 'vstssyncmigration' 'vstsbulkeditor-#{GITVERSION.FULLSEMVER}#.zip'
77

88
write-host 'VSTS Sync Migration has been uninstalled.'
9-
Write-ChocolateySuccess 'vstssyncmigration'
109
} catch {
11-
Write-ChocolateyFailure 'vstssyncmigration' $($_.Exception.Message)
1210
throw
1311
}

TfsWitMigrator.Core/Execution/ComponentContext/WorkItemStoreContext.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public int GetReflectedWorkItemId(WorkItem wi, string reflectedWotkItemIdField)
6767

6868

6969

70-
public WorkItem FindReflectedWorkItem(WorkItem workItemToFind, string reflectedWotkItemIdField)
70+
public WorkItem FindReflectedWorkItem(WorkItem workItemToFind, string reflectedWotkItemIdField, bool cache)
7171
{
7272
string ReflectedWorkItemId = CreateReflectedWorkItemId(workItemToFind);
7373
WorkItem found = null;
@@ -98,11 +98,10 @@ public WorkItem FindReflectedWorkItem(WorkItem workItemToFind, string reflectedW
9898
if (found == null) { found = FindReflectedWorkItemByMigrationRef(ReflectedWorkItemId); } // Too slow!
9999
//if (found == null) { found = FindReflectedWorkItemByTitle(workItemToFind.Title); }
100100
}
101-
if (found != null)
101+
if (found != null && cache)
102102
{
103103
foundWis.Add(workItemToFind.Id, found); /// TODO MENORY LEEK! LEAK
104104
}
105-
106105
return found;
107106
}
108107

TfsWitMigrator.Core/Execution/MigrationContext/LinkMigrationContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal override void InternalExecute()
5252
{
5353
Trace.WriteLine(string.Format("Migrating Links for wiSourceL={0}",
5454
wiSourceL.Id), "LinkMigrationContext");
55-
WorkItem wiTargetL = targetWitsc.FindReflectedWorkItem(wiSourceL, me.ReflectedWorkItemIdFieldName);
55+
WorkItem wiTargetL = targetWitsc.FindReflectedWorkItem(wiSourceL, me.ReflectedWorkItemIdFieldName, true);
5656
if (wiTargetL == null)
5757
{
5858
//wiSourceL was not migrated, or the migrated work item has been deleted.
@@ -225,7 +225,7 @@ private WorkItem GetRightHandSideTargitWi(WorkItem wiSourceL, WorkItem wiSourceR
225225
else
226226
{
227227
// Moving to Other Team Project from SOurceR
228-
wiTargetR = targetStore.FindReflectedWorkItem(wiSourceR, me.ReflectedWorkItemIdFieldName);
228+
wiTargetR = targetStore.FindReflectedWorkItem(wiSourceR, me.ReflectedWorkItemIdFieldName, true);
229229
if (wiTargetR == null) // Assume source only (other team projkect)
230230
{
231231
wiTargetR = wiSourceR;

TfsWitMigrator.Core/Execution/MigrationContext/TestPlansAndSuitsMigrationContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private void ProcessChildTestCases(ITestSuiteBase source, ITestSuiteBase target,
143143
foreach (ITestSuiteEntry sourceTestCaseEntry in source.TestCases)
144144
{
145145
Trace.WriteLine(string.Format(" Processing {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites");
146-
WorkItem wi = targetWitStore.FindReflectedWorkItem(sourceTestCaseEntry.TestCase.WorkItem, me.ReflectedWorkItemIdFieldName);
146+
WorkItem wi = targetWitStore.FindReflectedWorkItem(sourceTestCaseEntry.TestCase.WorkItem, me.ReflectedWorkItemIdFieldName, false);
147147
if (wi == null)
148148
{
149149
Trace.WriteLine(string.Format(" ERROR NOT FOUND {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites");

TfsWitMigrator.Core/Execution/MigrationContext/WorkItemMigrationContext.cs

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class WorkItemMigrationContext : MigrationContextBase
1616

1717
WorkItemMigrationConfig _config;
1818
MigrationEngine _me;
19+
List<String> _ignore;
1920

2021
public override string Name
2122
{
@@ -29,6 +30,36 @@ public WorkItemMigrationContext(MigrationEngine me, WorkItemMigrationConfig conf
2930
{
3031
_me = me;
3132
_config = config;
33+
PopulateIgnoreList();
34+
}
35+
36+
private void PopulateIgnoreList()
37+
{
38+
_ignore = new List<string>();
39+
//ignore.Add("System.CreatedDate");
40+
//ignore.Add("System.CreatedBy");
41+
_ignore.Add("System.Rev");
42+
_ignore.Add("System.AreaId");
43+
_ignore.Add("System.IterationId");
44+
_ignore.Add("System.Id");
45+
//ignore.Add("System.ChangedDate");
46+
//ignore.Add("System.ChangedBy");
47+
_ignore.Add("System.RevisedDate");
48+
_ignore.Add("System.AttachedFileCount");
49+
_ignore.Add("System.TeamProject");
50+
_ignore.Add("System.NodeName");
51+
_ignore.Add("System.RelatedLinkCount");
52+
_ignore.Add("System.WorkItemType");
53+
_ignore.Add("Microsoft.VSTS.Common.ActivatedDate");
54+
_ignore.Add("Microsoft.VSTS.Common.StateChangeDate");
55+
_ignore.Add("System.ExternalLinkCount");
56+
_ignore.Add("System.HyperLinkCount");
57+
_ignore.Add("System.Watermark");
58+
_ignore.Add("System.AuthorizedDate");
59+
_ignore.Add("System.BoardColumn");
60+
_ignore.Add("System.BoardColumnDone");
61+
_ignore.Add("System.BoardLane");
62+
_ignore.Add("SLB.SWT.DateOfClientFeedback");
3263
}
3364

3465
internal override void InternalExecute()
@@ -55,7 +86,7 @@ internal override void InternalExecute()
5586
Stopwatch witstopwatch = new Stopwatch();
5687
witstopwatch.Start();
5788
WorkItem targetFound;
58-
targetFound = targetStore.FindReflectedWorkItem(sourceWI, me.ReflectedWorkItemIdFieldName);
89+
targetFound = targetStore.FindReflectedWorkItem(sourceWI, me.ReflectedWorkItemIdFieldName, false);
5990
Trace.WriteLine(string.Format("{0} - Migrating: {1}-{2}", current, sourceWI.Id, sourceWI.Type.Name), this.Name);
6091
if (targetFound == null)
6192
{
@@ -88,6 +119,7 @@ internal override void InternalExecute()
88119
if (_config.UpdateCreatedDate) { newwit.Fields["System.CreatedDate"].Value = sourceWI.Fields["System.CreatedDate"].Value; }
89120
if (_config.UpdateCreatedBy) { newwit.Fields["System.CreatedBy"].Value = sourceWI.Fields["System.CreatedBy"].Value; }
90121
newwit.Save();
122+
newwit.Close();
91123
Trace.WriteLine(string.Format("...Saved as {0}", newwit.Id), this.Name);
92124
if (sourceWI.Fields.Contains(me.ReflectedWorkItemIdFieldName) && _config.UpdateSoureReflectedId)
93125
{
@@ -116,13 +148,15 @@ internal override void InternalExecute()
116148
// sourceWI.Fields["TfsMigrationTool.ReflectedWorkItemId"].Value = destWIFound[0].Id;
117149
//sourceWI.Save();
118150
}
151+
sourceWI.Close();
119152
witstopwatch.Stop();
120153
elapsedms = elapsedms + witstopwatch.ElapsedMilliseconds;
121154
current--;
122155
count++;
123156
TimeSpan average = new TimeSpan(0, 0, 0, 0, (int)(elapsedms / count));
124157
TimeSpan remaining = new TimeSpan(0, 0, 0, 0, (int)(average.TotalMilliseconds * current));
125158
Trace.WriteLine(string.Format("Average time of {0} per work item and {1} estimated to completion", string.Format(@"{0:s\:fff} seconds", average), string.Format(@"{0:%h} hours {0:%m} minutes {0:s\:fff} seconds", remaining)), this.Name);
159+
Trace.Flush();
126160
}
127161
//////////////////////////////////////////////////
128162
stopwatch.Stop();
@@ -135,38 +169,14 @@ private static bool HasChildPBI(WorkItem sourceWI)
135169
return sourceWI.Title.ToLower().StartsWith("epic") || sourceWI.Title.ToLower().StartsWith("theme");
136170
}
137171

138-
private static WorkItem CreateAndPopulateWorkItem(WorkItemMigrationConfig config , WorkItem oldWi, Project destProject, String destType)
172+
private WorkItem CreateAndPopulateWorkItem(WorkItemMigrationConfig config , WorkItem oldWi, Project destProject, String destType)
139173
{
140174
var fieldMappingStartTime = DateTime.UtcNow;
141175
Stopwatch fieldMappingTimer = new Stopwatch();
142176

143177
bool except = false;
144178
Trace.Write("... Building", "WorkItemMigrationContext");
145-
List<String> ignore = new List<string>();
146-
ignore.Add("System.CreatedDate");
147-
ignore.Add("System.CreatedBy");
148-
ignore.Add("System.Rev");
149-
ignore.Add("System.AreaId");
150-
ignore.Add("System.IterationId");
151-
ignore.Add("System.Id");
152-
ignore.Add("System.ChangedDate");
153-
ignore.Add("System.ChangedBy");
154-
ignore.Add("System.RevisedDate");
155-
ignore.Add("System.AttachedFileCount");
156-
ignore.Add("System.TeamProject");
157-
ignore.Add("System.NodeName");
158-
ignore.Add("System.RelatedLinkCount");
159-
ignore.Add("System.WorkItemType");
160-
ignore.Add("Microsoft.VSTS.Common.ActivatedDate");
161-
ignore.Add("Microsoft.VSTS.Common.StateChangeDate");
162-
ignore.Add("System.ExternalLinkCount");
163-
ignore.Add("System.HyperLinkCount");
164-
ignore.Add("System.Watermark");
165-
ignore.Add("System.AuthorizedDate");
166-
ignore.Add("System.BoardColumn");
167-
ignore.Add("System.BoardColumnDone");
168-
ignore.Add("System.BoardLane");
169-
ignore.Add("SLB.SWT.DateOfClientFeedback");
179+
170180

171181

172182
// WorkItem newwit = oldWi.Copy(destProject.WorkItemTypes[destType]);
@@ -193,7 +203,7 @@ private static WorkItem CreateAndPopulateWorkItem(WorkItemMigrationConfig config
193203

194204
foreach (Field f in oldWi.Fields)
195205
{
196-
if (newwit.Fields.Contains(f.ReferenceName) && !ignore.Contains(f.ReferenceName))
206+
if (newwit.Fields.Contains(f.ReferenceName) && !_ignore.Contains(f.ReferenceName))
197207
{
198208
newwit.Fields[f.ReferenceName].Value = oldWi.Fields[f.ReferenceName].Value;
199209
}
@@ -211,6 +221,7 @@ private static WorkItem CreateAndPopulateWorkItem(WorkItemMigrationConfig config
211221

212222
newwit.Fields["System.ChangedDate"].Value = oldWi.Fields["System.ChangedDate"].Value;
213223

224+
214225
switch (destType)
215226
{
216227
case "Test Case":

TfsWitMigrator.Core/Execution/MigrationContext/WorkItemPostProcessingContext.cs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ internal override void InternalExecute()
7575
Stopwatch witstopwatch = new Stopwatch();
7676
witstopwatch.Start();
7777
WorkItem targetFound;
78-
targetFound = targetStore.FindReflectedWorkItem(sourceWI, me.ReflectedWorkItemIdFieldName);
78+
targetFound = targetStore.FindReflectedWorkItem(sourceWI, me.ReflectedWorkItemIdFieldName, false);
7979
Trace.WriteLine(string.Format("{0} - Updating: {1}-{2}", current, sourceWI.Id, sourceWI.Type.Name));
8080
if (targetFound == null)
8181
{
@@ -104,7 +104,7 @@ internal override void InternalExecute()
104104
{
105105
Trace.WriteLine(string.Format(" No changes"));
106106
}
107-
107+
sourceWI.Close();
108108
}
109109
witstopwatch.Stop();
110110
elapsedms = elapsedms + witstopwatch.ElapsedMilliseconds;
@@ -119,40 +119,6 @@ internal override void InternalExecute()
119119
Console.WriteLine(@"DONE in {0:%h} hours {0:%m} minutes {0:s\:fff} seconds", stopwatch.Elapsed);
120120
}
121121

122-
//TODO: Can be removed
123-
//private string CreateTypeOrIdContraints()
124-
//{
125-
// string idContraints = string.Empty;
126-
// if (_workItemIDs != null && _workItemIDs.Count > 0)
127-
// {
128-
// if (_workItemIDs.Count == 1)
129-
// {
130-
// idContraints = string.Format(" AND [System.Id] = {0} ", _workItemIDs[0]);
131-
// }
132-
// else
133-
// {
134-
// idContraints = string.Format(" AND [System.Id] IN ({0}) ", string.Join(",", _workItemIDs));
135-
// }
136-
// return idContraints;
137-
// }
138-
139-
// string typeConstraints = string.Empty;
140-
// if (_workItemTypes != null && _workItemTypes.Count > 0)
141-
// {
142-
// if (_workItemTypes.Count == 1)
143-
// {
144-
// typeConstraints = string.Format(" AND [System.WorkItemType] = '{0}' ", _workItemTypes[0]);
145-
// }
146-
// else
147-
// {
148-
// typeConstraints = string.Format(" AND [System.WorkItemType] IN ('{0}') ", string.Join("','", _workItemTypes));
149-
// }
150-
// return typeConstraints;
151-
// }
152-
153-
// return string.Empty;
154-
//}
155-
156122
private string CreateConstraints()
157123
{
158124
if (_workItemIDs != null && _workItemIDs.Count > 0)

0 commit comments

Comments
 (0)