예제 #1
0
        public static string Serialise(ScheduledJob scheduledJob)
        {
           
            List<string> parts = new List<string>();

            ArrayEx.Add(parts, "FREQ=" + scheduledJob.Recurrance.GetValue().Value);
            ArrayEx.Add(parts, "INTERVAL=" + scheduledJob.RecurEvery.GetValue().ToString());

            if (scheduledJob.Recurrance.GetValue().Value == RecurranceFrequencyNames.WEEKLY)
            {
                List<string> days = new List<string>();
                if (scheduledJob.Monday.GetValue()) days.Add(DayNames.Monday);
                if (scheduledJob.Tuesday.GetValue()) days.Add(DayNames.Tuesday);
                if (scheduledJob.Wednesday.GetValue()) days.Add(DayNames.Wednesday);
                if (scheduledJob.Thursday.GetValue()) days.Add(DayNames.Thursday);
                if (scheduledJob.Friday.GetValue()) days.Add(DayNames.Friday);
                if (scheduledJob.Saturday.GetValue()) days.Add(DayNames.Saturday);
                if (scheduledJob.Sunday.GetValue()) days.Add(DayNames.Sunday);
                if (days.Count > 0)
                    ArrayEx.Add(parts, "BYDAY=" + days.Join(","));

            }

            if (!scheduledJob.NoEndDate.GetValue())
            {
                ArrayEx.Add(parts, "COUNT=" + scheduledJob.Count.GetValue());
            }
            string pattern = parts.Join(";");
            return pattern;
        }
예제 #2
0
        public static string Serialise(ScheduledJob scheduledJob)
        {
            List <string> parts = new List <string>();

            ArrayEx.Add(parts, "FREQ=" + scheduledJob.Recurrance.GetValue().Value);
            ArrayEx.Add(parts, "INTERVAL=" + scheduledJob.RecurEvery.GetValue().ToString());

            if (scheduledJob.Recurrance.GetValue().Value == RecurranceFrequencyNames.WEEKLY)
            {
                List <string> days = new List <string>();
                if (scheduledJob.Monday.GetValue())
                {
                    days.Add(DayNames.Monday);
                }
                if (scheduledJob.Tuesday.GetValue())
                {
                    days.Add(DayNames.Tuesday);
                }
                if (scheduledJob.Wednesday.GetValue())
                {
                    days.Add(DayNames.Wednesday);
                }
                if (scheduledJob.Thursday.GetValue())
                {
                    days.Add(DayNames.Thursday);
                }
                if (scheduledJob.Friday.GetValue())
                {
                    days.Add(DayNames.Friday);
                }
                if (scheduledJob.Saturday.GetValue())
                {
                    days.Add(DayNames.Saturday);
                }
                if (scheduledJob.Sunday.GetValue())
                {
                    days.Add(DayNames.Sunday);
                }
                if (days.Count > 0)
                {
                    ArrayEx.Add(parts, "BYDAY=" + days.Join(","));
                }
            }

            if (!scheduledJob.NoEndDate.GetValue())
            {
                ArrayEx.Add(parts, "COUNT=" + scheduledJob.Count.GetValue());
            }
            string pattern = parts.Join(";");

            return(pattern);
        }
예제 #3
0
        public Action NewCommand()
        {
            if (_newCommand == null)
            {
                _newCommand = delegate()
                {
                    // Remove selected rows
                    SelectedRange[] rows = new SelectedRange[0];
                    this.JobsViewModel.RaiseOnSelectedRowsChanged(rows);

                    // Create new schedule
                    ScheduledJob job = SelectedJob.GetValue();
                    job.Reset();
                };
            }
            return(_newCommand);
        }
예제 #4
0
        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();
            }
        }
