Skip to content

Commit

Permalink
PR 69: Fixed Memory leaks +semver:minor
Browse files Browse the repository at this point in the history
 - Updated messages to make a valid package -semver:minor
 - Fixed Memory leaks +semver:minor
 - Merge branch 'master'

Related work items: #4908
  • Loading branch information
MrHinsh committed Oct 18, 2016
2 parents b406381 + edc928d commit 05a507c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 75 deletions.
3 changes: 0 additions & 3 deletions TfsWitMigrator.Console/Chocolatey/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ try {
}

Install-ChocolateyZipPackage 'vstssyncmigration' 'https://github.com/nkdAgility/vsts-sync-migration/releases/download/#{GITVERSION.FULLSEMVER}#/vstsbulkeditor-#{GITVERSION.FULLSEMVER}#.zip' $vstssyncmigrationpath

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.'
Write-ChocolateySuccess 'vstssyncmigration'
} catch {
Write-ChocolateyFailure 'vstssyncmigration' $($_.Exception.Message)
throw
}
2 changes: 0 additions & 2 deletions TfsWitMigrator.Console/Chocolatey/chocolateyUninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ try {
Uninstall-ChocolateyZipPackage 'vstssyncmigration' 'vstsbulkeditor-#{GITVERSION.FULLSEMVER}#.zip'

write-host 'VSTS Sync Migration has been uninstalled.'
Write-ChocolateySuccess 'vstssyncmigration'
} catch {
Write-ChocolateyFailure 'vstssyncmigration' $($_.Exception.Message)
throw
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public int GetReflectedWorkItemId(WorkItem wi, string reflectedWotkItemIdField)



public WorkItem FindReflectedWorkItem(WorkItem workItemToFind, string reflectedWotkItemIdField)
public WorkItem FindReflectedWorkItem(WorkItem workItemToFind, string reflectedWotkItemIdField, bool cache)
{
string ReflectedWorkItemId = CreateReflectedWorkItemId(workItemToFind);
WorkItem found = null;
Expand Down Expand Up @@ -98,11 +98,10 @@ public WorkItem FindReflectedWorkItem(WorkItem workItemToFind, string reflectedW
if (found == null) { found = FindReflectedWorkItemByMigrationRef(ReflectedWorkItemId); } // Too slow!
//if (found == null) { found = FindReflectedWorkItemByTitle(workItemToFind.Title); }
}
if (found != null)
if (found != null && cache)
{
foundWis.Add(workItemToFind.Id, found); /// TODO MENORY LEEK! LEAK
}

return found;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal override void InternalExecute()
{
Trace.WriteLine(string.Format("Migrating Links for wiSourceL={0}",
wiSourceL.Id), "LinkMigrationContext");
WorkItem wiTargetL = targetWitsc.FindReflectedWorkItem(wiSourceL, me.ReflectedWorkItemIdFieldName);
WorkItem wiTargetL = targetWitsc.FindReflectedWorkItem(wiSourceL, me.ReflectedWorkItemIdFieldName, true);
if (wiTargetL == null)
{
//wiSourceL was not migrated, or the migrated work item has been deleted.
Expand Down Expand Up @@ -225,7 +225,7 @@ private WorkItem GetRightHandSideTargitWi(WorkItem wiSourceL, WorkItem wiSourceR
else
{
// Moving to Other Team Project from SOurceR
wiTargetR = targetStore.FindReflectedWorkItem(wiSourceR, me.ReflectedWorkItemIdFieldName);
wiTargetR = targetStore.FindReflectedWorkItem(wiSourceR, me.ReflectedWorkItemIdFieldName, true);
if (wiTargetR == null) // Assume source only (other team projkect)
{
wiTargetR = wiSourceR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private void ProcessChildTestCases(ITestSuiteBase source, ITestSuiteBase target,
foreach (ITestSuiteEntry sourceTestCaseEntry in source.TestCases)
{
Trace.WriteLine(string.Format(" Processing {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites");
WorkItem wi = targetWitStore.FindReflectedWorkItem(sourceTestCaseEntry.TestCase.WorkItem, me.ReflectedWorkItemIdFieldName);
WorkItem wi = targetWitStore.FindReflectedWorkItem(sourceTestCaseEntry.TestCase.WorkItem, me.ReflectedWorkItemIdFieldName, false);
if (wi == null)
{
Trace.WriteLine(string.Format(" ERROR NOT FOUND {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class WorkItemMigrationContext : MigrationContextBase

WorkItemMigrationConfig _config;
MigrationEngine _me;
List<String> _ignore;

public override string Name
{
Expand All @@ -29,6 +30,36 @@ public WorkItemMigrationContext(MigrationEngine me, WorkItemMigrationConfig conf
{
_me = me;
_config = config;
PopulateIgnoreList();
}

private void PopulateIgnoreList()
{
_ignore = new List<string>();
//ignore.Add("System.CreatedDate");
//ignore.Add("System.CreatedBy");
_ignore.Add("System.Rev");
_ignore.Add("System.AreaId");
_ignore.Add("System.IterationId");
_ignore.Add("System.Id");
//ignore.Add("System.ChangedDate");
//ignore.Add("System.ChangedBy");
_ignore.Add("System.RevisedDate");
_ignore.Add("System.AttachedFileCount");
_ignore.Add("System.TeamProject");
_ignore.Add("System.NodeName");
_ignore.Add("System.RelatedLinkCount");
_ignore.Add("System.WorkItemType");
_ignore.Add("Microsoft.VSTS.Common.ActivatedDate");
_ignore.Add("Microsoft.VSTS.Common.StateChangeDate");
_ignore.Add("System.ExternalLinkCount");
_ignore.Add("System.HyperLinkCount");
_ignore.Add("System.Watermark");
_ignore.Add("System.AuthorizedDate");
_ignore.Add("System.BoardColumn");
_ignore.Add("System.BoardColumnDone");
_ignore.Add("System.BoardLane");
_ignore.Add("SLB.SWT.DateOfClientFeedback");
}

internal override void InternalExecute()
Expand All @@ -55,7 +86,7 @@ internal override void InternalExecute()
Stopwatch witstopwatch = new Stopwatch();
witstopwatch.Start();
WorkItem targetFound;
targetFound = targetStore.FindReflectedWorkItem(sourceWI, me.ReflectedWorkItemIdFieldName);
targetFound = targetStore.FindReflectedWorkItem(sourceWI, me.ReflectedWorkItemIdFieldName, false);
Trace.WriteLine(string.Format("{0} - Migrating: {1}-{2}", current, sourceWI.Id, sourceWI.Type.Name), this.Name);
if (targetFound == null)
{
Expand Down Expand Up @@ -88,6 +119,7 @@ internal override void InternalExecute()
if (_config.UpdateCreatedDate) { newwit.Fields["System.CreatedDate"].Value = sourceWI.Fields["System.CreatedDate"].Value; }
if (_config.UpdateCreatedBy) { newwit.Fields["System.CreatedBy"].Value = sourceWI.Fields["System.CreatedBy"].Value; }
newwit.Save();
newwit.Close();
Trace.WriteLine(string.Format("...Saved as {0}", newwit.Id), this.Name);
if (sourceWI.Fields.Contains(me.ReflectedWorkItemIdFieldName) && _config.UpdateSoureReflectedId)
{
Expand Down Expand Up @@ -116,13 +148,15 @@ internal override void InternalExecute()
// sourceWI.Fields["TfsMigrationTool.ReflectedWorkItemId"].Value = destWIFound[0].Id;
//sourceWI.Save();
}
sourceWI.Close();
witstopwatch.Stop();
elapsedms = elapsedms + witstopwatch.ElapsedMilliseconds;
current--;
count++;
TimeSpan average = new TimeSpan(0, 0, 0, 0, (int)(elapsedms / count));
TimeSpan remaining = new TimeSpan(0, 0, 0, 0, (int)(average.TotalMilliseconds * current));
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);
Trace.Flush();
}
//////////////////////////////////////////////////
stopwatch.Stop();
Expand All @@ -135,38 +169,14 @@ private static bool HasChildPBI(WorkItem sourceWI)
return sourceWI.Title.ToLower().StartsWith("epic") || sourceWI.Title.ToLower().StartsWith("theme");
}

private static WorkItem CreateAndPopulateWorkItem(WorkItemMigrationConfig config , WorkItem oldWi, Project destProject, String destType)
private WorkItem CreateAndPopulateWorkItem(WorkItemMigrationConfig config , WorkItem oldWi, Project destProject, String destType)
{
var fieldMappingStartTime = DateTime.UtcNow;
Stopwatch fieldMappingTimer = new Stopwatch();

bool except = false;
Trace.Write("... Building", "WorkItemMigrationContext");
List<String> ignore = new List<string>();
ignore.Add("System.CreatedDate");
ignore.Add("System.CreatedBy");
ignore.Add("System.Rev");
ignore.Add("System.AreaId");
ignore.Add("System.IterationId");
ignore.Add("System.Id");
ignore.Add("System.ChangedDate");
ignore.Add("System.ChangedBy");
ignore.Add("System.RevisedDate");
ignore.Add("System.AttachedFileCount");
ignore.Add("System.TeamProject");
ignore.Add("System.NodeName");
ignore.Add("System.RelatedLinkCount");
ignore.Add("System.WorkItemType");
ignore.Add("Microsoft.VSTS.Common.ActivatedDate");
ignore.Add("Microsoft.VSTS.Common.StateChangeDate");
ignore.Add("System.ExternalLinkCount");
ignore.Add("System.HyperLinkCount");
ignore.Add("System.Watermark");
ignore.Add("System.AuthorizedDate");
ignore.Add("System.BoardColumn");
ignore.Add("System.BoardColumnDone");
ignore.Add("System.BoardLane");
ignore.Add("SLB.SWT.DateOfClientFeedback");



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

foreach (Field f in oldWi.Fields)
{
if (newwit.Fields.Contains(f.ReferenceName) && !ignore.Contains(f.ReferenceName))
if (newwit.Fields.Contains(f.ReferenceName) && !_ignore.Contains(f.ReferenceName))
{
newwit.Fields[f.ReferenceName].Value = oldWi.Fields[f.ReferenceName].Value;
}
Expand All @@ -211,6 +221,7 @@ private static WorkItem CreateAndPopulateWorkItem(WorkItemMigrationConfig config

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


switch (destType)
{
case "Test Case":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal override void InternalExecute()
Stopwatch witstopwatch = new Stopwatch();
witstopwatch.Start();
WorkItem targetFound;
targetFound = targetStore.FindReflectedWorkItem(sourceWI, me.ReflectedWorkItemIdFieldName);
targetFound = targetStore.FindReflectedWorkItem(sourceWI, me.ReflectedWorkItemIdFieldName, false);
Trace.WriteLine(string.Format("{0} - Updating: {1}-{2}", current, sourceWI.Id, sourceWI.Type.Name));
if (targetFound == null)
{
Expand Down Expand Up @@ -104,7 +104,7 @@ internal override void InternalExecute()
{
Trace.WriteLine(string.Format(" No changes"));
}

sourceWI.Close();
}
witstopwatch.Stop();
elapsedms = elapsedms + witstopwatch.ElapsedMilliseconds;
Expand All @@ -119,40 +119,6 @@ internal override void InternalExecute()
Console.WriteLine(@"DONE in {0:%h} hours {0:%m} minutes {0:s\:fff} seconds", stopwatch.Elapsed);
}

//TODO: Can be removed
//private string CreateTypeOrIdContraints()
//{
// string idContraints = string.Empty;
// if (_workItemIDs != null && _workItemIDs.Count > 0)
// {
// if (_workItemIDs.Count == 1)
// {
// idContraints = string.Format(" AND [System.Id] = {0} ", _workItemIDs[0]);
// }
// else
// {
// idContraints = string.Format(" AND [System.Id] IN ({0}) ", string.Join(",", _workItemIDs));
// }
// return idContraints;
// }

// string typeConstraints = string.Empty;
// if (_workItemTypes != null && _workItemTypes.Count > 0)
// {
// if (_workItemTypes.Count == 1)
// {
// typeConstraints = string.Format(" AND [System.WorkItemType] = '{0}' ", _workItemTypes[0]);
// }
// else
// {
// typeConstraints = string.Format(" AND [System.WorkItemType] IN ('{0}') ", string.Join("','", _workItemTypes));
// }
// return typeConstraints;
// }

// return string.Empty;
//}

private string CreateConstraints()
{
if (_workItemIDs != null && _workItemIDs.Count > 0)
Expand Down

0 comments on commit 05a507c

Please sign in to comment.