コード例 #1
0
        public SubscriptionUserSettings OptOutfTeamSubscription()
        {
            NotificationSubscription teamSubscription;

            using (new ClientSampleHttpLoggerOutputSuppression())
            {
                teamSubscription = CreateSubscriptionForTeam();
            }

            Guid teamMemberId = ClientSampleHelpers.GetCurrentUserId(Context);

            SubscriptionUserSettings userSettings = new SubscriptionUserSettings()
            {
                OptedOut = true
            };
            NotificationHttpClient notificationClient = this.Context.Connection.GetClient <NotificationHttpClient>();

            userSettings = notificationClient.UpdateSubscriptionUserSettingsAsync(userSettings, teamSubscription.Id, teamMemberId).Result;

            using (new ClientSampleHttpLoggerOutputSuppression())
            {
                notificationClient.DeleteSubscriptionAsync(teamSubscription.Id);
            }

            return(userSettings);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public TeamMemberCapacityIdentityRef GetTeamMemberCapacity()
        {
            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;

            return(capacity);
        }
コード例 #4
0
        public ReleaseDefinition CreateReleaseDefinition()
        {
            string projectName   = ClientSampleHelpers.FindAnyProject(this.Context).Name;
            string currentUserId = ClientSampleHelpers.GetCurrentUserId(this.Context).ToString();

            // If you want to override varaibles at release create time you should set 'AllowOverride'.
            ConfigurationVariableValue nonSceretVariable = new ConfigurationVariableValue();

            nonSceretVariable.Value         = "NonSecretValue";
            nonSceretVariable.IsSecret      = false;
            nonSceretVariable.AllowOverride = true;

            ConfigurationVariableValue sceretVariable = new ConfigurationVariableValue();

            sceretVariable.Value    = "SecretValue";
            sceretVariable.IsSecret = true;

            ConfigurationVariableValue nonOverrideVariable = new ConfigurationVariableValue();

            nonOverrideVariable.Value         = "NonOverridevariable";
            nonOverrideVariable.IsSecret      = false;
            nonOverrideVariable.AllowOverride = false;

            Dictionary <string, ConfigurationVariableValue> releaseLevelVariables = new Dictionary <string, ConfigurationVariableValue>();

            releaseLevelVariables.Add(NonSecretReleaseLevelVaraible, nonSceretVariable);
            releaseLevelVariables.Add("SecretReleaseLevelVaraible", sceretVariable);
            releaseLevelVariables.Add("NonOverridevariable", nonOverrideVariable);

            ReleaseDefinition definition = new ReleaseDefinition()
            {
                Name         = releaseDefinitionName,
                Revision     = 1,
                Variables    = releaseLevelVariables, // You can add varaibles at environment level also.
                Environments = new List <ReleaseDefinitionEnvironment>()
                {
                    new ReleaseDefinitionEnvironment()
                    {
                        Name         = "PROD",
                        DeployPhases = new List <DeployPhase>()
                        {
                            new AgentBasedDeployPhase()
                            {
                                Name            = "Run on agent",
                                Rank            = 1,
                                DeploymentInput = new AgentDeploymentInput()
                                {
                                    QueueId = 1
                                }
                            }
                        },
                        PreDeployApprovals = new ReleaseDefinitionApprovals()
                        {
                            Approvals = new List <ReleaseDefinitionApprovalStep>()
                            {
                                new ReleaseDefinitionApprovalStep()
                                {
                                    IsAutomated = false,
                                    Rank        = 1,
                                    Approver    = new IdentityRef()
                                    {
                                        Id = currentUserId
                                    }
                                },
                            }
                        },
                        PostDeployApprovals = new ReleaseDefinitionApprovals()
                        {
                            Approvals = new List <ReleaseDefinitionApprovalStep>()
                            {
                                new ReleaseDefinitionApprovalStep()
                                {
                                    IsAutomated = true,
                                    Rank        = 1
                                }
                            }
                        },
                        RetentionPolicy = new EnvironmentRetentionPolicy()
                        {
                            DaysToKeep     = 30,
                            ReleasesToKeep = 3,
                            RetainBuild    = true
                        }
                    }
                }
            };

            // Get a release client instance
            VssConnection     connection    = Context.Connection;
            ReleaseHttpClient releaseClient = connection.GetClient <ReleaseHttpClient>();

            // create a release definition
            ReleaseDefinition releaseDefinition = releaseClient.CreateReleaseDefinitionAsync(project: projectName, releaseDefinition: definition).Result;

            newlyCreatedReleaseDefinitionId = releaseDefinition.Id;

            Context.Log("{0} {1}", releaseDefinition.Id.ToString().PadLeft(6), releaseDefinition.Name);

            return(releaseDefinition);
        }
コード例 #5
0
        public ReleaseDefinition CreateReleaseDefinition()
        {
            string projectName   = ClientSampleHelpers.FindAnyProject(this.Context).Name;
            string currentUserId = ClientSampleHelpers.GetCurrentUserId(this.Context).ToString();

            ReleaseDefinition definition = new ReleaseDefinition()
            {
                Name         = releaseDefinitionName,
                Revision     = 1,
                Environments = new List <ReleaseDefinitionEnvironment>()
                {
                    new ReleaseDefinitionEnvironment()
                    {
                        Name         = "PROD",
                        DeployPhases = new List <DeployPhase>()
                        {
                            new AgentBasedDeployPhase()
                            {
                                Name            = "Run on agent",
                                Rank            = 1,
                                DeploymentInput = new AgentDeploymentInput()
                                {
                                    QueueId = 1
                                }
                            }
                        },
                        PreDeployApprovals = new ReleaseDefinitionApprovals()
                        {
                            Approvals = new List <ReleaseDefinitionApprovalStep>()
                            {
                                new ReleaseDefinitionApprovalStep()
                                {
                                    IsAutomated = false,
                                    Rank        = 1,
                                    Approver    = new IdentityRef()
                                    {
                                        Id = currentUserId
                                    }
                                },
                            }
                        },
                        PostDeployApprovals = new ReleaseDefinitionApprovals()
                        {
                            Approvals = new List <ReleaseDefinitionApprovalStep>()
                            {
                                new ReleaseDefinitionApprovalStep()
                                {
                                    IsAutomated = true,
                                    Rank        = 1
                                }
                            }
                        },
                        RetentionPolicy = new EnvironmentRetentionPolicy()
                        {
                            DaysToKeep     = 30,
                            ReleasesToKeep = 3,
                            RetainBuild    = true
                        }
                    }
                }
            };

            // Get a release client instance
            VssConnection     connection    = Context.Connection;
            ReleaseHttpClient releaseClient = connection.GetClient <ReleaseHttpClient>();

            // create a release definition
            ReleaseDefinition releaseDefinition = releaseClient.CreateReleaseDefinitionAsync(project: projectName, releaseDefinition: definition).Result;

            newlyCreatedReleaseDefinitionId = releaseDefinition.Id;

            Context.Log("{0} {1}", releaseDefinition.Id.ToString().PadLeft(6), releaseDefinition.Name);

            return(releaseDefinition);
        }