public async Task <PnPContext> CreateTeamAsync(TeamOptions teamToCreate, TeamCreationOptions creationOptions = null) { if (teamToCreate is TeamForGroupOptions teamForGroupOptions) { return(await TeamCreator.CreateTeamForGroupAsync(context, teamForGroupOptions, creationOptions).ConfigureAwait(false)); } else { throw new Exception("Coming soon"); } }
private static TeamCreationOptions EnsureTeamCreationOptions(TeamCreationOptions creationOptions) { if (creationOptions == null) { creationOptions = new TeamCreationOptions(); } if (!creationOptions.MaxStatusChecks.HasValue) { creationOptions.MaxStatusChecks = 10; } if (!creationOptions.WaitAfterStatusCheck.HasValue) { creationOptions.WaitAfterStatusCheck = 30; } return(creationOptions); }
internal static async Task <PnPContext> CreateTeamForGroupAsync(PnPContext context, TeamForGroupOptions teamToCreate, TeamCreationOptions creationOptions = null) { // Ensure the needed creation options are configured creationOptions = EnsureTeamCreationOptions(creationOptions); // Construct the request body var body = BuildTeamCreationBody(teamToCreate); var stopwatch = new Stopwatch(); stopwatch.Start(); bool isProvisioningComplete = false; var retryAttempt = 1; Exception lastException = null; do { if (retryAttempt > 1) { context.Logger.LogDebug($"Elapsed: {stopwatch.Elapsed:mm\\:ss\\.fff} | Waiting {creationOptions.WaitAfterStatusCheck.Value} seconds"); await context.WaitAsync(TimeSpan.FromSeconds(creationOptions.WaitAfterStatusCheck.Value)).ConfigureAwait(false); } // Add the Team to the current group try { await(context.Web as Web).RawRequestAsync(new ApiCall($"groups/{teamToCreate.GroupId}/team", ApiType.Graph, body), HttpMethod.Put).ConfigureAwait(false); isProvisioningComplete = true; } catch (Exception ex) { // Log and eat exception here context.Logger.LogWarning(PnPCoreAdminResources.Log_Warning_ExceptionWhileCreatingTeamForGroup, teamToCreate.GroupId, ex.ToString()); lastException = ex; } retryAttempt++; }while (!isProvisioningComplete && retryAttempt <= creationOptions.MaxStatusChecks); stopwatch.Stop(); context.Logger.LogDebug($"Elapsed: {stopwatch.Elapsed:mm\\:ss\\.fff} | Finished"); if (isProvisioningComplete) { return(await GetPnPContextWithTeamAsync(context, teamToCreate.GroupId).ConfigureAwait(false)); } else { throw new MicrosoftGraphServiceException(string.Format(PnPCoreAdminResources.Exception_TeamCreation, teamToCreate.GroupId), lastException); } }
public PnPContext CreateTeam(TeamOptions teamToCreate, TeamCreationOptions creationOptions = null) { return(CreateTeamAsync(teamToCreate, creationOptions).GetAwaiter().GetResult()); }