예제 #1
0
        public ScheduleRecurringOptionsForm()
        {
            InitializeComponent();

            this.CancelEvent  += form_CancelEvent;
            this.ConfirmEvent += form_ConfirmEvent;

            // Setup defaults and data bindings
            this.ModelChangedEvent += (sender, args) =>
            {
                this.Schedule = args.Model as Models.PlanSchedule;

                NUnit.Framework.Assert.AreEqual(Models.ScheduleTypeEnum.RECURRING, this.Schedule.ScheduleType);

                // Remove all data bindings
                ClearBindings();

                // Load Model default values
                ModelDefaults();

                // Setup Form state based on Model
                ModelToForm();

                // Setup data bindings between Form <=> Model
                WireBindings();
            };
        }
예제 #2
0
        private Trigger[] BuildTriggers(Models.ISchedulablePlan plan)
        {
            List <Trigger> triggers = new List <Trigger>();

            Models.PlanSchedule schedule = plan.Schedule;
            switch (schedule.ScheduleType)
            {
            case Models.ScheduleTypeEnum.RUN_MANUALLY:
            {
                break;
            }

            case Models.ScheduleTypeEnum.SPECIFIC:
            {
                DateTime?optional = schedule.OccursSpecificallyAt;
                if (!optional.HasValue)
                {
                    break;
                }

                DateTime whenToStart = optional.Value;

                Trigger tr = Trigger.CreateTrigger(TaskTriggerType.Time);

                // When to start?
                tr.StartBoundary = whenToStart.ToLocalTime();

                triggers.Add(tr);
                break;
            }

            case Models.ScheduleTypeEnum.RECURRING:
            {
                if (!schedule.RecurrencyFrequencyType.HasValue)
                {
                    break;
                }

                Trigger tr = null;

                switch (schedule.RecurrencyFrequencyType.Value)
                {
                case Models.FrequencyTypeEnum.DAILY:
                {
                    tr = Trigger.CreateTrigger(TaskTriggerType.Daily);

                    if (schedule.IsRecurrencyDailyFrequencySpecific)
                    {
                        // Repetition - Occurs every day
                        tr.Repetition.Interval = TimeSpan.FromDays(1);
                    }

                    break;
                }

                case Models.FrequencyTypeEnum.WEEKLY:
                {
                    if (schedule.OccursAtDaysOfWeek == null || schedule.OccursAtDaysOfWeek.Count == 0)
                    {
                        break;
                    }

                    tr = Trigger.CreateTrigger(TaskTriggerType.Weekly);

                    WeeklyTrigger wt = tr as WeeklyTrigger;

                    // IMPORTANT: The default constructed `WeeklyTrigger` sets Sunday.
                    wt.DaysOfWeek = 0;

                    Models.PlanScheduleDayOfWeek matchDay = null;

                    matchDay = schedule.OccursAtDaysOfWeek.SingleOrDefault(p => p.DayOfWeek == DayOfWeek.Monday);
                    if (matchDay != null)
                    {
                        wt.DaysOfWeek |= DaysOfTheWeek.Monday;
                    }

                    matchDay = schedule.OccursAtDaysOfWeek.SingleOrDefault(p => p.DayOfWeek == DayOfWeek.Tuesday);
                    if (matchDay != null)
                    {
                        wt.DaysOfWeek |= DaysOfTheWeek.Tuesday;
                    }

                    matchDay = schedule.OccursAtDaysOfWeek.SingleOrDefault(p => p.DayOfWeek == DayOfWeek.Wednesday);
                    if (matchDay != null)
                    {
                        wt.DaysOfWeek |= DaysOfTheWeek.Wednesday;
                    }

                    matchDay = schedule.OccursAtDaysOfWeek.SingleOrDefault(p => p.DayOfWeek == DayOfWeek.Thursday);
                    if (matchDay != null)
                    {
                        wt.DaysOfWeek |= DaysOfTheWeek.Thursday;
                    }

                    matchDay = schedule.OccursAtDaysOfWeek.SingleOrDefault(p => p.DayOfWeek == DayOfWeek.Friday);
                    if (matchDay != null)
                    {
                        wt.DaysOfWeek |= DaysOfTheWeek.Friday;
                    }

                    matchDay = schedule.OccursAtDaysOfWeek.SingleOrDefault(p => p.DayOfWeek == DayOfWeek.Saturday);
                    if (matchDay != null)
                    {
                        wt.DaysOfWeek |= DaysOfTheWeek.Saturday;
                    }

                    matchDay = schedule.OccursAtDaysOfWeek.SingleOrDefault(p => p.DayOfWeek == DayOfWeek.Sunday);
                    if (matchDay != null)
                    {
                        wt.DaysOfWeek |= DaysOfTheWeek.Sunday;
                    }

                    break;
                }

                case Models.FrequencyTypeEnum.MONTHLY:
                {
                    if (!schedule.MonthlyOccurrenceType.HasValue || !schedule.OccursMonthlyAtDayOfWeek.HasValue)
                    {
                        break;
                    }

                    tr = Trigger.CreateTrigger(TaskTriggerType.MonthlyDOW);

                    MonthlyDOWTrigger mt = tr as MonthlyDOWTrigger;

                    switch (schedule.MonthlyOccurrenceType.Value)
                    {
                    case Models.MonthlyOccurrenceTypeEnum.FIRST:
                        mt.WeeksOfMonth = WhichWeek.FirstWeek;
                        break;

                    case Models.MonthlyOccurrenceTypeEnum.SECOND:
                        mt.WeeksOfMonth = WhichWeek.SecondWeek;
                        break;

                    case Models.MonthlyOccurrenceTypeEnum.THIRD:
                        mt.WeeksOfMonth = WhichWeek.ThirdWeek;
                        break;

                    case Models.MonthlyOccurrenceTypeEnum.FOURTH:
                        mt.WeeksOfMonth = WhichWeek.FourthWeek;
                        break;

                    case Models.MonthlyOccurrenceTypeEnum.PENULTIMATE:
                        mt.WeeksOfMonth = WhichWeek.ThirdWeek;
                        break;

                    case Models.MonthlyOccurrenceTypeEnum.LAST:
                        mt.WeeksOfMonth = WhichWeek.LastWeek;
                        break;
                    }

                    switch (schedule.OccursMonthlyAtDayOfWeek.Value)
                    {
                    case DayOfWeek.Monday:
                        mt.DaysOfWeek = DaysOfTheWeek.Monday;
                        break;

                    case DayOfWeek.Tuesday:
                        mt.DaysOfWeek = DaysOfTheWeek.Tuesday;
                        break;

                    case DayOfWeek.Wednesday:
                        mt.DaysOfWeek = DaysOfTheWeek.Wednesday;
                        break;

                    case DayOfWeek.Thursday:
                        mt.DaysOfWeek = DaysOfTheWeek.Thursday;
                        break;

                    case DayOfWeek.Friday:
                        mt.DaysOfWeek = DaysOfTheWeek.Friday;
                        break;

                    case DayOfWeek.Saturday:
                        mt.DaysOfWeek = DaysOfTheWeek.Saturday;
                        break;

                    case DayOfWeek.Sunday:
                        mt.DaysOfWeek = DaysOfTheWeek.Sunday;
                        break;
                    }

                    break;
                }

                case Models.FrequencyTypeEnum.DAY_OF_MONTH:
                {
                    if (!schedule.OccursAtDayOfMonth.HasValue)
                    {
                        break;
                    }

                    tr = Trigger.CreateTrigger(TaskTriggerType.Monthly);

                    MonthlyTrigger mt = tr as MonthlyTrigger;

                    //
                    // TODO: What happens if the specified day is >=29 and we are in February?
                    //
                    mt.DaysOfMonth = new int[] { schedule.OccursAtDayOfMonth.Value };

                    break;
                }
                }

                if (tr == null)
                {
                    break;
                }

                // When to start?
                DateTime now = DateTime.UtcNow;
                if (schedule.IsRecurrencyDailyFrequencySpecific)
                {
                    TimeSpan?optional = schedule.RecurrencySpecificallyAtTime;
                    if (!optional.HasValue)
                    {
                        break;
                    }

                    TimeSpan time = optional.Value;
                    tr.StartBoundary = new DateTime(now.Year, now.Month, now.Day, time.Hours, time.Minutes, time.Seconds);
                }
                else
                {
                    tr.StartBoundary = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);                                     // Start of day.
                }

                // Repetition - Occurs every interval
                if (!schedule.IsRecurrencyDailyFrequencySpecific)
                {
                    switch (schedule.RecurrencyTimeUnit.Value)
                    {
                    case Models.TimeUnitEnum.HOURS:
                        tr.Repetition.Interval = TimeSpan.FromHours(schedule.RecurrencyTimeInterval.Value);
                        break;

                    case Models.TimeUnitEnum.MINUTES:
                        tr.Repetition.Interval = TimeSpan.FromMinutes(schedule.RecurrencyTimeInterval.Value);
                        break;
                    }
                }

                // Window limits
                if (!schedule.IsRecurrencyDailyFrequencySpecific)
                {
                    if (schedule.RecurrencyWindowStartsAtTime.HasValue && schedule.RecurrencyWindowEndsAtTime.HasValue)
                    {
                        tr.Repetition.StopAtDurationEnd = false;

                        TimeSpan window = schedule.RecurrencyWindowEndsAtTime.Value - schedule.RecurrencyWindowStartsAtTime.Value;

                        tr.Repetition.Duration = window;
                        //tr.ExecutionTimeLimit = window;
                    }
                }

                triggers.Add(tr);
                break;
            }
            }

            if (triggers.Count == 0)
            {
                Warn("No task was created for {0}", BuildTaskName(plan));
            }

            return(triggers.ToArray());
        }
