public void RemoveIncidentWorkflowAndRelatedLists()
        {
            var incidentsList = CSOMUtil.GetListByTitle(clientContext, "Incidents");

            var service = new WorkflowProvisionService(clientContext);
            service.Unsubscribe(incidentsList.Id, "Incident");
            service.DeleteDefinitions("Incident");
            service.DeleteList("Incident Workflow Tasks");
            service.DeleteList("Incident Workflow History");
        }
        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);
        }
        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();
        }