コード例 #1
0
        public async Task <ActionResult> ProvisionWorkflowPost()
        {
            var token = await O365Util.GetAccessToken(ServiceResources.Dashboard);

            var suiteLevelWebAppUrl = Regex.Match(Request.Url.AbsoluteUri, "https?://[^/]+?(?=/)", RegexOptions.Compiled).Value;

            using (var clientContext = TokenHelper.GetClientContextWithAccessToken(DemoSiteCollectionUrl, token))
            {
                var service       = new WorkflowProvisionService(clientContext);
                var incidentsList = CSOMUtil.getListByTitle(clientContext, "Incidents");

                service.Unsubscribe(incidentsList.Id, "Incident");
                service.DeleteDefinitions("Incident");
                service.DeleteList("Incident Workflow Tasks");
                service.DeleteList("Incident Workflow History");

                var workflow = System.IO.File.ReadAllText(Server.MapPath("~/Workflows/Incident.xaml"));

                workflow = workflow.Replace("(SuiteLevelWebAppUrlPlaceholder)", suiteLevelWebAppUrl)
                           .Replace("(dispatcherPlaceHolder)", ConfigurationManager.AppSettings["DispatcherName"]);
                workflow = WorkflowUtil.TranslateWorkflow(workflow);
                var definitionId  = service.SaveDefinitionAndPublish("Incident", workflow);
                var taskListId    = service.CreateTaskList("Incident Workflow Tasks");
                var historyListId = service.CreateHistoryList("Incident Workflow History");
                service.Subscribe("Incident Workflow", definitionId, incidentsList.Id, WorkflowSubscritpionEventType.ItemAdded, taskListId, historyListId);

                ViewBag.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.";
            }
            return(View());
        }
コード例 #2
0
        public async Task <ActionResult> Index()
        {
            string token = await O365Util.GetAccessToken(ServiceResources.Admin);

            //Determine if the site collection used for the demo is already created
            using (var adminClientContext = TokenHelper.GetClientContextWithAccessToken(AdminServiceResourceId, token))
            {
                switch (CSOMUtil.GetSiteCollectionStatusByUrl(adminClientContext, DemoSiteCollectionUrl))
                {
                case "Active":
                    ViewBag.refresh = string.Empty;
                    ViewBag.Message = "The demo site collection was successfully created.  Proceeding to provision information architecture and content.  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.";

                    return(new RedirectResult("/O365SiteProvisioning/ProvisionSiteComponents"));

                case "Creating":
                    ViewBag.refresh  = "refresh";
                    ViewBag.Message += DateTime.Now.ToString() + " - The demo site collection is being created.  The page will be refreshed automatically to check status.  This operation can take up to 20 minutes to complete.";
                    break;

                case "None":
                    try
                    {
                        CSOMUtil.CreateSiteCollection(adminClientContext, new SiteCreationProperties
                        {
                            Url                  = DemoSiteCollectionUrl,
                            Owner                = DemoSiteCollectionOwner,
                            Template             = "BLANKINTERNETCONTAINER#0",
                            Title                = "Contoso Property Management Dashboard",
                            StorageMaximumLevel  = 1000,
                            StorageWarningLevel  = 750,
                            TimeZoneId           = 7,
                            UserCodeMaximumLevel = 1000,
                            UserCodeWarningLevel = 500
                        });

                        ViewBag.refresh           = "refresh";
                        ViewBag.Message           = "The demo site collection is being created, please wait a few minutes, and the page will be refreshed automatically to check status.";
                        ViewBag.serviceResourceId = AdminServiceResourceId;
                    }
                    catch (Exception el)
                    {
                        ViewBag.refresh = "";
                        ViewBag.Message = el.Message + " If the Site Collection still exists in the Recycle Bin use the SharePoint Online Management Shell to delete it completely. Remove-SPODeletedSite -Identity <Site Collection URL>";
                    }
                    break;
                }
            }

            return(View());
        }
コード例 #3
0
        public static void ProvisionWorkFlowAndRelatedList(string workFlowXMlFile, string binderSiteUrl)
        {
            //Return the list the workflow will be associated with
            binderSiteClientContext = new ClientContext(binderSiteUrl);
            binderSiteClientContext.Credentials = new SharePointOnlineCredentials("*****@*****.**", passWord);
            var bbhDocumentList = CSOMUtil.GetListByTitle(binderSiteClientContext, "BBH Documents");

            //Create a new WorkflowProvisionService class instance which uses the 
            //Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager to
            //provision and configure workflows
            var service = new WorkflowProvisionService(binderSiteClientContext);

            //Read the workflow .XAML file
            //var bbhDocumentWF = System.IO.File.ReadAllText(workFlowXMlFile);
            //string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
            //foreach (char c in invalid)
            //{
            //    workFlowXMlFile = workFlowXMlFile.Replace(c.ToString(), "");
            //}
            //var solutionPath = "E:/Site Provisioning files/BBH Document Atestation (1).wsp";
            var bbhDocumentWF = workFlowXMlFile;


            //Create the WorkflowDefinition and use the 
            //Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager
            //to save and publish it.  
            //This method is shown below for reference.
            //var bbhDocumentWFDefinitionId = service.SaveDefinitionAndPublish("BBHDocument", WorkflowUtil.TranslateWorkflow(bbhDocumentWF));
            var bbhDocumentWFDefinitionId = service.SaveDefinitionAndPublish("BBHDocument", bbhDocumentWF);

            //Create the workflow tasks list
            //var taskListId = service.CreateTaskList("BBHDocument Workflow Tasks");
            var taskListId = CSOMUtil.GetListByTitle(binderSiteClientContext, "BBHDocument Workflow Tasks");
            //Create the workflow history list
            var historyListId = service.CreateHistoryList("BBHDocument Workflow History");

            //Use the Microsoft.SharePoint.Client.WorkflowServices.WorkflowSubscriptionService to 
            //subscibe the workflow to the list the workflow is associated with, register the
            //events it is associated with, and register the tasks and history list. 
            //This method is shown below for reference.
            service.Subscribe("BBHDocument Workflow", bbhDocumentWFDefinitionId, bbhDocumentList.Id,
                WorkflowSubscritpionEventType.ItemAdded, taskListId.Id, historyListId);
        }