Skip to content

Commit

Permalink
PR 41: Merge addDocs to master
Browse files Browse the repository at this point in the history
 - Added migrator for teams
 - Added Documentation with mkdocs
  • Loading branch information
MrHinsh committed Aug 16, 2016
1 parent 36cc85a commit 20b91f2
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VSTS.DataBulkEditor.Engine.Configuration.Processing
{
public class TeamMigrationConfig : ITfsProcessingConfig
{
public bool Enabled { get; set; }
public Type Processor
{
get
{
return typeof(TeamMigrationContext);
}
}

}
}

136 changes: 136 additions & 0 deletions TfsWitMigrator.Core/Execution/MigrationContext/TeamMigrationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.ProcessConfiguration.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using VSTS.DataBulkEditor.Engine.Configuration.Processing;

namespace VSTS.DataBulkEditor.Engine
{
public class TeamMigrationContext : MigrationContextBase
{

TeamMigrationConfig _config;
MigrationEngine _me;

public override string Name
{
get
{
return "TeamMigrationContext";
}
}

public TeamMigrationContext(MigrationEngine me, TeamMigrationConfig config) : base(me, config)
{
_me = me;
_config = config;
}

internal override void InternalExecute()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
//////////////////////////////////////////////////
WorkItemStoreContext sourceStore = new WorkItemStoreContext(me.Source, WorkItemStoreFlags.BypassRules);
TfsTeamService sourceTS = me.Source.Collection.GetService<TfsTeamService>();
List<TeamFoundationTeam> sourceTL = sourceTS.QueryTeams(me.Source.Name).ToList();
Trace.WriteLine(string.Format("Found {0} teams in Source?", sourceTL.Count));
var sourceTSCS = me.Source.Collection.GetService<TeamSettingsConfigurationService>();
//////////////////////////////////////////////////
WorkItemStoreContext targetStore = new WorkItemStoreContext(me.Target, WorkItemStoreFlags.BypassRules);
Project targetProject = targetStore.GetProject();
Trace.WriteLine(string.Format("Found target project as {0}", targetProject.Name));
TfsTeamService targetTS = me.Target.Collection.GetService<TfsTeamService>();
List<TeamFoundationTeam> targetTL = targetTS.QueryTeams(me.Target.Name).ToList();
Trace.WriteLine(string.Format("Found {0} teams in Target?", targetTL.Count));
var targetTSCS = me.Target.Collection.GetService<TeamSettingsConfigurationService>();
//////////////////////////////////////////////////
int current = sourceTL.Count;
int count = 0;
long elapsedms = 0;

/// Create teams
///
foreach (TeamFoundationTeam sourceTeam in sourceTL)
{
Stopwatch witstopwatch = new Stopwatch();
witstopwatch.Start();
var foundTargetTeam = (from x in targetTL where x.Name == sourceTeam.Name select x).SingleOrDefault();
if (foundTargetTeam == null)
{
Trace.WriteLine(string.Format("Processing team {0}", sourceTeam.Name));
TeamFoundationTeam newTeam = targetTS.CreateTeam(targetProject.Uri.ToString(), sourceTeam.Name, sourceTeam.Description, null);
}
else
{
Trace.WriteLine(string.Format("Team found.. skipping"));
}

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("");
//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)));
}
// Set Team Settings
//foreach (TeamFoundationTeam sourceTeam in sourceTL)
//{
// Stopwatch witstopwatch = new Stopwatch();
// witstopwatch.Start();
// var foundTargetTeam = (from x in targetTL where x.Name == sourceTeam.Name select x).SingleOrDefault();
// if (foundTargetTeam == null)
// {
// Trace.WriteLine(string.Format("Processing team {0}", sourceTeam.Name));
// var sourceTCfU = sourceTSCS.GetTeamConfigurations((new[] { sourceTeam.Identity.TeamFoundationId })).SingleOrDefault();
// TeamSettings newTeamSettings = CreateTargetTeamSettings(sourceTCfU);
// TeamFoundationTeam newTeam = targetTS.CreateTeam(targetProject.Uri.ToString(), sourceTeam.Name, sourceTeam.Description, null);
// targetTSCS.SetTeamSettings(newTeam.Identity.TeamFoundationId, newTeamSettings);
// }
// else
// {
// Trace.WriteLine(string.Format("Team found.. skipping"));
// }

// 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("");
// //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)));

//}
//////////////////////////////////////////////////
stopwatch.Stop();
Console.WriteLine(@"DONE in {0:%h} hours {0:%m} minutes {0:s\:fff} seconds", stopwatch.Elapsed);
}


private TeamSettings CreateTargetTeamSettings(TeamConfiguration sourceTCfU)
{
///////////////////////////////////////////////////
TeamSettings newTeamSettings = sourceTCfU.TeamSettings;
newTeamSettings.BacklogIterationPath = newTeamSettings.BacklogIterationPath.Replace(me.Source.Name, me.Target.Name);
List<string> newIterationPaths = new List<string>();
foreach (var ip in newTeamSettings.IterationPaths)
{
newIterationPaths.Add(ip.Replace(me.Source.Name, me.Target.Name));
}
newTeamSettings.IterationPaths = newIterationPaths.ToArray();

///////////////////////////////////////////////////
return newTeamSettings;
}
}
}
2 changes: 2 additions & 0 deletions TfsWitMigrator.Core/_VSTS.DataBulkEditor.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
<Compile Include="Configuration\FieldMap\FieldValueMapConfig.cs" />
<Compile Include="Configuration\FieldMap\IFieldMapConfig.cs" />
<Compile Include="Configuration\JsonCreationConverter.cs" />
<Compile Include="Configuration\Processing\TeamMigrationConfig.cs" />
<Compile Include="Configuration\Processing\WorkItemUpdateAreasAsTagsConfig.cs" />
<Compile Include="Configuration\Processing\FakeProcessorConfig.cs" />
<Compile Include="Configuration\Processing\ExportProfilePictureFromADConfig.cs" />
Expand Down Expand Up @@ -302,6 +303,7 @@
<Compile Include="Execution\MigrationContext\TestRunsMigrationContext.cs" />
<Compile Include="Execution\MigrationContext\TestVeriablesMigrationContext.cs" />
<Compile Include="Execution\MigrationContext\FakeProcessor.cs" />
<Compile Include="Execution\MigrationContext\TeamMigrationContext.cs" />
<Compile Include="Execution\MigrationContext\WorkItemPostProcessingContext.cs" />
<Compile Include="Execution\ProcessingContext\ExportTeamList.cs" />
<Compile Include="Execution\ProcessingContext\FixGitCommitLinks.cs" />
Expand Down
17 changes: 17 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Welcome to MkDocs

For full documentation visit [mkdocs.org](http://mkdocs.org).

## Commands

* `mkdocs new [dir-name]` - Create a new project.
* `mkdocs serve` - Start the live-reloading docs server.
* `mkdocs build` - Build the documentation site.
* `mkdocs help` - Print this help message.

## Project layout

mkdocs.yml # The configuration file.
docs/
index.md # The documentation homepage.
... # Other markdown pages, images and other files.
4 changes: 4 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
site_name: VSTS Data Bulk Editor
pages:
- Home: index.md
theme: readthedocs

0 comments on commit 20b91f2

Please sign in to comment.