Пример #1
0
        public static async Task <Team> NewTeamAsync(string accessToken, HttpClient httpClient, string groupId, string displayName, string description, string classification, string mailNickname, string owner, GroupVisibility visibility, TeamCreationInformation teamCI)
        {
            Group group      = null;
            Team  returnTeam = null;

            // Create group
            if (string.IsNullOrEmpty(groupId))
            {
                group = await CreateGroupAsync(accessToken, httpClient, displayName, description, classification, mailNickname, owner, visibility);
            }
            else
            {
                group = await GraphHelper.GetAsync <Group>(httpClient, $"v1.0/groups/{groupId}", accessToken);

                if (group == null)
                {
                    throw new PSArgumentException($"Cannot find group with id {groupId}");
                }
                teamCI.Visibility  = group.Visibility;
                teamCI.Description = group.Description;
            }
            if (group != null)
            {
                Team team         = teamCI.ToTeam();
                var  teamSettings = await GraphHelper.PutAsync(httpClient, $"v1.0/groups/{group.Id}/team", team, accessToken);

                if (teamSettings != null)
                {
                    returnTeam = await TeamsUtility.GetTeamAsync(accessToken, httpClient, group.Id);
                }
            }
            return(returnTeam);
        }
Пример #2
0
        public static async Task <Team> NewTeamAsync(string accessToken, HttpClient httpClient, string groupId, string displayName, string description, string classification, string mailNickname, string owner, GroupVisibility visibility, TeamCreationInformation teamCI, TeamsTemplateType templateType = TeamsTemplateType.None, TeamResourceBehaviorOptions?[] resourceBehaviorOptions = null)
        {
            Group group      = null;
            Team  returnTeam = null;

            // Create group
            if (string.IsNullOrEmpty(groupId))
            {
                group = await CreateGroupAsync(accessToken, httpClient, displayName, description, classification, mailNickname, owner, visibility, templateType, resourceBehaviorOptions);

                bool wait       = true;
                int  iterations = 0;
                while (wait)
                {
                    iterations++;

                    try
                    {
                        var createdGroup = await GraphHelper.GetAsync <Group>(httpClient, $"v1.0/groups/{group.Id}", accessToken);

                        if (!string.IsNullOrEmpty(createdGroup.DisplayName))
                        {
                            wait = false;
                        }
                    }
                    catch (Exception)
                    {
                        // In case of exception wait for 5 secs
                        await Task.Delay(TimeSpan.FromSeconds(5));
                    }

                    // Don't wait more than 1 minute
                    if (iterations > 12)
                    {
                        wait = false;
                    }
                }
            }
            else
            {
                group = await GraphHelper.GetAsync <Group>(httpClient, $"v1.0/groups/{groupId}", accessToken);

                if (group == null)
                {
                    throw new PSArgumentException($"Cannot find group with id {groupId}");
                }
                teamCI.Visibility  = group.Visibility;
                teamCI.Description = group.Description;
            }
            if (group != null)
            {
                Team team      = teamCI.ToTeam(group.Visibility);
                var  retry     = true;
                var  iteration = 0;
                while (retry)
                {
                    try
                    {
                        var teamSettings = await GraphHelper.PutAsync(httpClient, $"v1.0/groups/{group.Id}/team", team, accessToken);

                        if (teamSettings != null)
                        {
                            returnTeam = await TeamsUtility.GetTeamAsync(accessToken, httpClient, group.Id);
                        }
                        retry = false;
                    }

                    catch (Exception)
                    {
                        await Task.Delay(5000);

                        iteration++;
                    }

                    if (iteration > 10) // don't try more than 10 times
                    {
                        retry = false;
                    }
                }
            }
            return(returnTeam);
        }