public bool Apply()
        {
            if (!Validate())
            {
                return(false);
            }

            this.adapterConfiguration.Name           = this.textScheduleName.Text;
            this.adapterConfiguration.Uri            = string.Format("schedule://{0}/{1}", this.comboScheduleType.SelectedItem, this.textScheduleName.Text);
            this.adapterConfiguration.SuspendMessage = this.checkSuspendMessage.Checked;

            #region Schedule
            Schedule schedule = null;
            switch ((ScheduleType)this.comboScheduleType.SelectedItem)
            {
            case ScheduleType.TimeSpan:
                schedule           = new TimeSpanSchedule();
                schedule.StartDate = this.dateStartDate.Value;
                schedule.StartTime = this.dateStartTime.Value;
                int interval = 0;
                switch ((ScheduleTimeUnit)this.comboTimeUnits.SelectedItem)
                {
                case ScheduleTimeUnit.Seconds:
                    interval = Convert.ToInt32(this.updownTimeInterval.Value);
                    break;

                case ScheduleTimeUnit.Minutes:
                    interval = Convert.ToInt32(this.updownTimeInterval.Value * 60);
                    break;

                case ScheduleTimeUnit.Hours:
                    interval = Convert.ToInt32(this.updownTimeInterval.Value * 3600);
                    break;

                default:
                    interval = 3600;
                    break;
                }
                ((TimeSpanSchedule)schedule).Interval = interval;
                break;

            case ScheduleType.Daily:
                schedule           = new DaySchedule();
                schedule.StartDate = this.dateStartDate.Value;
                schedule.StartTime = this.dateStartTime.Value;
                if (radioDayInterval.Checked)
                {
                    ((DaySchedule)schedule).Interval      = Convert.ToInt32(this.updownDayInterval.Value);
                    ((DaySchedule)schedule).ScheduledDays = ScheduleDay.None;
                }
                else
                {
                    ScheduleDay days = ScheduleDay.None;
                    if (checkDaySunday.Checked)
                    {
                        days |= ScheduleDay.Sunday;
                    }
                    if (checkDayMonday.Checked)
                    {
                        days |= ScheduleDay.Monday;
                    }
                    if (checkDayTuesday.Checked)
                    {
                        days |= ScheduleDay.Tuesday;
                    }
                    if (checkDayWednesday.Checked)
                    {
                        days |= ScheduleDay.Wednesday;
                    }
                    if (checkDayThursday.Checked)
                    {
                        days |= ScheduleDay.Thursday;
                    }
                    if (checkDayFriday.Checked)
                    {
                        days |= ScheduleDay.Friday;
                    }
                    if (checkDaySaturday.Checked)
                    {
                        days |= ScheduleDay.Saturday;
                    }
                    ((DaySchedule)schedule).ScheduledDays = days;
                    ((DaySchedule)schedule).Interval      = 0;
                }
                break;

            case ScheduleType.Weekly:
                schedule           = new WeekSchedule();
                schedule.StartDate = this.dateStartDate.Value;
                schedule.StartTime = this.dateStartTime.Value;
                ((WeekSchedule)schedule).Interval = Convert.ToInt32(this.updownWeekInterval.Value);
                ScheduleDay weekDays = ScheduleDay.None;
                if (checkWeekSunday.Checked)
                {
                    weekDays |= ScheduleDay.Sunday;
                }
                if (checkWeekMonday.Checked)
                {
                    weekDays |= ScheduleDay.Monday;
                }
                if (checkWeekTuesday.Checked)
                {
                    weekDays |= ScheduleDay.Tuesday;
                }
                if (checkWeekWednesday.Checked)
                {
                    weekDays |= ScheduleDay.Wednesday;
                }
                if (checkWeekThursday.Checked)
                {
                    weekDays |= ScheduleDay.Thursday;
                }
                if (checkWeekFriday.Checked)
                {
                    weekDays |= ScheduleDay.Friday;
                }
                if (checkWeekSaturday.Checked)
                {
                    weekDays |= ScheduleDay.Saturday;
                }
                ((WeekSchedule)schedule).ScheduledDays = weekDays;
                break;

            case ScheduleType.Monthly:
                schedule           = new MonthSchedule();
                schedule.StartDate = this.dateStartDate.Value;
                schedule.StartTime = this.dateStartTime.Value;
                if (radioDayofMonth.Checked)
                {
                    ((MonthSchedule)schedule).Day = Convert.ToInt32(this.updownDayofMonth.Value);
                }
                else
                {
                    ((MonthSchedule)schedule).Ordinal = (ScheduleOrdinal)this.comboOrdinal.SelectedItem;
                    ((MonthSchedule)schedule).WeekDay = (ScheduleDay)this.comboWeekday.SelectedItem;
                }
                ScheduleMonth months = ScheduleMonth.None;
                if (checkJanuary.Checked)
                {
                    months |= ScheduleMonth.January;
                }
                if (checkFebruary.Checked)
                {
                    months |= ScheduleMonth.February;
                }
                if (checkMarch.Checked)
                {
                    months |= ScheduleMonth.March;
                }
                if (checkApril.Checked)
                {
                    months |= ScheduleMonth.April;
                }
                if (checkMay.Checked)
                {
                    months |= ScheduleMonth.May;
                }
                if (checkJune.Checked)
                {
                    months |= ScheduleMonth.June;
                }
                if (checkJuly.Checked)
                {
                    months |= ScheduleMonth.July;
                }
                if (checkAugust.Checked)
                {
                    months |= ScheduleMonth.August;
                }
                if (checkSeptember.Checked)
                {
                    months |= ScheduleMonth.September;
                }
                if (checkOctober.Checked)
                {
                    months |= ScheduleMonth.October;
                }
                if (checkNovember.Checked)
                {
                    months |= ScheduleMonth.November;
                }
                if (checkDecember.Checked)
                {
                    months |= ScheduleMonth.December;
                }
                ((MonthSchedule)schedule).ScheduledMonths = months;
                break;

            default:
                break;
            }

            adapterConfiguration.Schedule = schedule;
            #endregion

            #region Task
            Task task = new Task();
            task.TaskType                  = this.taskType;
            task.TaskParameters            = propertyGridTask.SelectedObject;
            this.adapterConfiguration.Task = task;
            #endregion

            return(true);
        }
        public void ScheduledPropertyPage_OnLoad(object sender, EventArgs e)
        {
            this.textScheduleName.Text       = adapterConfiguration.Name;
            this.checkSuspendMessage.Checked = adapterConfiguration.SuspendMessage;

            if (adapterConfiguration.Schedule != null)
            {
                this.dateStartDate.Value            = adapterConfiguration.Schedule.StartDate;
                this.dateStartTime.Value            = adapterConfiguration.Schedule.StartTime;
                this.comboScheduleType.SelectedItem = adapterConfiguration.Schedule.Type;
                switch (adapterConfiguration.Schedule.Type)
                {
                case ScheduleType.Daily:
                    //set Daily schedule properties
                    DaySchedule daySchedule = adapterConfiguration.Schedule as DaySchedule;
                    this.updownDayInterval.Value = Convert.ToDecimal(daySchedule.Interval);
                    //if (this.updownDayInterval.Value == 0) --- to be removed
                    if (daySchedule.ScheduledDays != ScheduleDay.None)
                    {
                        ScheduleDay days = daySchedule.ScheduledDays;
                        if ((days & ScheduleDay.Sunday) > 0)
                        {
                            checkDaySunday.Checked = true;
                        }
                        if ((days & ScheduleDay.Monday) > 0)
                        {
                            checkDayMonday.Checked = true;
                        }
                        if ((days & ScheduleDay.Tuesday) > 0)
                        {
                            checkDayTuesday.Checked = true;
                        }
                        if ((days & ScheduleDay.Wednesday) > 0)
                        {
                            checkDayWednesday.Checked = true;
                        }
                        if ((days & ScheduleDay.Thursday) > 0)
                        {
                            checkDayThursday.Checked = true;
                        }
                        if ((days & ScheduleDay.Friday) > 0)
                        {
                            checkDayFriday.Checked = true;
                        }
                        if ((days & ScheduleDay.Saturday) > 0)
                        {
                            checkDaySaturday.Checked = true;
                        }
                        //radioDayInterval.Checked = false; --- to be removed
                        radioSelectDays.Checked = true;
                    }
                    else
                    {
                        radioDayInterval.Checked = true;
                    }
                    break;

                case ScheduleType.Weekly:
                    //set Weekly schedule properties
                    WeekSchedule weekSchedule = adapterConfiguration.Schedule as WeekSchedule;
                    this.updownWeekInterval.Value = weekSchedule.Interval;
                    ScheduleDay weekDays = weekSchedule.ScheduledDays;
                    if ((weekDays & ScheduleDay.Sunday) > 0)
                    {
                        checkWeekSunday.Checked = true;
                    }
                    if ((weekDays & ScheduleDay.Monday) > 0)
                    {
                        checkWeekMonday.Checked = true;
                    }
                    if ((weekDays & ScheduleDay.Tuesday) > 0)
                    {
                        checkWeekTuesday.Checked = true;
                    }
                    if ((weekDays & ScheduleDay.Wednesday) > 0)
                    {
                        checkWeekWednesday.Checked = true;
                    }
                    if ((weekDays & ScheduleDay.Thursday) > 0)
                    {
                        checkWeekThursday.Checked = true;
                    }
                    if ((weekDays & ScheduleDay.Friday) > 0)
                    {
                        checkWeekFriday.Checked = true;
                    }
                    if ((weekDays & ScheduleDay.Saturday) > 0)
                    {
                        checkWeekSaturday.Checked = true;
                    }
                    break;

                case ScheduleType.Monthly:
                    //set Monthly schedule properties
                    MonthSchedule monthSchedule = adapterConfiguration.Schedule as MonthSchedule;
                    this.updownDayofMonth.Value = monthSchedule.Day;
                    if (this.updownDayofMonth.Value == 0)
                    {
                        this.comboOrdinal.SelectedItem = monthSchedule.Ordinal;
                        this.comboWeekday.SelectedItem = monthSchedule.WeekDay;
                        radioDayofMonth.Checked        = false;
                    }
                    else
                    {
                        radioDayofMonth.Checked = true;
                    }
                    ScheduleMonth months = monthSchedule.ScheduledMonths;
                    if ((months & ScheduleMonth.January) > 0)
                    {
                        checkJanuary.Checked = true;
                    }
                    if ((months & ScheduleMonth.February) > 0)
                    {
                        checkFebruary.Checked = true;
                    }
                    if ((months & ScheduleMonth.March) > 0)
                    {
                        checkMarch.Checked = true;
                    }
                    if ((months & ScheduleMonth.April) > 0)
                    {
                        checkApril.Checked = true;
                    }
                    if ((months & ScheduleMonth.May) > 0)
                    {
                        checkMay.Checked = true;
                    }
                    if ((months & ScheduleMonth.June) > 0)
                    {
                        checkJune.Checked = true;
                    }
                    if ((months & ScheduleMonth.July) > 0)
                    {
                        checkJuly.Checked = true;
                    }
                    if ((months & ScheduleMonth.August) > 0)
                    {
                        checkAugust.Checked = true;
                    }
                    if ((months & ScheduleMonth.September) > 0)
                    {
                        checkSeptember.Checked = true;
                    }
                    if ((months & ScheduleMonth.October) > 0)
                    {
                        checkOctober.Checked = true;
                    }
                    if ((months & ScheduleMonth.November) > 0)
                    {
                        checkNovember.Checked = true;
                    }
                    if ((months & ScheduleMonth.December) > 0)
                    {
                        checkDecember.Checked = true;
                    }
                    break;

                case ScheduleType.TimeSpan:
                    //set Timespan schedule properties
                    TimeSpanSchedule timeSchedule = adapterConfiguration.Schedule as TimeSpanSchedule;
                    int timeinseconds             = timeSchedule.Interval;
                    if (timeinseconds % 3600 == 0)
                    {
                        this.updownTimeInterval.Value    = (timeinseconds / 3600);
                        this.comboTimeUnits.SelectedItem = ScheduleTimeUnit.Hours;
                    }
                    else if (timeinseconds % 60 == 0)
                    {
                        this.updownTimeInterval.Value    = (timeinseconds / 60);
                        this.comboTimeUnits.SelectedItem = ScheduleTimeUnit.Minutes;
                    }
                    else
                    {
                        this.updownTimeInterval.Value    = timeinseconds;
                        this.comboTimeUnits.SelectedItem = ScheduleTimeUnit.Seconds;
                    }
                    break;

                default:
                    break;
                }
            }
            if (adapterConfiguration.Task != null)
            {
                this.taskType           = adapterConfiguration.Task.TaskType;
                this.textTaskClass.Text = adapterConfiguration.Task.TaskType.AssemblyQualifiedName;
                this.propertyGridTask.SelectedObject = adapterConfiguration.Task.TaskParameters;
            }
        }