private void CleanupWorkflowDefinitionsAndSubscriptions(Microsoft.SharePoint.Client.Web web) { // Get a reference to infrastructural services Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager servicesManager = null; try { servicesManager = new Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager(web.Context, web); } catch (ServerException) { // If there is no workflow service present in the farm this method will throw an error. // Swallow the exception } if (servicesManager != null) { var deploymentService = servicesManager.GetWorkflowDeploymentService(); var subscriptionService = servicesManager.GetWorkflowSubscriptionService(); if (subscriptionService != null) { var subscription = subscriptionService.GetSubscription(this._wfSubscriptionId); web.Context.Load(subscription); web.Context.ExecuteQueryRetry(); if (!subscription.ServerObjectIsNull()) { subscriptionService.DeleteSubscription(this._wfSubscriptionId); web.Context.ExecuteQueryRetry(); } } if (deploymentService != null) { var definition = deploymentService.GetDefinition(this._wfDefinitionId); web.Context.Load(definition); web.Context.ExecuteQueryRetry(); if (!definition.ServerObjectIsNull()) { deploymentService.DeleteDefinition(this._wfDefinitionId); web.Context.ExecuteQueryRetry(); } } } }
private void ExecuteCmdletByListItem() { List list = null; ListItem listitem = null; if (List != null) { list = List.GetList(SelectedWeb); if (list == null) { throw new PSArgumentException($"No list found with id, title or url '{List}'", nameof(List)); } } else { throw new PSArgumentException("List required"); } if (ListItem != null) { listitem = ListItem.GetListItem(list); if (listitem == null) { throw new PSArgumentException($"No list item found with id, or title '{ListItem}'", nameof(ListItem)); } } else { throw new PSArgumentException("List Item required"); } var workflowServicesManager = new Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager(ClientContext, SelectedWeb); var workflowInstanceService = workflowServicesManager.GetWorkflowInstanceService(); var workflows = workflowInstanceService.EnumerateInstancesForListItem(list.Id, listitem.Id); ClientContext.Load(workflows); ClientContext.ExecuteQueryRetry(); WriteObject(workflows, true); }