Exemplo n.º 1
0
        public void CreateDeleteProjectVSTSGroup()
        {
            // Get the client
            VssConnection connection = Context.Connection;

            //
            // Part 1: get the project id
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "GetProjectId");
            ProjectHttpClient projectClient = connection.GetClient <ProjectHttpClient>();
            string            projectName   = ClientSampleHelpers.FindAnyProject(this.Context).Name;
            TeamProject       project       = projectClient.GetProject(projectName, includeCapabilities: true, includeHistory: true).Result;
            Guid projectId = project.Id;

            //
            // Part 2: get the project scope descriptor
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "GetProjectScopeDescriptor");
            GraphHttpClient       graphClient       = connection.GetClient <GraphHttpClient>();
            GraphDescriptorResult projectDescriptor = graphClient.GetDescriptorAsync(projectId).Result;

            //
            // Part 3: create a group at the project level
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "CreateGroupInProject");
            GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext
            {
                DisplayName = "Project Developers-" + Guid.NewGuid(),
                Description = "Group at project level created via client library"
            };

            GraphGroup newGroup        = graphClient.CreateGroupAsync(createGroupContext, projectDescriptor.Value).Result;
            string     groupDescriptor = newGroup.Descriptor;

            Context.Log("New group created! ID: {0}", groupDescriptor);

            //
            // Part 4: delete the group
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteGroup");
            graphClient.DeleteGroupAsync(groupDescriptor).SyncResult();

            // Try to get the deleted group (should result in an exception)
            ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledGroup");
            try
            {
                newGroup = graphClient.GetGroupAsync(groupDescriptor).Result;
            }
            catch (Exception e)
            {
                Context.Log("Unable to get the deleted group:" + e.Message);
            }
        }
Exemplo n.º 2
0
        public void GetDescriptorById()
        {
            // Get the client
            VssConnection   connection  = Context.Connection;
            GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>();

            //
            // Part 1: add the AAD user
            //
            Guid storageKey = new Guid("9b71f216-4c4f-6b74-a911-efb0fa9c777f");

            ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithStorageKey");
            GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext
            {
                OriginId   = "27dbfced-5593-4756-98a3-913c39af7612",
                StorageKey = storageKey
            };

            GraphUser newUser        = graphClient.CreateUserAsync(addAADUserContext).Result;
            string    userDescriptor = newUser.Descriptor;

            Context.Log("New user added! ID: {0}", userDescriptor);

            //
            // Part 2: get the descriptor
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "GetDescriptorById");
            GraphDescriptorResult descriptor = graphClient.GetDescriptorAsync(storageKey).Result; //TODO: This is failing!!!!!

            try
            {
                if (descriptor.Value != userDescriptor)
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                Context.Log("The descriptors don't match!");
            }

            //
            // Part 3: remove the user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUser");
            graphClient.DeleteUserAsync(userDescriptor).SyncResult();

            // Try to get the deleted user
            ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipState");
            GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result;

            try
            {
                if (membershipState.Active)
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                Context.Log("The deleted user is not disabled!");
            }
        }