コード例 #1
0
        public void CreateDemoData(DemoDate demoDate)
        {
            var baseFolderPath    = Server.MapPath("~/");
            var currentUsername   = HttpContext.User.Identity.Name;
            var graphServiceToken = this.TempData.Peek("graphServiceToken").ToString();

            if (demoDataProvisioningTask == null || demoDataProvisioningTask.Phase == "Completed")
            {
                demoDataProvisioningTask      = new SiteProvisioningTask();
                demoDataProvisioningTask.Task = Task.Factory.StartNew(async() =>
                {
                    try
                    {
                        var token        = this.TempData.Peek("demoSiteToken") as string;
                        var graphService = this.TempData.Peek("graphService") as GraphServiceClient;

                        using (var clientContext = this.TempData.Peek("demoSiteClientContext") as Microsoft.SharePoint.Client.ClientContext)
                        {
                            demoDataProvisioningTask.Phase   = "provision SharePoint demo data";
                            demoDataProvisioningTask.Message = "The SharePoint demo data is being provisioned. This operation can take up to 20 minutes to complete.  Please be patient and do not refresh the page during this process.";

                            var siteProvisioning = new SiteProvisioning(clientContext, baseFolderPath, currentUsername, graphServiceToken);
                            await siteProvisioning.AddSiteContentsAsync(new VideoPortalHelper(token));
                            siteProvisioning.UpdateInspectionAndIncidentListItems(DateTime.Parse(demoDate.date));

                            demoDataProvisioningTask.Phase   = "provision demo users and AAD groups";
                            demoDataProvisioningTask.Message = "The SharePoint demo data has been provisioned successfully.  Proceeding to provision Demo users and AAD groups. Please be patient and do not refresh the page during this process.";
                            await siteProvisioning.AddGroupsAndUsersAsync(graphService, graphServiceToken);

                            demoDataProvisioningTask.Phase   = "provision o365 groups";
                            demoDataProvisioningTask.Message = "The demo AAD users and groups have been provisioned successfully.  Proceeding to provision Office 365 Groups. Please be patient and do not refresh the page during this process.";
                            await siteProvisioning.CreateUnifiedGroupsForPropertiesAsync(graphService, graphServiceToken);

                            demoDataProvisioningTask.Phase   = "provision demo excel";
                            demoDataProvisioningTask.Message = "The Office 365 Groups have been provisioned successfully.  Proceeding to provision Excel Workbooks. Please be patient and do not refresh the page during this process.";
                            await siteProvisioning.UpdateExcelGroupsForPropertiesAsync(graphService, graphServiceToken);

                            office365groups = await GetO365DemoGroups(graphService);
                            demoDataProvisioningTask.Phase   = "Completed";
                            demoDataProvisioningTask.Message = "The AAD Users and Groups, Office 365 Groups, and all demo data have been successfully created.  The initial password for all the users is: TempP@ssw0rd!";
                        }
                    }
                    catch (Exception ex)
                    {
                        demoDataProvisioningTask.Message = "An unexpected error occurred, please try again, error message: " + ex.Message;
                        demoDataProvisioningTask.Phase   = "Error";
                    }
                });
            }
        }
        public async Task <ActionResult> CreateDemoData(SuiteLevelWebApp.Models.ProvisionDemoData model)
        {
            var token        = AuthenticationHelper.GetAccessTokenAsync(AppSettings.DemoSiteServiceResourceId);
            var graphService = AuthenticationHelper.GetGraphServiceAsync();

            using (var clientContext = await AuthenticationHelper.GetDemoSiteClientContextAsync())
            {
                var siteProvisioning = new SiteProvisioning(clientContext);
                await siteProvisioning.AddSiteContentsAsync(new VideoPortalHelper(await token));

                siteProvisioning.UpdateInspectionAndIncidentListItems(model.DateDemo);
                await siteProvisioning.AddGroupsAndUsersAsync(await graphService);

                await siteProvisioning.CreateUnifiedGroupsForPropertiesAsync(await graphService);

                model.Message        = "The AAD Groups, AAD Users, and demo data have been created successfully.  The initial password for all the users is: TempP@ssw0rd!";
                TempData["datetime"] = model;
                return(RedirectToAction("ProvisionDemoData"));
            }
        }