Exemplo n.º 1
0
        internal PagedGraphGroups GetAllGroups()
        {
            GraphHttpClient  graphClient = connection.GetClient <GraphHttpClient>();
            PagedGraphGroups groups      = graphClient.ListGroupsAsync().Result;

            return(groups);
        }
Exemplo n.º 2
0
    internal static async IAsyncEnumerable <GraphGroup> AsContinuousCollectionAsync(
        this PagedGraphGroups page,
        Func <string, Task <PagedGraphGroups> > getNextPage)
    {
        if (page is null)
        {
            throw new ArgumentNullException(nameof(page));
        }

        if (getNextPage is null)
        {
            throw new ArgumentNullException(nameof(getNextPage));
        }

        var currentPage = page;

        do
        {
            if (!(currentPage.GraphGroups?.Any() ?? false))
            {
                yield break;
            }

            foreach (var element in currentPage.GraphGroups)
            {
                yield return(element);
            }
        } while ((currentPage.ContinuationToken?.Any() ?? false) &&
                 (currentPage = await getNextPage(currentPage.ContinuationToken.First()).ConfigureAwait(false)) is not null);
    }
Exemplo n.º 3
0
        public void ConnectionIsCreated()
        {
            string        PAT           = Environment.GetEnvironmentVariable("ADOConnection_PAT");
            string        collectionUrl = Environment.GetEnvironmentVariable("ADOConnection_URL");
            ADOConnection aDOConnection = new ADOConnection(collectionUrl, PAT);

            using (GraphHttpClient graphClient = aDOConnection.Connection.GetClient <GraphHttpClient>())
            {
                PagedGraphGroups groups = graphClient.ListGroupsAsync().Result;
                Assert.IsNotNull(groups.GraphGroups);
            }
        }
Exemplo n.º 4
0
        public async Task <List <string> > GetUsers(string organization)
        {
            VssConnection connection = null;

            try
            {
                string url = $"https://dev.azure.com/{organization}";
                if (_adoConfig.UsePta)
                {
                    connection = new VssConnection(new Uri(url), new VssBasicCredential(string.Empty, _adoConfig.AdoPersonalAccessToken));
                }
                //connection = new VssConnection()
                else
                {
                    connection = new VssConnection(new Uri(url), new VssClientCredentials(true));
                }

                GraphHttpClient  graphClient = connection.GetClient <GraphHttpClient>();
                PagedGraphGroups groups      = await graphClient.ListGroupsAsync();

                var users = await graphClient.ListUsersAsync();

                return(users?.GraphUsers.Where(a => a.Origin.Contains("ad", StringComparison.OrdinalIgnoreCase))?.Select(a => a.DisplayName)?.ToList());


                //UserHttpClient userHttpClient = connection.GetClient<UserHttpClient>();

                //TeamHttpClient teamHttpClient = connection.GetClient<TeamHttpClient>();

                //AccountHttpClient accountHttpClient = connection.GetClient<AccountHttpClient>();
                //var res = await accountHttpClient.GetAccountsAsync();
                //return res.Select(a => a.AccountName).ToList();

                //ProfileHttpClient profileHttpClient = connection.GetClient<ProfileHttpClient>();

                //OrganizationHttpClient organizatioClient = connection.GetClient<OrganizationHttpClient>();

                //var res = profileHttpClient.ge
                //var res = await teamHttpClient.GetTeamMembers()

                return(null);
            }
            catch (Exception ex)
            {
                //throw;
            }
            finally
            {
                connection?.Dispose();
            }
            return(null);
        }
Exemplo n.º 5
0
        public PagedGraphGroups GetAllGroups()
        {
            VssConnection    connection  = Context.Connection;
            GraphHttpClient  graphClient = connection.GetClient <GraphHttpClient>();
            PagedGraphGroups groups      = graphClient.GetGroupsAsync().Result;

            foreach (var group in groups.GraphGroups)
            {
                LogGroup(group);
            }

            return(groups);
        }
Exemplo n.º 6
0
        //================ VSTS graph api helper code ===========================================================

        private static GraphGroup GetGraphGroupFromString(GraphHttpClient graphClient, string groupDisplayname)
        {
            PagedGraphGroups groups = graphClient.GetGroupsAsync().Result;

            GraphGroup selectedGroup = null;

            foreach (var group in groups.GraphGroups)
            {
                if (group.DisplayName.Equals(groupDisplayName))
                {
                    return(selectedGroup = group);
                }
            }
            return(null);
        }
Exemplo n.º 7
0
        internal static async IAsyncEnumerable <GraphGroup> AsContinousEnumerationAsync(this PagedGraphGroups page, Func <string, Task <PagedGraphGroups> > nextPageCallback)
        {
            if (page is null)
            {
                throw new ArgumentNullException(nameof(page));
            }

            if (nextPageCallback is null)
            {
                throw new ArgumentNullException(nameof(nextPageCallback));
            }

            foreach (var group in page.GraphGroups ?? Enumerable.Empty <GraphGroup>())
            {
                yield return(group);
            }

            var continuationToken = page.ContinuationToken?.SingleOrDefault();

            if (!string.IsNullOrEmpty(continuationToken))
            {
                var nextPage = await nextPageCallback(continuationToken)
                               .ConfigureAwait(false);

                await foreach (var group in nextPage.AsContinousEnumerationAsync(nextPageCallback))
                {
                    yield return(group);
                }
            }
        }