private void Disable()
 {
     Parallel.ForEach(workflows, entity =>
     {
         crmService.ExecuteRequest(new SetStateRequest
         {
             EntityMoniker = entity.ToEntityReference(),
             State         = new OptionSetValue(1),
             Status        = new OptionSetValue(2)
         });
     });
 }
        public void ExecuteDeleteSteps(ICrmService crmService)
        {
            var requestsQueue = new Queue <OrganizationRequest>(deleteStageSteps);

            while (requestsQueue.Count > 0)
            {
                var request = requestsQueue.Dequeue();
                try
                {
                    var res = crmService.ExecuteRequest(request);
                }
                catch (Exception e)
                {
                    string message = e.Message;

                    if (request is DeleteRequest deleteRequest)
                    {
                        var target = deleteRequest.Target;
                        message = $"Error while trying to delete {target.LogicalName}/{target.Id}: {message}";
                    }

                    Log.Error(message, e);
                    Debugger.Break();
                }
            }
        }
        public void ExecuteUpdateSteps(ICrmService crmService)
        {
            var requestsQueue = new Queue <OrganizationRequest>(updateStageSteps);

            do
            {
                var requestsChunk = ToOrganizationRequestCollection(DequeueChunk(requestsQueue, 1000));

                if (requestsChunk.Count == 0)
                {
                    break;
                }


                var transactionalRequest = new ExecuteTransactionRequest
                {
                    ReturnResponses = true,
                    Requests        = requestsChunk
                };

                var res = crmService.ExecuteRequest(transactionalRequest);
            } while (true);
        }