示例#1
0
 private void BatchCreateBulkDeleteJobs(List <BulkDeleteRequest> items, Action completedCallback)
 {
     DelegateItterator.CallbackItterate(delegate(int index, Action nextCallback, ErrorCallBack errorCallBack)
     {
         BulkDeleteRequest pendingDeleteItem = items[index];
         OrganizationServiceProxy.BeginExecute(pendingDeleteItem, delegate(object result)
         {
             try
             {
                 OrganizationServiceProxy.EndExecute(result);
                 IsBusyProgress.SetValue((index / items.Count) * 100);
                 nextCallback();
             }
             catch (Exception ex)
             {
                 errorCallBack(ex);
             }
         });
     },
                                        items.Count,
                                        completedCallback,
                                        delegate(Exception ex)
     {
         // Error
         ReportError(ex);
     });
 }
示例#2
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);
                }
            });
        }
示例#3
0
        public Action DeleteCommand()
        {
            if (_deleteCommand == null)
            {
                _deleteCommand = delegate()
                {
                    // Delete all selected jobs in grid
                    SelectedRange[] ranges = JobsViewModel.GetSelectedRows();
                    List <int>      rows   = DataViewBase.RangesToRows(ranges);

                    bool confirmed = Script.Confirm(String.Format("Are you sure you want to delete these {0} job(s)?", rows.Count));
                    if (!confirmed)
                    {
                        return;
                    }



                    IsBusy.SetValue(true);
                    DelegateItterator.CallbackItterate(delegate(int index, Action nextCallback, ErrorCallBack errorCallBack)
                    {
                        dev1_ScheduledJob job = (dev1_ScheduledJob)this.JobsViewModel.GetItem(rows[index]);
                        // First delete the scheduled jobs associated
                        DeleteBulkDeleteJobs(job.dev1_ScheduledJobId, delegate(){
                            OrganizationServiceProxy.BeginDelete(dev1_ScheduledJob.EntityLogicalName, job.dev1_ScheduledJobId, delegate(object result)
                            {
                                try
                                {
                                    OrganizationServiceProxy.EndDelete(result);
                                    IsBusyProgress.SetValue((index / rows.Count) * 100);
                                    nextCallback();
                                }
                                catch (Exception ex)
                                {
                                    errorCallBack(ex);
                                }
                            });
                        });
                    },
                                                       rows.Count,
                                                       delegate()
                    {
                        // Completed
                        IsBusy.SetValue(false);
                        JobsViewModel.Reset();
                        JobsViewModel.Refresh();
                    },
                                                       delegate(Exception ex)
                    {
                        // Error
                        ReportError(ex);
                    });
                };
            }
            return(_deleteCommand);
        }
示例#4
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);
            });
        }
示例#5
0
        public Action SaveCommand()
        {
            if (_saveCommand == null)
            {
                _saveCommand = delegate()
                {
                    bool confirmed = Script.Confirm(String.Format("Are you sure save these sessions?"));
                    if (!confirmed)
                    {
                        return;
                    }

                    try
                    {
                        IsBusy.SetValue(true);
                        IsBusyProgress.SetValue(0);
                        IsBusyMessage.SetValue("Saving...");
                        // Create a an array of sessions to be saved
                        List <dev1_session> editedSessions = SessionDataView.GetEditedSessions();


                        DelegateItterator.CallbackItterate(delegate(int index, Action nextCallback, ErrorCallBack errorCallBack)
                        {
                            dev1_session session = editedSessions[index];
                            IsBusyProgress.SetValue((index / editedSessions.Count) * 100);
                            // Create/Update the session
                            if (session.dev1_sessionId == null)
                            {
                                OrganizationServiceProxy.BeginCreate(session, delegate(object result)
                                {
                                    IsBusyProgress.SetValue((index / editedSessions.Count) * 100);
                                    try
                                    {
                                        session.dev1_sessionId = OrganizationServiceProxy.EndCreate(result);
                                        session.EntityState    = EntityStates.Unchanged;
                                        session.RaisePropertyChanged("EntityState");
                                        nextCallback();
                                    }
                                    catch (Exception ex)
                                    {
                                        // TODO: Mark error row
                                        Script.Alert(ex.Message);
                                        nextCallback();
                                    }
                                });
                            }
                            else
                            {
                                OrganizationServiceProxy.BeginUpdate(session, delegate(object result)
                                {
                                    try
                                    {
                                        OrganizationServiceProxy.EndUpdate(result);
                                        session.EntityState = EntityStates.Unchanged;
                                        session.RaisePropertyChanged("EntityState");
                                        nextCallback();
                                    }
                                    catch (Exception ex)
                                    {
                                        // TODO: Mark error row
                                        Script.Alert(ex.Message);
                                        nextCallback();
                                    }
                                });
                            }
                        },
                                                           editedSessions.Count,
                                                           delegate()
                        {
                            // Completed
                            IsBusyProgress.SetValue(100);
                            IsBusy.SetValue(false);
                        },
                                                           delegate(Exception ex)
                        {
                            // Error
                            ReportError(ex);
                        });
                    }
                    catch (Exception ex)
                    {
                        ReportError(ex);
                    }
                };
            }
            return(_saveCommand);
        }
