From 56efece4335b760d4db3309492e961014eeca379 Mon Sep 17 00:00:00 2001 From: Steven Hutchings Date: Mon, 28 Jan 2019 15:30:03 -0800 Subject: [PATCH 1/3] Add capacity examples --- .../Work/TeamSettingsSample.cs | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs index 252608e5..9cbd4424 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs @@ -81,6 +81,98 @@ public TeamSetting UpdateTeamSettings() Console.WriteLine("Working days: {0}", String.Join(",", result.WorkingDays.Select(dow => { return dow.ToString(); }))); return result; + } + + [ClientSampleMethod] + public TeamMemberCapacityIdentityRef GetTeamMemberCapacity() + { + VssConnection connection = Context.Connection; + WorkHttpClient workClient = connection.GetClient(); + + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; + Guid userId = ClientSampleHelpers.GetCurrentUserId(this.Context); + + var teamContext = new TeamContext(projectId, teamId); + List result = workClient.GetTeamIterationsAsync(teamContext, "current").Result; + var iterationId = result[0].Id; + + var capacity = workClient.GetCapacityWithIdentityRefAsync(teamContext, iterationId, userId).Result; + + return capacity; + } + + [ClientSampleMethod] + public List GetTeamCapacity() + { + VssConnection connection = Context.Connection; + WorkHttpClient workClient = connection.GetClient(); + + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; + + var teamContext = new TeamContext(projectId, teamId); + List result = workClient.GetTeamIterationsAsync(teamContext, "current").Result; + var iterationId = result[0].Id; + + var capacity = workClient.GetCapacitiesWithIdentityRefAsync(teamContext, iterationId).Result; + + return capacity; + } + + [ClientSampleMethod] + public TeamMemberCapacityIdentityRef UpdateTeamMemberCapacity() + { + VssConnection connection = Context.Connection; + WorkHttpClient workClient = connection.GetClient(); + + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; + Guid userId = ClientSampleHelpers.GetCurrentUserId(this.Context); + + var teamContext = new TeamContext(projectId, teamId); + List result = workClient.GetTeamIterationsAsync(teamContext, "current").Result; + var iterationId = result[0].Id; + + var capacity = workClient.GetCapacityAsync(teamContext, iterationId, userId).Result; + var capacityPatch = new CapacityPatch() + { + Activities = capacity.Activities.Select(a => { return new Activity { Name = a.Name, CapacityPerDay = a.CapacityPerDay + 1 }; }), + DaysOff = capacity.DaysOff + }; + + var updatedCapacity = workClient.UpdateCapacityWithIdentityRefAsync(capacityPatch, teamContext, iterationId, userId).Result; + + return updatedCapacity; + } + + [ClientSampleMethod] + public List ReplaceTeamMemberCapacities() + { + VssConnection connection = Context.Connection; + WorkHttpClient workClient = connection.GetClient(); + + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; + + var teamContext = new TeamContext(projectId, teamId); + List result = workClient.GetTeamIterationsAsync(teamContext, "current").Result; + var iterationId = result[0].Id; + + var 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; } } } From 98762930ac919930d5d07aa674dbc158d9972469 Mon Sep 17 00:00:00 2001 From: Steven Hutchings Date: Mon, 28 Jan 2019 15:30:42 -0800 Subject: [PATCH 2/3] Fix indentation --- .../Work/TeamSettingsSample.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs index 9cbd4424..ef278fc3 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs @@ -83,7 +83,7 @@ public TeamSetting UpdateTeamSettings() return result; } - [ClientSampleMethod] + [ClientSampleMethod] public TeamMemberCapacityIdentityRef GetTeamMemberCapacity() { VssConnection connection = Context.Connection; From a3f7c7f137b8db708eb1cf89951289284555e99a Mon Sep 17 00:00:00 2001 From: Steven Hutchings Date: Mon, 28 Jan 2019 15:35:32 -0800 Subject: [PATCH 3/3] Remove usage of var --- .../Work/TeamSettingsSample.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs index ef278fc3..5da3a8cc 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs @@ -93,11 +93,11 @@ public TeamMemberCapacityIdentityRef GetTeamMemberCapacity() Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; Guid userId = ClientSampleHelpers.GetCurrentUserId(this.Context); - var teamContext = new TeamContext(projectId, teamId); + TeamContext teamContext = new TeamContext(projectId, teamId); List result = workClient.GetTeamIterationsAsync(teamContext, "current").Result; - var iterationId = result[0].Id; + Guid iterationId = result[0].Id; - var capacity = workClient.GetCapacityWithIdentityRefAsync(teamContext, iterationId, userId).Result; + TeamMemberCapacityIdentityRef capacity = workClient.GetCapacityWithIdentityRefAsync(teamContext, iterationId, userId).Result; return capacity; } @@ -111,11 +111,11 @@ public List GetTeamCapacity() Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; - var teamContext = new TeamContext(projectId, teamId); + TeamContext teamContext = new TeamContext(projectId, teamId); List result = workClient.GetTeamIterationsAsync(teamContext, "current").Result; - var iterationId = result[0].Id; + Guid iterationId = result[0].Id; - var capacity = workClient.GetCapacitiesWithIdentityRefAsync(teamContext, iterationId).Result; + List capacity = workClient.GetCapacitiesWithIdentityRefAsync(teamContext, iterationId).Result; return capacity; } @@ -130,18 +130,18 @@ public TeamMemberCapacityIdentityRef UpdateTeamMemberCapacity() Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; Guid userId = ClientSampleHelpers.GetCurrentUserId(this.Context); - var teamContext = new TeamContext(projectId, teamId); + TeamContext teamContext = new TeamContext(projectId, teamId); List result = workClient.GetTeamIterationsAsync(teamContext, "current").Result; - var iterationId = result[0].Id; + Guid iterationId = result[0].Id; - var capacity = workClient.GetCapacityAsync(teamContext, iterationId, userId).Result; - var capacityPatch = new CapacityPatch() + 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 }; - var updatedCapacity = workClient.UpdateCapacityWithIdentityRefAsync(capacityPatch, teamContext, iterationId, userId).Result; + TeamMemberCapacityIdentityRef updatedCapacity = workClient.UpdateCapacityWithIdentityRefAsync(capacityPatch, teamContext, iterationId, userId).Result; return updatedCapacity; } @@ -155,11 +155,11 @@ public List ReplaceTeamMemberCapacities() Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; - var teamContext = new TeamContext(projectId, teamId); + TeamContext teamContext = new TeamContext(projectId, teamId); List result = workClient.GetTeamIterationsAsync(teamContext, "current").Result; - var iterationId = result[0].Id; + Guid iterationId = result[0].Id; - var capacity = workClient.GetCapacitiesWithIdentityRefAsync(teamContext, iterationId).Result; + List capacity = workClient.GetCapacitiesWithIdentityRefAsync(teamContext, iterationId).Result; var updatedCapacity = capacity.Select(teamMemberCapacity => { return new TeamMemberCapacityIdentityRef()