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); }
void jobsViewModel_OnSelectedRowsChanged() { // Get the selected bulk delete SelectedRange[] selectedRows = JobsViewModel.GetSelectedRows(); if (selectedRows.Length > 0) { ScheduledJob job = SelectedJob.GetValue(); dev1_ScheduledJob item = (dev1_ScheduledJob)JobsViewModel.GetItem(selectedRows[0].FromRow.Value); job.RecurrancePattern.SetValue(item.dev1_RecurrancePattern); RecurrancePatternMapper.DeSerialise(job, item.dev1_RecurrancePattern); job.ScheduledJobId.SetValue(item.dev1_ScheduledJobId); job.Name.SetValue(item.dev1_Name); job.StartDate.SetValue(item.dev1_StartDate); job.RecurrancePattern.SetValue(item.dev1_RecurrancePattern); EntityReference entityName = new EntityReference(null, null, item.dev1_WorkflowName); job.WorkflowId.SetValue(entityName); // Update the dependant data grid string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' returntotalrecordcount='true' no-lock='true' distinct='false' count='{0}' paging-cookie='{1}' page='{2}'> <entity name='bulkdeleteoperation'> <attribute name='name' /> <attribute name='createdon' /> <attribute name='asyncoperationid' /> <filter type='and'> <condition attribute='name' operator='like' value='%" + item.dev1_ScheduledJobId.Value + @"%' /> </filter> <link-entity name='asyncoperation' to='asyncoperationid' from='asyncoperationid' link-type='inner' alias='a0'> <attribute name='postponeuntil' alias='asyncoperation_postponeuntil' /> <attribute name='statecode' alias='asyncoperation_statecode' /> <attribute name='statuscode' alias='asyncoperation_statuscode' /> <attribute name='recurrencepattern' alias='asyncoperation_recurrencepattern' /> </link-entity>{3} </entity> </fetch>"; bulkDeleteJobsViewModel.FetchXml = fetchXml; bulkDeleteJobsViewModel.Reset(); bulkDeleteJobsViewModel.Refresh(); } }
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); }