public async Task<ActionResult> ProvisionSiteComponents() { string token = await O365Util.GetAccessToken(ServiceResources.Dashboard); using (var clientContext = TokenHelper.GetClientContextWithAccessToken(DemoSiteCollectionUrl, token)) { SiteProvisioning siteProvisioning = new SiteProvisioning(clientContext); siteProvisioning.AddSiteComponents(); //siteProvisioning.RemoveSiteComponents(); ViewBag.Message = "The demo site collection has been created successfully. Click the Provision Workflow menu item to proceed."; } return View(); }
public void StartSiteProvisioning() { var baseFolderPath = Server.MapPath("~/"); if (siteProvisioningTask == null || siteProvisioningTask.Task.IsCompleted) { siteProvisioningTask = new SiteProvisioningTask(); siteProvisioningTask.Task = Task.Factory.StartNew(() => { try { SiteProvisioning siteProvisioning = new SiteProvisioning(this.TempData.Peek("demoSiteClientContext") as ClientContext, baseFolderPath); //provision site collection siteProvisioningTask.Phase = "provision site collection"; while (true) { using (var adminClientContext = this.TempData.Peek("adminClientContext") as ClientContext) { siteProvisioningTask.Message = "The demo site collection is being created. This operation can take up to 20 minutes to complete. Please be patient and do not refresh the page during this process."; var status = siteProvisioning.CreateSiteCollection(adminClientContext); if (status == "created") { siteProvisioningTask.Message = "The demo site collection was successfully created. Proceeding to provision information architecture. This process may take several minutes, please be patient and do not refresh the page during this process. If you are eager to see the progress you may browse to the new site collection in your browser and inspect the new components as they are provisioned."; break; } if (status == "fail") { siteProvisioningTask.Message = "An error occurred. This is usually due to one of two reasons. 1. You did not log in with an account that is a Global Administrator for your tenancy. If you have logged in with a Global Administrator account, log out and close all browser windows then try this step again. 2. The site collection exists in the Recycle Bin. If the Site Collection still exists in the Recycle Bin use the SharePoint Online Management Shell to delete it completely. The How to re-provision the entire information architecture and demo data section in the README describes how to use the following command to delete the site collection from the Recycle Bin. Remove-SPODeletedSite -Identity <Site Collection URL>"; return; } } Thread.Sleep(1000 * 30); } //reset demosite client context siteProvisioning.clientContext = this.TempData["demoSiteClientContext"] as ClientContext; //provision information architecture siteProvisioningTask.Phase = "provision information architecture"; siteProvisioning.RemoveSiteComponents(); siteProvisioning.AddSiteComponents(); siteProvisioningTask.Message = "The information architecture has been created successfully. Proceeding to provision Workflows. This process may take several minutes, please be patient and do not refresh the page during this process. "; //provision workflow siteProvisioningTask.Phase = "provision workflow"; string incidentWorkflowFile = Server.MapPath("~/Workflows/Incident.xaml"); string suiteLevelWebAppUrl = Request.Url.GetLeftPart(UriPartial.Authority); siteProvisioning.RemoveIncidentWorkflowAndRelatedLists(); siteProvisioning.ProvisionIncidentWorkflowAndRelatedLists(incidentWorkflowFile, suiteLevelWebAppUrl, AppSettings.DispatcherName); siteProvisioningTask.Message = "Incident Workflow, Incident Workflow Tasks list and Incident Workflow History list have been created successfully. Click the Create Sample Data menu item to proceed."; siteProvisioning.clientContext.Dispose(); } catch (Exception ex) { siteProvisioningTask.Message = "An unexpected error occurred, please try again, error message: " + ex.Message; } }); } }