public List <TeamMemberCapacityIdentityRef> ReplaceTeamMemberCapacities() { VssConnection connection = Context.Connection; WorkHttpClient workClient = connection.GetClient <WorkHttpClient>(); Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; TeamContext teamContext = new TeamContext(projectId, teamId); List <TeamSettingsIteration> result = workClient.GetTeamIterationsAsync(teamContext, "current").Result; Guid iterationId = result[0].Id; List <TeamMemberCapacityIdentityRef> capacity = workClient.GetCapacitiesWithIdentityRefAsync(teamContext, iterationId).Result; var updatedCapacity = capacity.Select(teamMemberCapacity => { return(new TeamMemberCapacityIdentityRef() { TeamMember = teamMemberCapacity.TeamMember, Activities = teamMemberCapacity.Activities.Select(a => { return new Activity() { Name = a.Name, CapacityPerDay = a.CapacityPerDay }; }), DaysOff = teamMemberCapacity.DaysOff }); }); var updatedCapacityResult = workClient.ReplaceCapacitiesWithIdentityRefAsync(updatedCapacity, teamContext, iterationId).Result; return(updatedCapacityResult); }
private TeamSettingsIteration GetCurrentIteration(Project project, TeamFoundationIdentity teamId, WorkHttpClient client) { var iterations = client.GetTeamIterationsAsync(new TeamContext(project.Name)).Result; return(iterations.FirstOrDefault(x => x.IsCurrent())); }
public TeamMemberCapacityIdentityRef UpdateTeamMemberCapacity() { VssConnection connection = Context.Connection; WorkHttpClient workClient = connection.GetClient <WorkHttpClient>(); Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; Guid userId = ClientSampleHelpers.GetCurrentUserId(this.Context); TeamContext teamContext = new TeamContext(projectId, teamId); List <TeamSettingsIteration> result = workClient.GetTeamIterationsAsync(teamContext, "current").Result; Guid iterationId = result[0].Id; TeamMemberCapacityIdentityRef capacity = workClient.GetCapacityWithIdentityRefAsync(teamContext, iterationId, userId).Result; CapacityPatch capacityPatch = new CapacityPatch() { Activities = capacity.Activities.Select(a => { return(new Activity { Name = a.Name, CapacityPerDay = a.CapacityPerDay + 1 }); }), DaysOff = capacity.DaysOff }; TeamMemberCapacityIdentityRef updatedCapacity = workClient.UpdateCapacityWithIdentityRefAsync(capacityPatch, teamContext, iterationId, userId).Result; return(updatedCapacity); }
/// <summary> /// Gets all iteration paths for the project with the given <paramref name="projectName"/> /// </summary> public async Task <IEnumerable <string> > GetIterations(string projectName) { var project = await _projectClient.GetProject(projectName); if (project == null) { return(new List <string>()); } var iterations = await _workClient.GetTeamIterationsAsync(new TeamContext(project.Name, project.DefaultTeam.Name)); return(iterations.Select(i => i.Path)); }
private async Task <string> GetCurrentIterationName() { using (WorkHttpClient workHttpClient = new WorkHttpClient(_uri, credentials)) { List <TeamSettingsIteration> iteration = await workHttpClient.GetTeamIterationsAsync(new TeamContext(_project), timeframe : "current"); if (iteration.Count != 1) { throw new ApplicationException($"There was an error fetching iterations for the project. Found {iteration.Count} iteration. Need exactly 1 iteration."); } string iterationName = iteration.First().Name; return(iterationName); } }
/// <summary> /// Get Team Iterations /// </summary> /// <param name="TeamProjectName"></param> /// <param name="TeamName"></param> static void GetTeamIterations(string TeamProjectName, string TeamName) { Console.WriteLine("==========Get Team Iterations"); TeamContext teamContext = new TeamContext(TeamProjectName, TeamName); Console.WriteLine("Iterations of the team " + TeamName); TeamSettingsIteration currentiteration = (WorkClient.GetTeamIterationsAsync(teamContext, "Current").Result).FirstOrDefault(); // get a current iteration if (currentiteration != null) { Console.WriteLine("Current iteration - {0} : {1}-{2}", currentiteration.Name, currentiteration.Attributes.StartDate, currentiteration.Attributes.FinishDate); } List <TeamSettingsIteration> teamIterations = WorkClient.GetTeamIterationsAsync(teamContext).Result; //get all iterations Console.WriteLine("Team Iterations: "); foreach (TeamSettingsIteration teamIteration in teamIterations) { Console.WriteLine("{0} : {1} : {2}-{3}", teamIteration.Attributes.TimeFrame, teamIteration.Name, teamIteration.Attributes.StartDate, teamIteration.Attributes.FinishDate); } }
public List <TeamMemberCapacityIdentityRef> GetTeamCapacity() { VssConnection connection = Context.Connection; WorkHttpClient workClient = connection.GetClient <WorkHttpClient>(); Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; TeamContext teamContext = new TeamContext(projectId, teamId); List <TeamSettingsIteration> result = workClient.GetTeamIterationsAsync(teamContext, "current").Result; Guid iterationId = result[0].Id; List <TeamMemberCapacityIdentityRef> capacity = workClient.GetCapacitiesWithIdentityRefAsync(teamContext, iterationId).Result; return(capacity); }
/// <summary> /// Returns the current iteration of the given team context /// </summary> /// <param name="conn">connection information to query iteration of</param> /// <returns>current iteration, or null if operation fails or user is not connected to AzureDevOps</returns> internal string GetIteration(ConnectionInfo conn) { if (!ConnectedToAzureDevOps) { return(null); } WorkHttpClient client = _baseServerConnection.GetClient <WorkHttpClient>(); #pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler return(client.GetTeamIterationsAsync(new TeamContext(conn.Project.Id, conn.Team?.Id), "current").ContinueWith(task => { // Can fail if there is no current iteration return task.IsFaulted ? null : task.Result.FirstOrDefault().Path; }).Result); #pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler }
public async void GetIterationsMethod() { Iterations.Clear(); if (SelectedTeamProject == null) { return; } Status = "Getting iterations for team project " + SelectedTeamProject.Name; WorkHttpClient workClient = ConnectionManager.Instance.GetClient <WorkHttpClient>(); var allIterations = await workClient.GetTeamIterationsAsync(new TeamContext(SelectedTeamProject.Id)); foreach (var iteration in allIterations) { Iterations.Add(new IterationsViewModel(iteration)); } Status = "All iteration loaded"; }
public List <TeamSettingsIteration> GetTeamSettingsCurrentIteration() { VssConnection connection = Context.Connection; WorkHttpClient workClient = connection.GetClient <WorkHttpClient>(); Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; var context = new TeamContext(projectId, teamId); List <TeamSettingsIteration> result = workClient.GetTeamIterationsAsync(context, "current").Result; foreach (var item in result) { Console.WriteLine("Current Iteration: {0}", item.Name); Console.WriteLine("Start Date: {0}", item.Attributes.StartDate.ToString()); Console.WriteLine("Finish Date: {0}", item.Attributes.FinishDate.ToString()); } return(result); }
private void MigrateCapacities(WorkHttpClient sourceHttpClient, WorkHttpClient targetHttpClient, TeamFoundationTeam sourceTeam, TeamFoundationTeam targetTeam, Dictionary <string, string> iterationMap) { if (!_Options.MigrateTeamCapacities) { return; } Log.LogInformation("Migrating team capacities.."); try { var sourceTeamContext = new TeamContext(Source.TfsProject.Guid, sourceTeam.Identity.TeamFoundationId); var sourceIterations = sourceHttpClient.GetTeamIterationsAsync(sourceTeamContext).ConfigureAwait(false).GetAwaiter().GetResult(); var targetTeamContext = new TeamContext(Target.TfsProject.Guid, targetTeam.Identity.TeamFoundationId); var targetIterations = targetHttpClient.GetTeamIterationsAsync(targetTeamContext).ConfigureAwait(false).GetAwaiter().GetResult(); foreach (var sourceIteration in sourceIterations) { try { var targetIterationPath = iterationMap[sourceIteration.Path]; var targetIteration = targetIterations.FirstOrDefault(i => i.Path == targetIterationPath); if (targetIteration == null) { continue; } var targetCapacities = new List <TeamMemberCapacityIdentityRef>(); var sourceCapacities = sourceHttpClient.GetCapacitiesWithIdentityRefAsync(sourceTeamContext, sourceIteration.Id).ConfigureAwait(false).GetAwaiter().GetResult(); foreach (var sourceCapacity in sourceCapacities) { var sourceDisplayName = sourceCapacity.TeamMember.DisplayName; var index = sourceDisplayName.IndexOf("<"); if (index > 0) { sourceDisplayName = sourceDisplayName.Substring(0, index).Trim(); } var targetTeamFoundatationIdentity = _targetTeamFoundationIdentitiesLazyCache.Value.FirstOrDefault(i => i.DisplayName == sourceDisplayName); if (targetTeamFoundatationIdentity != null) { targetCapacities.Add(new TeamMemberCapacityIdentityRef { Activities = sourceCapacity.Activities, DaysOff = sourceCapacity.DaysOff, TeamMember = new IdentityRef { Id = targetTeamFoundatationIdentity.TeamFoundationId.ToString() } }); } else { Log.LogWarning("[SKIP] Team Member {member} was not found on target when replacing capacities on iteration {iteration}.", sourceCapacity.TeamMember.DisplayName, targetIteration.Path); } } if (targetCapacities.Count > 0) { targetHttpClient.ReplaceCapacitiesWithIdentityRefAsync(targetCapacities, targetTeamContext, targetIteration.Id).ConfigureAwait(false).GetAwaiter().GetResult(); Log.LogDebug("Team {team} capacities for iteration {iteration} migrated.", targetTeam.Name, targetIteration.Path); } } catch (Exception ex) { Log.LogError(ex, "[SKIP] Problem migrating team capacities for iteration {iteration}.", sourceIteration.Path); } } } catch (Exception ex) { Log.LogError(ex, "[SKIP] Problem migrating team capacities."); } Log.LogInformation("Team capacities migration done.."); }
public async Task <bool> RegisterIterations() { bool result = true; VssConnection connection = new VssConnection(new Uri(Options.Url), new VssBasicCredential(string.Empty, Options.PAT)); // get VSTS's project collection ProjectHttpClient projectClient = connection.GetClient <ProjectHttpClient>(); IEnumerable <TeamProjectReference> projects = projectClient.GetProjects().Result; var targetProject = projects.FirstOrDefault(p => string.CompareOrdinal(p.Name, Options.Project) == 0); if (targetProject == null) { Console.WriteLine($"Project {Options.Project} not found in Server {Options.Url}"); return(false); } // get team of project setting TeamHttpClient teamClient = connection.GetClient <TeamHttpClient>(); var teams = await teamClient.GetTeamsAsync(targetProject.Id.ToString()); // found specific team var team = teams.FirstOrDefault(p => string.CompareOrdinal(p.Name, Options.Team) == 0); if (team == null) { Console.WriteLine($"Team {Options.Team} not found in Project {Options.Project}"); return(false); } WorkHttpClient workHttpClient = connection.GetClient <WorkHttpClient>(); // get team's iteration var teamContext = new TeamContext(targetProject.Id, team.Id); var teamSetting = await workHttpClient.GetTeamIterationsAsync(teamContext); if (teamSetting == null) { Console.WriteLine("Can\'t get team Iteration"); return(false); } try { int SprintCounter = Options.SprintStartIndex; do { var teamIteration = new TeamSettingsIteration { // these date values looks like ignore. Attributes = new TeamIterationAttributes { StartDate = DateTime.Today, FinishDate = DateTime.Today }, Name = string.Format($"Sprint {SprintCounter}"), Path = string.Format($"{Options.Project}\\{Options.SprintPrefix} {SprintCounter}"), }; // add team iteration from Project iteration. var execResult = await workHttpClient.PostTeamIterationAsync(teamIteration, teamContext); if (execResult != null) { SprintCounter++; Console.WriteLine($"Sprint {execResult.Path} add team iteration"); } } while (true); } catch (Exception ex) { // Exception is ignore, because PostTeamIteration Async method can't return error value. } return(result); }
static void Main(string[] args) { VssCredentials creds = new VssClientCredentials(); creds.Storage = new VssClientCredentialStorage(); VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds); v = connection; // Dont need this code at the moment. GitHttpClient gitClient = connection.GetClient <GitHttpClient>(); var repo = gitClient.GetRepositoryAsync(c_projectname, c_reponame).Result; //// Get process templates //ProcessHttpClient processClient = connection.GetClient<ProcessHttpClient>(); //var processes = processClient.GetProcessesAsync().Result; // Retrieve a list of projects from the account. (and ask if they should be deleted). This is to tidy up my test data. Console.WriteLine("Preparing a list of projects you may wish to delete!"); var projectHttpClient = connection.GetClient <ProjectHttpClient>(); //then - same as above..iterate over the project references(with a hard-coded pagination of the first 10 entries only) foreach (var projectReference in projectHttpClient.GetProjects(top: 20, skip: 0).Result) { var teamProject = projectHttpClient.GetProject(projectReference.Id.ToString()).Result; //var urlForTeamProject = ((ReferenceLink)teamProject.Links.Links["web"]).Href; //Console.WriteLine("Team Project '{0}' (Id: {1}) at Web Url: '{2}' & API Url: '{3}'", //teamProject.Name, //teamProject.Id, //urlForTeamProject, //teamProject.Url); if (teamProject.Description == "This is a dummy project") { Console.WriteLine("Delete this project {0}? (Y/N) default=No", teamProject.Name); string s = Console.ReadLine(); if (s == "Y") { projectHttpClient.QueueDeleteProject(teamProject.Id); } } } // return; bool createVSTSProject = false; string p = null; if (createVSTSProject) { // Create a new project Console.WriteLine("***************Project Creation ******************"); Console.WriteLine("Enter your project name"); p = null; do { p = Console.ReadLine(); } while (String.IsNullOrEmpty(p)); projectHttpClient = connection.GetClient <ProjectHttpClient>(); string projectName = CreateProject(connection, projectHttpClient, p); var createdProject = projectHttpClient.GetProject(projectName).Result; Console.WriteLine("retrieve and delete default iterations from project"); WorkHttpClient workClient = connection.GetClient <WorkHttpClient>(); TeamContext tc = new TeamContext(createdProject.Name); var iterations = workClient.GetTeamIterationsAsync(tc).Result; foreach (var item in iterations) { workClient.DeleteTeamIterationAsync(tc, item.Id).SyncResult(); Console.WriteLine("Deleting {0}", item.Name); } DateTime projectStartDate = new DateTime(2017, 07, 01); int discoveryIterationDays = 30; int breathingSpaceDays = 3; int standardIterationDays = 14; int alphaStandardIterations = 4; int privateBetaStandardIterations = 4; int publicBetaStandardIterations = 6; DateTime startDate = projectStartDate; DateTime endDate = startDate.AddDays(discoveryIterationDays); // Create a discovery iteration to get hold of a node to use as the re-assignment node when deleting stock iterations. Console.WriteLine("Creating a Discovery Phase from {0} to {1}", startDate, endDate); var node = AddIteration(createdProject.Id, "Discovery", startDate, endDate); int discoveryNodeId = node.Id; TeamSettingsIteration tsi = new TeamSettingsIteration(); tsi.Id = node.Identifier; var x = workClient.PostTeamIterationAsync(tsi, tc).Result; // Delete the standard iterations that come with a new project WorkItemTrackingHttpClient workItemTrackingClient = v.GetClient <WorkItemTrackingHttpClient>(); workItemTrackingClient.DeleteClassificationNodeAsync(createdProject.Id, TreeStructureGroup.Iterations, "Iteration 1", discoveryNodeId).SyncResult(); workItemTrackingClient.DeleteClassificationNodeAsync(createdProject.Id, TreeStructureGroup.Iterations, "Iteration 2", discoveryNodeId).SyncResult(); workItemTrackingClient.DeleteClassificationNodeAsync(createdProject.Id, TreeStructureGroup.Iterations, "Iteration 3", discoveryNodeId).SyncResult(); // Dont really need this at the moment // var processConfiguration = workClient.GetProcessConfigurationAsync(projectName).Result; // Add Alpha Phase startDate = endDate.AddDays(breathingSpaceDays); endDate = startDate.AddDays((alphaStandardIterations + 2 * standardIterationDays)); Console.WriteLine("Creating an Alpha Phase from {0} to {1}", startDate, endDate); node = AddIteration(createdProject.Id, "Alpha", startDate, endDate); tsi = new TeamSettingsIteration(); tsi.Id = node.Identifier; x = workClient.PostTeamIterationAsync(tsi, tc).Result; endDate = startDate.AddDays(standardIterationDays); Console.WriteLine("Creating an inception iteration from {0} to {1}", startDate, endDate); AddIteration(createdProject.Id, "Inception", startDate, endDate, "Alpha"); tsi = new TeamSettingsIteration(); tsi.Id = node.Identifier; x = workClient.PostTeamIterationAsync(tsi, tc).Result; for (int i = 0; i < alphaStandardIterations; i++) { startDate = endDate.AddDays(1); endDate = startDate.AddDays(standardIterationDays); Console.WriteLine("Creating a Standard Iteration {0} from {1} to {2}", i + 1, startDate, endDate); AddIteration(createdProject.Id, String.Format("Iteration {0}", i + 1), startDate, endDate, "Alpha"); tsi = new TeamSettingsIteration(); tsi.Id = node.Identifier; x = workClient.PostTeamIterationAsync(tsi, tc).Result; } startDate = endDate.AddDays(1); endDate = startDate.AddDays(standardIterationDays); Console.WriteLine("Creating an conclusion iteration from {0} to {1}", startDate, endDate); AddIteration(createdProject.Id, "Conclusion", startDate, endDate, "Alpha"); tsi = new TeamSettingsIteration(); tsi.Id = node.Identifier; x = workClient.PostTeamIterationAsync(tsi, tc).Result; startDate = endDate.AddDays(breathingSpaceDays); endDate = startDate.AddDays((privateBetaStandardIterations + publicBetaStandardIterations) * standardIterationDays); Console.WriteLine("Creating a Beta Phase from {0} to {1}", startDate, endDate); AddIteration(createdProject.Id, "Beta", startDate, endDate); tsi = new TeamSettingsIteration(); tsi.Id = node.Identifier; x = workClient.PostTeamIterationAsync(tsi, tc).Result; // test putting the sample project into GiT. // This would actually retrieve the files from the core template project. gitClient = connection.GetClient <GitHttpClient>(); repo = gitClient.GetRepositoryAsync(createdProject.Name, createdProject.Name).Result; GitHelper gh = new GitHelper(connection); var pushes = gh.ListPushesIntoMaster(c_projectname, c_reponame); var push = gh.CreatePush(createdProject.Name, repo.Name); pushes = gh.ListPushesIntoMaster(createdProject.Name, repo.Name); } // Create a new project Console.WriteLine("***************Create a DevTest Lab ******************"); Console.WriteLine("Enter a deployment name (need to work out how to capture template paramters here"); Console.WriteLine("or q to quit"); p = null; do { p = Console.ReadLine(); } while (String.IsNullOrEmpty(p)); if (p == "q") { return; } DeployerParameters parameters = new DeployerParameters(); parameters.ResourceGroupName = "Xekina-RG"; parameters.DeploymentName = "Xekina-Lab-Deployment"; parameters.ResourceGroupLocation = "North Europe"; // must be specified for creating a new resource group parameters.PathToTemplateFile = "./Files/azuredeploy.json"; parameters.PathToParameterFile = "./Files/azuredeploy.parameters.json"; // TODO: Get this from app.settings parameters.TenantId = CloudConfigurationManager.GetSetting("TenantId"); parameters.ClientId = CloudConfigurationManager.GetSetting("ClientId"); parameters.ClientSecret = CloudConfigurationManager.GetSetting("ClientSecret"); parameters.SubscriptionId = CloudConfigurationManager.GetSetting("SubscriptionId"); string templateParameters = File.ReadAllText(parameters.PathToParameterFile); RootObject ltp = JsonConvert.DeserializeObject <RootObject>(templateParameters); ltp.parameters.newLabName.value = "XekinaLab"; parameters.ParameterFileContent = JsonConvert.SerializeObject(ltp); Deployer deployer = new Deployer(parameters); deployer.Deploy().SyncResult(); Console.ReadLine(); return; }