コード例 #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 void ProvisionIncidentWorkflowAndRelatedLists(string incidentWorkflowFile, string suiteLevelWebAppUrl, string dispatcherName)
        {
            var incidentsList = CSOMUtil.GetListByTitle(clientContext, "Incidents");

            var service    = new WorkflowProvisionService(clientContext);
            var incidentWF = System.IO.File.ReadAllText(incidentWorkflowFile)
                             .Replace("(SuiteLevelWebAppUrlPlaceholder)", suiteLevelWebAppUrl)
                             .Replace("(dispatcherPlaceHolder)", dispatcherName);
            var incidentWFDefinitionId = service.SaveDefinitionAndPublish("Incident",
                                                                          WorkflowUtil.TranslateWorkflow(incidentWF));
            var taskListId    = service.CreateTaskList("Incident Workflow Tasks");
            var historyListId = service.CreateHistoryList("Incident Workflow History");

            service.Subscribe("Incident Workflow", incidentWFDefinitionId, incidentsList.Id,
                              WorkflowSubscritpionEventType.ItemAdded, taskListId, historyListId);
        }
コード例 #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);
        }