Skip to content

Commit 710e6f5

Browse files
committed
PR 71: Merge Preview to master +semver:major
- Updated exe name to vsts-sm to make it easyer to call and remember +semver:major - Added new Field type to match a bunch of values and then update a bunch of - Fix bugabo...
2 parents 8f880f8 + 6a22062 commit 710e6f5

File tree

7 files changed

+120
-5
lines changed

7 files changed

+120
-5
lines changed

TfsWitMigrator.Console/Chocolatey/chocolateyInstall.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ try {
77
Remove-Item "$($vstssyncmigrationpath)\*" -recurse -force
88
}
99

10-
Install-ChocolateyZipPackage 'vstssyncmigration' 'https://github.com/nkdAgility/vsts-sync-migration/releases/download/#{GITVERSION.FULLSEMVER}#/vstsbulkeditor-#{GITVERSION.FULLSEMVER}#.zip' $vstssyncmigrationpath
11-
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.'
10+
Install-ChocolateyZipPackage 'vsts-sm' 'https://github.com/nkdAgility/vsts-sync-migration/releases/download/#{GITVERSION.FULLSEMVER}#/vstsbulkeditor-#{GITVERSION.FULLSEMVER}#.zip' $vstssyncmigrationpath
11+
write-host 'VSTS Sync Migration has been installed. Call `vsts-sm` from the command line to see options. You may need to close and reopen the command shell.'
1212
} catch {
1313
throw
1414
}

