Пример #1
0
        private void DeleteBulkDeleteJobs(Guid scheduledJobId, Action callback)
        {
            IsBusyMessage.SetValue("Deleting existing schedule...");
            // Get each bulk delete using the name = Scheduled Job {xxxx}
            string fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                              "<entity name='bulkdeleteoperation'>" +
                              "<attribute name='name' />" +
                              "<attribute name='asyncoperationid' />" +
                              "<link-entity name='asyncoperation' alias='a0' to='asyncoperationid' from='asyncoperationid'>" +
                              "<attribute name='statecode' alias='asyncoperation_statecode'/>" +
                              "<attribute name='statuscode'  alias='asyncoperation_statuscode'/>" +
                              "</link-entity>" +
                              "<filter type='and'>" +
                              "<condition attribute='name' operator='like' value='%" + scheduledJobId.ToString() + "%' />" +
                              "</filter>" +
                              "</entity>" +
                              "</fetch>";

            OrganizationServiceProxy.BeginRetrieveMultiple(fetchXml, delegate(object fetchJobsResponse)
            {
                try
                {
                    // For each item, delete
                    EntityCollection jobs            = OrganizationServiceProxy.EndRetrieveMultiple(fetchJobsResponse, typeof(BulkDeleteOperation));
                    List <PendingDelete> deleteItems = new List <PendingDelete>();

                    IsBusyProgress.SetValue(0);

                    foreach (BulkDeleteOperation item in jobs.Entities)
                    {
                        // First delete the job
                        PendingDelete deleteJobOperationRequest = new PendingDelete();
                        deleteJobOperationRequest.entityName    = BulkDeleteOperation.EntityLogicalName;
                        deleteJobOperationRequest.id            = item.BulkDeleteOperationId;
                        ArrayEx.Add(deleteItems, deleteJobOperationRequest);


                        // then the async operation
                        PendingDelete deleteAsyncOperationRequest = new PendingDelete();
                        deleteAsyncOperationRequest.entityName    = asyncoperation.EntityLogicalName;
                        deleteAsyncOperationRequest.id            = item.AsyncOperationId.Id;

                        // if the job is suspended/waiting then cancel
                        deleteAsyncOperationRequest.cancelFirst = (item.AsyncOperation_StateCode.Value == 1);
                        ArrayEx.Add(deleteItems, deleteAsyncOperationRequest);
                    }

                    // Delete each in turn

                    DeleteJob(deleteItems, callback);
                }
                catch (Exception ex)
                {
                    ReportError(ex);
                }
            });
        }
Пример #2
0
        private void DeleteJob(List <PendingDelete> items, Action completedCallback)
        {
            DelegateItterator.CallbackItterate(delegate(int index, Action nextCallback, ErrorCallBack errorCallBack)
            {
                // Do work
                PendingDelete pendingDeleteItem = items[index];

                if (pendingDeleteItem.cancelFirst)
                {
                    // If the operation is not completed, we need to cancle it first
                    // TODO: Note this will fail if waiting for resources/in progress - so we should add a wait here until finished.
                    asyncoperation operationToUpdate   = new asyncoperation();
                    operationToUpdate.AsyncOperationId = pendingDeleteItem.id;
                    operationToUpdate.Id        = operationToUpdate.AsyncOperationId.Value;
                    operationToUpdate.StateCode = new OptionSetValue(3);
                    OrganizationServiceProxy.Update(operationToUpdate);
                }
                OrganizationServiceProxy.BeginDelete(pendingDeleteItem.entityName, pendingDeleteItem.id, delegate(object result)
                {
                    try
                    {
                        OrganizationServiceProxy.EndDelete(result);
                        IsBusyProgress.SetValue((index / items.Count) * 100);
                        nextCallback();
                    }
                    catch (Exception ex)
                    {
                        errorCallBack(ex);
                    }
                });
            },
                                               items.Count,
                                               completedCallback,
                                               delegate(Exception ex)
            {
                // Error
                ReportError(ex);
            });
        }
        private void DeleteBulkDeleteJobs(Guid scheduledJobId, Action callback)
        {
            IsBusyMessage.SetValue("Deleting existing schedule...");
            // Get each bulk delete using the name = Scheduled Job {xxxx}
            string fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                      "<entity name='bulkdeleteoperation'>" +
                        "<attribute name='name' />" +
                        "<attribute name='asyncoperationid' />" +
                          "<link-entity name='asyncoperation' alias='a0' to='asyncoperationid' from='asyncoperationid'>" +
                          "<attribute name='statecode' alias='asyncoperation_statecode'/>"+
                          "<attribute name='statuscode'  alias='asyncoperation_statuscode'/>" +
                          "</link-entity>"+
                        "<filter type='and'>" +
                          "<condition attribute='name' operator='like' value='%" + scheduledJobId.ToString() + "%' />" +
                        "</filter>" +
                      "</entity>" +
                    "</fetch>";

            OrganizationServiceProxy.BeginRetrieveMultiple(fetchXml, delegate(object fetchJobsResponse)
            {
                try
                {
                    // For each item, delete
                    EntityCollection jobs = OrganizationServiceProxy.EndRetrieveMultiple(fetchJobsResponse, typeof(BulkDeleteOperation));
                    List<PendingDelete> deleteItems = new List<PendingDelete>();

                    IsBusyProgress.SetValue(0);
 
                    foreach (BulkDeleteOperation item in jobs.Entities)
                    {
                        // First delete the job
                        PendingDelete deleteJobOperationRequest = new PendingDelete();
                        deleteJobOperationRequest.entityName = BulkDeleteOperation.EntityLogicalName;
                        deleteJobOperationRequest.id = item.BulkDeleteOperationId;
                        ArrayEx.Add(deleteItems, deleteJobOperationRequest);
                       

                        // then the async operation
                        PendingDelete deleteAsyncOperationRequest = new PendingDelete();
                        deleteAsyncOperationRequest.entityName = asyncoperation.EntityLogicalName;
                        deleteAsyncOperationRequest.id = item.AsyncOperationId.Id;

                        // if the job is suspended/waiting then cancel
                        deleteAsyncOperationRequest.cancelFirst = (item.AsyncOperation_StateCode.Value == 1);
                        ArrayEx.Add(deleteItems, deleteAsyncOperationRequest);
                        
                    }

                    // Delete each in turn
                   
                    DeleteJob(deleteItems, callback); 
                    
                }
                catch (Exception ex)
                {
                    ReportError(ex);
                }

            });

        }