예제 #3
0
        public override void OnFinish()
        {
            base.OnFinish();

            Models.BackupPlan plan = Model as Models.BackupPlan;

            Console.WriteLine("Name                  = {0}", plan.Name);
            Console.WriteLine("StorageAccount        = {0}", plan.StorageAccount.DisplayName);
            Console.WriteLine("StorageAccountType    = {0}", plan.StorageAccountType.ToString());
            foreach (Models.BackupPlanSourceEntry entry in plan.SelectedSources)
            {
                Console.WriteLine("SelectedSource => #{0}, {1}, {2}", entry.Id, entry.Type.ToString(), entry.Path);
            }
            Console.WriteLine("ScheduleType          = {0}", plan.ScheduleType.ToString());
            Console.WriteLine("Schedule.ScheduleType = {0}", plan.Schedule.ScheduleType.ToString());

            Models.PlanSchedule schedule = plan.Schedule;
            switch (plan.ScheduleType)
            {
            case Models.ScheduleTypeEnum.RUN_MANUALLY:
                break;

            case Models.ScheduleTypeEnum.SPECIFIC:
                Console.WriteLine("OccursSpecificallyAt  = {0}", schedule.OccursSpecificallyAt.HasValue ? schedule.OccursSpecificallyAt.Value.ToString() : "null");
                break;

            case Models.ScheduleTypeEnum.RECURRING:
                Console.WriteLine("RecurrencyFrequencyType      = {0}",
                                  schedule.RecurrencyFrequencyType.HasValue ? schedule.RecurrencyFrequencyType.Value.ToString() : "null");
                Console.WriteLine("RecurrencyDailyFrequencyType = {0}",
                                  schedule.RecurrencyDailyFrequencyType.HasValue ? schedule.RecurrencyDailyFrequencyType.Value.ToString() : "null");

                if (schedule.RecurrencyFrequencyType.HasValue)
                {
                    switch (schedule.RecurrencyFrequencyType.Value)
                    {
                    case Models.FrequencyTypeEnum.DAILY:
                        break;

                    case Models.FrequencyTypeEnum.WEEKLY:
                        Console.WriteLine("OccursAtDaysOfWeek           = {0}",
                                          schedule.OccursAtDaysOfWeek != null ? schedule.OccursAtDaysOfWeek.ToReadableString() : "null");
                        break;

                    case Models.FrequencyTypeEnum.MONTHLY:
                        Console.WriteLine("MonthlyOccurrenceType        = {0}",
                                          schedule.MonthlyOccurrenceType.HasValue ? schedule.MonthlyOccurrenceType.Value.ToString() : "null");
                        Console.WriteLine("OccursMonthlyAtDayOfWeek     = {0}",
                                          schedule.OccursMonthlyAtDayOfWeek.HasValue ? schedule.OccursMonthlyAtDayOfWeek.Value.ToString() : "null");
                        break;

                    case Models.FrequencyTypeEnum.DAY_OF_MONTH:
                        Console.WriteLine("OccursAtDayOfMonth           = {0}",
                                          schedule.OccursAtDayOfMonth.HasValue ? schedule.OccursAtDayOfMonth.Value.ToString() : "null");
                        break;
                    }
                }
                Console.WriteLine("RecurrencySpecificallyAtTime = {0}",
                                  schedule.RecurrencySpecificallyAtTime.HasValue ? schedule.RecurrencySpecificallyAtTime.Value.ToString() : "null");
                Console.WriteLine("RecurrencyTimeInterval       = {0}",
                                  schedule.RecurrencyTimeInterval.HasValue ? schedule.RecurrencyTimeInterval.Value.ToString() : "null");
                Console.WriteLine("RecurrencyTimeUnit           = {0}",
                                  schedule.RecurrencyTimeUnit.HasValue ? schedule.RecurrencyTimeUnit.Value.ToString() : "null");
                Console.WriteLine("RecurrencyWindowStartsAtTime = {0}",
                                  schedule.RecurrencyWindowStartsAtTime.HasValue ? schedule.RecurrencyWindowStartsAtTime.Value.ToString() : "null");
                Console.WriteLine("RecurrencyWindowEndsAtTime   = {0}",
                                  schedule.RecurrencyWindowEndsAtTime.HasValue ? schedule.RecurrencyWindowEndsAtTime.Value.ToString() : "null");

                Console.WriteLine("PurgeOptions.PurgeType       = {0}", plan.PurgeOptions.PurgeType.ToString());
                switch (plan.PurgeOptions.PurgeType)
                {
                case Models.BackupPlanPurgeTypeEnum.DEFAULT:
                    break;

                case Models.BackupPlanPurgeTypeEnum.CUSTOM:
                    Console.WriteLine("EnabledKeepNumberOfVersions  = {0}", plan.PurgeOptions.EnabledKeepNumberOfVersions);
                    Console.WriteLine("NumberOfVersionsToKeep       = {0}", plan.PurgeOptions.NumberOfVersionsToKeep);
                    break;
                }
                break;
            }

            plan.UpdatedAt = DateTime.UtcNow;

            //try
            //{
            if (IsEditingModel)
            {
                _dao.Update(plan);
            }
            else
            {
                plan.StorageAccount.Hostname = Environment.MachineName;
                _dao.Insert(plan);
            }
            //}
            //catch (Exception ex)
            //{
            //	MessageBox.Show(ex.Message, "Error");
            //}
        }