TfsWitMigrator.Console/Chocolatey/chocolateyUninstall.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ try {
22
$toolsLoc = Get-ToolsLocation
33
$vstssyncmigrationpath =Join-Path -Path $toolsLoc -ChildPath "\VSTSSyncMigration"
44

5-
Uninstall-ChocolateyZipPackage 'vstssyncmigration' 'vstsbulkeditor-#{GITVERSION.FULLSEMVER}#.zip'
5+
Uninstall-ChocolateyZipPackage 'vsts-sm' 'vstsbulkeditor-#{GITVERSION.FULLSEMVER}#.zip'
66

77
write-host 'VSTS Sync Migration has been uninstalled.'
88
} catch {

TfsWitMigrator.Console/VSTS.DataBulkEditor.Console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<OutputType>Exe</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>VSTS.DataBulkEditor.ConsoleApp</RootNamespace>
11-
<AssemblyName>vstsbulkeditor</AssemblyName>
11+
<AssemblyName>vsts-sm</AssemblyName>
1212
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<NuGetPackageImportStamp>

TfsWitMigrator.Core/Configuration/EngineConfiguration.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,24 @@ public static EngineConfiguration GetDefault()
2727
ec.Target = new TeamProjectConfig() { Name = "DemoProjt", Collection = new Uri("https://sdd2016.visualstudio.com/") };
2828
ec.ReflectedWorkItemIDFieldName = "TfsMigrationTool.ReflectedWorkItemId";
2929
ec.FieldMaps = new List<IFieldMapConfig>();
30-
ec.FieldMaps.Add(new FieldBlankMapConfig() { WorkItemTypeName = "*", targetField = "TfsMigrationTool.ReflectedWorkItemId" });
30+
ec.FieldMaps.Add(new MultiValueConditionalMapConfig()
31+
{
32+
WorkItemTypeName = "*",
33+
sourceFieldsAndValues = new Dictionary<string, string>
34+
{
35+
{ "Field1", "Value1" },
36+
{ "Field2", "Value2" }
37+
},
38+
targetFieldsAndValues = new Dictionary<string, string>
39+
{
40+
{ "Field1", "Value1" },
41+
{ "Field2", "Value2" }
42+
}
43+
});
44+
ec.FieldMaps.Add(new FieldBlankMapConfig() {
45+
WorkItemTypeName = "*",
46+
targetField = "TfsMigrationTool.ReflectedWorkItemId"
47+
});
3148
ec.FieldMaps.Add(new FieldValueMapConfig()
3249
{
3350
WorkItemTypeName = "*",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using VSTS.DataBulkEditor.Engine.ComponentContext;
7+
8+
namespace VSTS.DataBulkEditor.Engine.Configuration.FieldMap
9+
{
10+
public class MultiValueConditionalMapConfig : IFieldMapConfig
11+
{
12+
public string WorkItemTypeName { get; set; }
13+
public Dictionary<string,string> sourceFieldsAndValues { get; set; }
14+
public Dictionary<string, string> targetFieldsAndValues { get; set; }
15+
public Type FieldMap
16+
{
17+
get
18+
{
19+
return typeof(MultiValueConditionalMap);
20+
}
21+
}
22+
}
23+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.TeamFoundation.WorkItemTracking.Client;
7+
using System.Diagnostics;
8+
using Microsoft.ApplicationInsights;
9+
using VSTS.DataBulkEditor.Engine.Configuration.FieldMap;
10+
11+
namespace VSTS.DataBulkEditor.Engine.ComponentContext
12+
{
13+
public class MultiValueConditionalMap : FieldMapBase
14+
{
15+
private MultiValueConditionalMapConfig config;
16+
17+
public MultiValueConditionalMap(MultiValueConditionalMapConfig config)
18+
{
19+
this.config = config;
20+
}
21+
22+
internal override void InternalExecute(WorkItem source, WorkItem target)
23+
{
24+
if (fieldsExist(config.sourceFieldsAndValues, source) && fieldsExist(config.targetFieldsAndValues, target))
25+
{
26+
if (fieldsValueMatch(config.sourceFieldsAndValues, source))
27+
{
28+
fieldsUpdate(config.targetFieldsAndValues, target);
29+
}
30+
Trace.WriteLine(string.Format(" [UPDATE] field mapped {0}:{1} to {2}:{3}", source.Id, config.sourceFieldsAndValues.Keys.ToString(), target.Id, config.targetFieldsAndValues.Keys.ToString()));
31+
} else
32+
{
33+
Trace.WriteLine(string.Format(" [SKIPPED] Not all source and target fields exist", source.Id, config.sourceFieldsAndValues.Keys.ToString(), target.Id, config.targetFieldsAndValues.Keys.ToString()));
34+
}
35+
}
36+
37+
private void fieldsUpdate(Dictionary<string, string> fieldAndValues, WorkItem workitem)
38+
{
39+
foreach (string field in fieldAndValues.Keys)
40+
{
41+
workitem.Fields[field].Value = fieldAndValues[field];
42+
}
43+
}
44+
45+
private bool fieldsValueMatch(Dictionary<string, string> fieldAndValues, WorkItem workitem)
46+
{
47+
bool matches = true;
48+
foreach (string field in fieldAndValues.Keys)
49+
{
50+
if((string)workitem.Fields[field].Value != fieldAndValues[field])
51+
{
52+
matches = false;
53+
}
54+
}
55+
return matches;
56+
}
57+
58+
private bool fieldsExist(Dictionary<string, string> fieldsAndValues, WorkItem workitem)
59+
{
60+
bool exists = true;
61+
foreach (string field in fieldsAndValues.Keys)
62+
{
63+
if (!workitem.Fields.Contains(field))
64+
{
65+
exists = false;
66+
}
67+
}
68+
return exists;
69+
}
70+
71+
72+
}
73+
}

TfsWitMigrator.Core/_VSTS.DataBulkEditor.Engine.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@
258258
<Compile Include="Configuration\EngineConfiguration.cs" />
259259
<Compile Include="Configuration\FieldMap\FieldMapConfigJsonConverter.cs" />
260260
<Compile Include="Configuration\FieldMap\FieldBlankMapConfig.cs" />
261+
<Compile Include="Configuration\FieldMap\MultiValueConditionalMapConfig.cs" />
261262
<Compile Include="Configuration\FieldMap\FieldValuetoTagMapConfig.cs" />
262263
<Compile Include="Configuration\FieldMap\TreeToTagMapConfig.cs" />
263264
<Compile Include="Configuration\FieldMap\FieldMergeMapConfig.cs" />
@@ -293,6 +294,7 @@
293294
<Compile Include="Execution\FieldMaps\FieldMergeMap.cs" />
294295
<Compile Include="Execution\FieldMaps\FieldBlankMap.cs" />
295296
<Compile Include="Execution\FieldMaps\FieldToFieldMap.cs" />
297+
<Compile Include="Execution\FieldMaps\MultiValueConditionalMap.cs" />
296298
<Compile Include="Execution\FieldMaps\FieldValuetoTagMap.cs" />
297299
<Compile Include="Execution\FieldMaps\FieldValueMap.cs" />
298300
<Compile Include="Execution\FieldMaps\IFieldMap.cs" />

0 commit comments

Comments
 (0)