Ejemplo n.º 1
0
        private static async Task <PnPContext> CreateClassicSiteAsync(PnPContext context, ClassicSiteOptions siteToCreate, SiteCreationOptions creationOptions)
        {
            using (var tenantAdminContext = await context.GetSharePointAdmin().GetTenantAdminCenterContextAsync().ConfigureAwait(false))
            {
                string owner      = siteToCreate.Owner;
                var    splitOwner = owner.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                if (splitOwner.Length == 3)
                {
                    owner = splitOwner[2];
                }

                List <IRequest <object> > csomRequests = new List <IRequest <object> >
                {
                    new CreateSiteRequest(siteToCreate.Url, siteToCreate.Title, owner, siteToCreate.WebTemplate, (int)siteToCreate.Language, (int)siteToCreate.TimeZone)
                };

                var result = await(tenantAdminContext.Web as Web).RawRequestAsync(new ApiCall(csomRequests), HttpMethod.Post).ConfigureAwait(false);

                SpoOperation op = result.ApiCall.CSOMRequests[0].Result as SpoOperation;

                if (!op.IsComplete)
                {
                    await SiteCollectionManagement.WaitForSpoOperationCompleteAsync(tenantAdminContext, op).ConfigureAwait(false);
                }

                return(await context.CloneAsync(siteToCreate.Url).ConfigureAwait(false));
            }
        }
        internal static async Task WaitForSpoOperationCompleteAsync(PnPContext tenantAdminContext, SpoOperation operation, int maxStatusChecks = 10)
        {
            if (operation.IsComplete)
            {
                return;
            }

            List <IRequest <object> > csomRequests = new List <IRequest <object> >
            {
                new SpoOperationRequest(operation.ObjectIdentity)
            };

            bool operationComplete  = false;
            var  statusCheckAttempt = 1;

            do
            {
                await tenantAdminContext.WaitAsync(TimeSpan.FromMilliseconds(operation.PollingInterval)).ConfigureAwait(false);

                var result = await(tenantAdminContext.Web as Web).RawRequestAsync(new ApiCall(csomRequests), HttpMethod.Post).ConfigureAwait(false);

                operation = result.ApiCall.CSOMRequests[0].Result as SpoOperation;

                if (operation.IsComplete)
                {
                    operationComplete = true;
                }

                statusCheckAttempt++;
            }while (!operationComplete && statusCheckAttempt <= maxStatusChecks);
        }