示例#6
0
        public Action DeleteCommand()
        {
            if (_deleteCommand == null)
            {
                _deleteCommand = delegate()
                {
                    List <int> selectedRows = DataViewBase.RangesToRows(this.SessionDataView.GetSelectedRows());
                    if (selectedRows.Count == 0)
                    {
                        return;
                    }

                    bool confirmed = Script.Confirm(String.Format("Are you sure you want to delete the {0} selected sessions?", selectedRows.Count));
                    if (!confirmed)
                    {
                        return;
                    }


                    IsBusyMessage.SetValue("Deleting Sessions...");
                    IsBusyProgress.SetValue(0);
                    IsBusy.SetValue(true);

                    // Get each item to remove
                    List <dev1_session> itemsToDelete = new List <dev1_session>();
                    for (int i = 0; i < selectedRows.Count; i++)
                    {
                        itemsToDelete.Add((dev1_session)this.SessionDataView.GetItem(i));
                    }
                    DelegateItterator.CallbackItterate(delegate(int index, Action nextCallback, ErrorCallBack errorCallBack)
                    {
                        dev1_session session = itemsToDelete[index];
                        IsBusyProgress.SetValue((index / selectedRows.Count) * 100);
                        OrganizationServiceProxy.BeginDelete(session.LogicalName, session.dev1_sessionId, delegate(object result)
                        {
                            try
                            {
                                OrganizationServiceProxy.EndDelete(result);
                                this.SessionDataView.RemoveItem(session);
                                this.SessionDataView.Refresh();
                                nextCallback();
                            }
                            catch (Exception ex)
                            {
                                Script.Alert(ex.Message);
                                nextCallback();
                            }
                        });
                    },
                                                       selectedRows.Count,
                                                       delegate()
                    {
                        // Complete
                        IsBusyProgress.SetValue(100);
                        IsBusy.SetValue(false);
                        SessionDataView.Refresh();
                        Days.ReCalculate();
                    },
                                                       delegate(Exception ex)
                    {
                        ReportError(ex);
                    }
                                                       );
                };
            }
            return(_deleteCommand);
        }
