private void WriteSubscriptionInstances(List list, WorkflowInstanceService deploymentService, WorkflowSubscription workflowSubscription) { Instances = new List <SPWorkflowInstance>(); if (workflowSubscription != null && !workflowSubscription.ServerObjectIsNull()) { var countTerminated = deploymentService.CountInstancesWithStatus(workflowSubscription, WorkflowStatus.Terminated); var countSuspended = deploymentService.CountInstancesWithStatus(workflowSubscription, WorkflowStatus.Suspended); var countInvalid = deploymentService.CountInstancesWithStatus(workflowSubscription, WorkflowStatus.Invalid); var countCancelled = deploymentService.CountInstancesWithStatus(workflowSubscription, WorkflowStatus.Canceled); var countCanceling = deploymentService.CountInstancesWithStatus(workflowSubscription, WorkflowStatus.Canceling); var countStarted = deploymentService.CountInstancesWithStatus(workflowSubscription, WorkflowStatus.Started); var countNotStarted = deploymentService.CountInstancesWithStatus(workflowSubscription, WorkflowStatus.NotStarted); var countNotSpecified = deploymentService.CountInstancesWithStatus(workflowSubscription, WorkflowStatus.NotSpecified); ClientContext.ExecuteQueryRetry(); LogVerbose("Terminated => {0}", countTerminated.Value); LogVerbose("Suspended => {0}", countSuspended.Value); LogVerbose("Invalid => {0}", countInvalid.Value); LogVerbose("Canceled => {0}", countCancelled.Value); LogVerbose("Canceling => {0}", countCanceling.Value); LogVerbose("Started => {0}", countStarted.Value); LogVerbose("NotStarted => {0}", countNotStarted.Value); LogVerbose("NotSpecified => {0}", countNotSpecified.Value); if (!DeepScan) { var instances = deploymentService.Enumerate(workflowSubscription); ClientContext.Load(instances); ClientContext.ExecuteQueryRetry(); LogVerbose($"Instance {instances.Count}..."); foreach (var instance in instances) { Instances.Add(new SPWorkflowInstance(instance)); } } else { var idx = 1; var viewCaml = new CamlQuery() { ViewXml = CAML.ViewQuery(string.Empty, string.Empty, 100), ListItemCollectionPosition = null }; do { LogVerbose($"Deep search itr=>{idx++} paging => {viewCaml.ListItemCollectionPosition?.PagingInfo}"); var items = list.GetItems(viewCaml); this.ClientContext.Load(items, ftx => ftx.ListItemCollectionPosition, ftx => ftx.Include(ftcx => ftcx.Id, ftcx => ftcx.ParentList.Id)); this.ClientContext.ExecuteQueryRetry(); viewCaml.ListItemCollectionPosition = items.ListItemCollectionPosition; foreach (var item in items) { // Load ParentList ID to Pull Workflow Instances var allinstances = ClientContext.Web.GetWorkflowInstances(item); if (allinstances.Any()) { foreach (var instance in allinstances) { Instances.Add(new SPWorkflowInstance(instance, item.Id)); } } } }while (viewCaml.ListItemCollectionPosition != null); } } }