예제 #5
0
        public static void DeSerialise(ScheduledJob scheduledJob, string patternString)
        {
             
            // Unpack the pattern
            string[] pattern = patternString.Split(";");
            bool mon = false, tue = false, wed = false, thu = false, fri = false, sat = false, sun = false;
            int interval = 1;
            int? count = null;
            RecurranceFrequency frequency = null;

            foreach (string part in pattern)
            {
                string[] value = part.Split("=");

                switch (value[0])
                {
                    case "FREQ":
                        for (int i = 0; i < RecurrancePatternMapper.RecurranceFrequencies.Length; i++)
                        {
                            if (value[1] == RecurrancePatternMapper.RecurranceFrequencies[i].Value)
                            {
                                frequency = RecurrancePatternMapper.RecurranceFrequencies[i];
                                break;
                            }
                        }
                        break;
                    case "COUNT":
                        count = int.Parse(value[1]);
                        break;
                    case "INTERVAL":
                        interval = int.Parse(value[1]);
                        break;
                    case "BYDAY":
                        string[] days = value[1].Split(",");

                        foreach (string day in days)
                        {
                            switch (day)
                            {
                                case DayNames.Monday:
                                    mon = true;
                                    break;
                                case DayNames.Tuesday:
                                    tue = true;
                                    break;
                                case DayNames.Wednesday:
                                    wed = true;
                                    break;
                                case DayNames.Thursday:
                                    thu = true;
                                    break;
                                case DayNames.Friday:
                                    fri = true;
                                    break;
                                case DayNames.Saturday:
                                    sat = true;
                                    break;
                                case DayNames.Sunday:
                                    sun = true;
                                    break;

                            }


                        }
                        break;
                }


            }
            // Set Values

            
            scheduledJob.Recurrance.SetValue(frequency);
            scheduledJob.Monday.SetValue(mon);
            scheduledJob.Tuesday.SetValue(tue);
            scheduledJob.Wednesday.SetValue(wed);
            scheduledJob.Thursday.SetValue(thu);
            scheduledJob.Friday.SetValue(fri);
            scheduledJob.Saturday.SetValue(sat);
            scheduledJob.Sunday.SetValue(sun);
            scheduledJob.RecurEvery.SetValue(interval);
            scheduledJob.Count.SetValue(count);
            scheduledJob.NoEndDate.SetValue(count == null);
        
        }
        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();
                   
                });

              

            });

        }
예제 #7
0
        public static void DeSerialise(ScheduledJob scheduledJob, string patternString)
        {
            // Unpack the pattern
            string[]            pattern = patternString.Split(";");
            bool                mon = false, tue = false, wed = false, thu = false, fri = false, sat = false, sun = false;
            int                 interval  = 1;
            int?                count     = null;
            RecurranceFrequency frequency = null;

            foreach (string part in pattern)
            {
                string[] value = part.Split("=");

                switch (value[0])
                {
                case "FREQ":
                    for (int i = 0; i < RecurrancePatternMapper.RecurranceFrequencies.Length; i++)
                    {
                        if (value[1] == RecurrancePatternMapper.RecurranceFrequencies[i].Value)
                        {
                            frequency = RecurrancePatternMapper.RecurranceFrequencies[i];
                            break;
                        }
                    }
                    break;

                case "COUNT":
                    count = int.Parse(value[1]);
                    break;

                case "INTERVAL":
                    interval = int.Parse(value[1]);
                    break;

                case "BYDAY":
                    string[] days = value[1].Split(",");

                    foreach (string day in days)
                    {
                        switch (day)
                        {
                        case DayNames.Monday:
                            mon = true;
                            break;

                        case DayNames.Tuesday:
                            tue = true;
                            break;

                        case DayNames.Wednesday:
                            wed = true;
                            break;

                        case DayNames.Thursday:
                            thu = true;
                            break;

                        case DayNames.Friday:
                            fri = true;
                            break;

                        case DayNames.Saturday:
                            sat = true;
                            break;

                        case DayNames.Sunday:
                            sun = true;
                            break;
                        }
                    }
                    break;
                }
            }
            // Set Values


            scheduledJob.Recurrance.SetValue(frequency);
            scheduledJob.Monday.SetValue(mon);
            scheduledJob.Tuesday.SetValue(tue);
            scheduledJob.Wednesday.SetValue(wed);
            scheduledJob.Thursday.SetValue(thu);
            scheduledJob.Friday.SetValue(fri);
            scheduledJob.Saturday.SetValue(sat);
            scheduledJob.Sunday.SetValue(sun);
            scheduledJob.RecurEvery.SetValue(interval);
            scheduledJob.Count.SetValue(count);
            scheduledJob.NoEndDate.SetValue(count == null);
        }
예제 #8
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();
                });
            });
        }
예제 #9
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);
        }