示例#7
0
        private void CreateBulkDeleteJobs(ScheduledJob job)
        {
            IsBusyMessage.SetValue("Creating new schedule...");
            IsBusyProgress.SetValue(0);
            // Convert bulk delete fetch into QueryExpression
            string fetchxml = "<fetch distinct='false' no-lock='false' mapping='logical'><entity name='lead'><attribute name='fullname' /><attribute name='statuscode' /><attribute name='createdon' /><attribute name='subject' /><attribute name='leadid' /><filter type='and'><condition attribute='ownerid' operator='eq-userid' /><condition attribute='statecode' operator='eq' value='0' /><condition attribute='address1_county' operator='eq' value='deleteme' /></filter><order attribute='createdon' descending='true' /></entity></fetch>";
            FetchXmlToQueryExpressionRequest convertRequest = new FetchXmlToQueryExpressionRequest();

            convertRequest.FetchXml = fetchxml;
            OrganizationServiceProxy.BeginExecute(convertRequest, delegate(object state)
            {
                FetchXmlToQueryExpressionResponse response = (FetchXmlToQueryExpressionResponse)OrganizationServiceProxy.EndExecute(state);

                List <BulkDeleteRequest> bulkDeleteRequests = new List <BulkDeleteRequest>();

                // If the recurrance is minutely, hourly, weekly we need to schedule multiple jobs
                if (job.Recurrance.GetValue().Value != RecurranceFrequencyNames.DAILY)
                {
                    DateTime startDate = DateTimeEx.UTCToLocalTimeFromSettings(job.StartDate.GetValue(), OrganizationServiceProxy.GetUserSettings());

                    DateInterval interval = DateInterval.Days;
                    int incrementAmount   = 1;
                    int dayInterval       = 1;
                    int recurranceCount   = 0;
                    int totalCount        = 0;
                    string freq           = RecurranceFrequencyNames.DAILY;

                    switch (job.Recurrance.GetValue().Value)
                    {
                    case RecurranceFrequencyNames.MINUTELY:
                        interval        = DateInterval.Minutes;
                        incrementAmount = job.RecurEvery.GetValue();
                        dayInterval     = 1;
                        recurranceCount = (60 * 24) / incrementAmount;
                        break;

                    case RecurranceFrequencyNames.HOURLY:
                        interval        = DateInterval.Hours;
                        incrementAmount = job.RecurEvery.GetValue();
                        dayInterval     = 1;
                        recurranceCount = 24 / incrementAmount;
                        break;

                    case RecurranceFrequencyNames.WEEKLY:
                    case RecurranceFrequencyNames.YEARLY:
                        // To schedule weekly, me must create a job per week day for the whole year, and set recurrance to every 365 days
                        // but this doesn't deal with leap years, so we can't do it!
                        throw new Exception("The selected schedule interval is currently not supported due to the limitation of bulk delete");
                    }

                    if (incrementAmount < 0)
                    {
                        throw new Exception("Invalid schedule");
                    }

                    // Increment in the recurrency frequence
                    for (int i = 0; i < recurranceCount; i++)
                    {
                        BulkDeleteRequest request     = new BulkDeleteRequest();
                        request.QuerySet              = response.Query.Replace(@"<d:anyType ", @"<d:anyType xmlns:e=""http://www.w3.org/2001/XMLSchema"" ");
                        request.SendEmailNotification = false;
                        request.StartDateTime         = startDate;
                        request.RecurrencePattern     = "FREQ=DAILY;INTERVAL=" + dayInterval.ToString();
                        request.JobName = "Scheduled Job " + i.Format("0000") + " " + job.ScheduledJobId.GetValue().Value;
                        ArrayEx.Add(bulkDeleteRequests, request);
                        startDate = DateTimeEx.DateAdd(interval, incrementAmount, startDate);
                    }
                }
                else
                {
                    // Just a single request
                    BulkDeleteRequest request     = new BulkDeleteRequest();
                    request.QuerySet              = response.Query.Replace(@"<d:anyType ", @"<d:anyType xmlns:e=""http://www.w3.org/2001/XMLSchema"" ");
                    request.SendEmailNotification = false;
                    request.StartDateTime         = job.StartDate.GetValue();
                    request.RecurrencePattern     = RecurrancePatternMapper.Serialise(job);
                    request.JobName = "Scheduled Job " + job.ScheduledJobId.GetValue().Value;
                    ArrayEx.Add(bulkDeleteRequests, request);
                }

                BatchCreateBulkDeleteJobs(bulkDeleteRequests, delegate()
                {
                    IsBusy.SetValue(false);
                    JobsViewModel.Reset();
                    JobsViewModel.Refresh();
                });
            });
        }
示例#8
0
        public Action SaveCommand()
        {
            if (_saveCommand == null)
            {
                _saveCommand = delegate()
                {
                    if (!((IValidatedObservable)SelectedJob).IsValid())
                    {
                        ValidationErrors validationResult = ValidationApi.Group(SelectedJob.GetValue());
                        validationResult.ShowAllMessages(true);
                        return;
                    }

                    bool confirmed = Script.Confirm(String.Format("Are you sure you want to save this schedule?"));
                    if (!confirmed)
                    {
                        return;
                    }


                    IsBusy.SetValue(true);
                    IsBusyProgress.SetValue(0);
                    IsBusyMessage.SetValue("Saving...");



                    // Create a new Scheduled Job
                    dev1_ScheduledJob jobToSave = new dev1_ScheduledJob();
                    ScheduledJob      job       = this.SelectedJob.GetValue();
                    jobToSave.dev1_Name         = job.Name.GetValue();
                    jobToSave.dev1_StartDate    = job.StartDate.GetValue();
                    jobToSave.dev1_WorkflowName = job.WorkflowId.GetValue().Name;

                    jobToSave.dev1_RecurrancePattern = RecurrancePatternMapper.Serialise(job);

                    if (job.ScheduledJobId.GetValue() == null)
                    {
                        // Create the schedule

                        OrganizationServiceProxy.BeginCreate(jobToSave, delegate(object createJobResponse)
                        {
                            try
                            {
                                job.ScheduledJobId.SetValue(OrganizationServiceProxy.EndCreate(createJobResponse));
                                CreateBulkDeleteJobs(job);
                            }
                            catch (Exception ex)
                            {
                                ReportError(ex);
                            }
                        });
                    }
                    else
                    {
                        jobToSave.dev1_ScheduledJobId = job.ScheduledJobId.GetValue();
                        // Update the schedule
                        OrganizationServiceProxy.BeginUpdate(jobToSave, delegate(object createJobResponse)
                        {
                            try
                            {
                                OrganizationServiceProxy.EndUpdate(createJobResponse);
                                DeleteBulkDeleteJobs(job.ScheduledJobId.GetValue(), delegate()
                                {
                                    // Create new jobs
                                    CreateBulkDeleteJobs(job);
                                });
                            }
                            catch (Exception ex)
                            {
                                ReportError(ex);
                            }
                        });
                    }
                };
            }

            return(_saveCommand);
        }