Exemple #1
0
        public ActionResult EditSchedule(string dbServer, Guid jobID, Guid scheduleUID)
        {
            JobSchedules            jobschedules          = new JobSchedules();
            PopulateDropDowns       dropdown              = new PopulateDropDowns();
            JobScheduleDetailsModel schedule              = new JobScheduleDetailsModel();
            List <SelectListItem>   frequencyTypes        = new List <SelectListItem>();
            List <SelectListItem>   subdayTypes           = new List <SelectListItem>();
            List <SelectListItem>   freqRelativeIntervals = new List <SelectListItem>();
            List <SelectListItem>   monthlyFrequency      = new List <SelectListItem>();

            schedule = jobschedules.getScheduleDetails(dbServer, jobID, scheduleUID);

            frequencyTypes    = dropdown.getFrequencyTypes();
            ViewBag.FreqTypes = frequencyTypes;

            subdayTypes         = dropdown.getSubdayTypes();
            ViewBag.SubDayTypes = subdayTypes;

            freqRelativeIntervals         = dropdown.getFreqRelativeIntervals();
            ViewBag.FreqRelativeIntervals = freqRelativeIntervals;

            monthlyFrequency         = dropdown.getMonthlyFrequency();
            ViewBag.MonthlyFrequency = monthlyFrequency;

            ViewBag.ServerName = dbServer;
            ViewBag.JobID      = jobID;

            return(View(schedule));
        }
Exemple #2
0
        public ActionResult EditSchedule(JobScheduleDetailsModel schedule)
        {
            if (ModelState.IsValid)
            {
                JobSchedules jobschedules = new JobSchedules();
                jobschedules.saveScheduleDetails(schedule);

                ViewBag.ServerName = schedule.ServerName;
                ViewBag.JobID      = schedule.JobID;

                LogActivity log = new LogActivity();
                log.Add(User.Identity.Name, schedule.ServerName, schedule.JobID, "Edit Schedule");

                return(RedirectToAction("Schedules", "Edit", new { dbServer = ViewBag.ServerName, jobID = ViewBag.JobID }));
            }
            else
            {
                PopulateDropDowns     dropdown              = new PopulateDropDowns();
                List <SelectListItem> frequencyTypes        = new List <SelectListItem>();
                List <SelectListItem> subdayTypes           = new List <SelectListItem>();
                List <SelectListItem> freqRelativeIntervals = new List <SelectListItem>();
                List <SelectListItem> monthlyFrequency      = new List <SelectListItem>();

                frequencyTypes    = dropdown.getFrequencyTypes();
                ViewBag.FreqTypes = frequencyTypes;

                subdayTypes         = dropdown.getSubdayTypes();
                ViewBag.SubDayTypes = subdayTypes;

                freqRelativeIntervals         = dropdown.getFreqRelativeIntervals();
                ViewBag.FreqRelativeIntervals = freqRelativeIntervals;

                monthlyFrequency         = dropdown.getMonthlyFrequency();
                ViewBag.MonthlyFrequency = monthlyFrequency;

                ViewBag.ServerName = schedule.ServerName;
                ViewBag.JobID      = schedule.JobID;

                return(View(schedule));
            }
        }
        private JobSchedule setCommon(JobSchedule scheduleToUpdate, JobScheduleDetailsModel schedule)
        {
            scheduleToUpdate.ActiveStartTimeOfDay = schedule.DailyFreqOccursOnceTime;
            if (schedule.DailyFreqOccursOnce)
            {
                scheduleToUpdate.ActiveEndTimeOfDay   = TimeSpan.ParseExact("23:59:59", "hh\\:mm\\:ss", CultureInfo.InvariantCulture);
                scheduleToUpdate.FrequencySubDayTypes = FrequencySubDayTypes.Once;
            }
            else
            {
                scheduleToUpdate.ActiveEndTimeOfDay      = schedule.DailyFreqEndingTime;
                scheduleToUpdate.FrequencySubDayInterval = schedule.DailyFreqOccursEvery;
                switch (schedule.DailyFreqSubDay)
                {
                case "Hour":
                    scheduleToUpdate.FrequencySubDayTypes = FrequencySubDayTypes.Hour;
                    break;

                case "Minute":
                    scheduleToUpdate.FrequencySubDayTypes = FrequencySubDayTypes.Minute;
                    break;

                case "Second":
                    scheduleToUpdate.FrequencySubDayTypes = FrequencySubDayTypes.Second;
                    break;
                }
            }
            scheduleToUpdate.ActiveStartDate = schedule.DurationStartDate;
            if (schedule.DurationNoEndDate)
            {
                scheduleToUpdate.ActiveEndDate = DateTime.MaxValue;
            }
            else
            {
                scheduleToUpdate.ActiveEndDate = schedule.DurationEndDate;
            }

            return(scheduleToUpdate);
        }
        private JobScheduleDetailsModel setDefaults(JobScheduleDetailsModel schedule)
        {
            schedule.OneTimeStartDate              = DateTime.Now.Date;
            schedule.OneTimeStartTimeOfDay         = TimeSpan.MinValue;
            schedule.DailyRecursEvery              = 1;
            schedule.WeeklyRecursEvery             = 1;
            schedule.MonthlyDayNo                  = 1;
            schedule.MonthlyFrequency              = 1;
            schedule.MonthlyRelativeFreq           = 1;
            schedule.MonthlyRelativeFreqSubDayType = "First";
            schedule.MonthlyRelativeSubFreq        = "EveryDay";
            schedule.DailyFreqOccursOnce           = true;
            schedule.DailyFreqOccursOnceTime       = TimeSpan.MinValue;
            schedule.DailyFreqOccursEvery          = 1;
            schedule.DailyFreqSubDay               = "hour";
            schedule.DailyFreqStartingTime         = TimeSpan.MinValue;
            schedule.DailyFreqEndingTime           = TimeSpan.ParseExact("23:59:59", "hh\\:mm\\:ss", CultureInfo.InvariantCulture);
            schedule.DurationStartDate             = DateTime.Now.Date;
            schedule.DurationEndDate               = DateTime.MaxValue.Date;
            schedule.DurationNoEndDate             = true;

            return(schedule);
        }
        public void saveScheduleDetails(JobScheduleDetailsModel schedule)
        {
            ConnectSqlServer connection  = new ConnectSqlServer();
            Server           dbServer    = connection.Connect(schedule.ServerName);
            Job         job              = dbServer.JobServer.GetJobByID(schedule.JobID);
            JobSchedule scheduleToUpdate = job.JobSchedules[schedule.ScheduleUID];

            if (schedule.Name != scheduleToUpdate.Name)
            {
                scheduleToUpdate.Rename(schedule.Name);
                scheduleToUpdate.Refresh();
            }

            scheduleToUpdate.IsEnabled = schedule.IsEnabled;

            switch (schedule.ScheduleFrequency)
            {
            case "OneTime":
                scheduleToUpdate.FrequencyTypes       = FrequencyTypes.OneTime;
                scheduleToUpdate.ActiveStartDate      = schedule.OneTimeStartDate;
                scheduleToUpdate.ActiveStartTimeOfDay = schedule.OneTimeStartTimeOfDay;
                break;

            case "Daily":
                scheduleToUpdate.FrequencyTypes    = FrequencyTypes.Daily;
                scheduleToUpdate.FrequencyInterval = schedule.DailyRecursEvery;
                scheduleToUpdate = setCommon(scheduleToUpdate, schedule);
                break;

            case "Weekly":
                scheduleToUpdate.FrequencyTypes            = FrequencyTypes.Weekly;
                scheduleToUpdate.FrequencyRecurrenceFactor = schedule.WeeklyRecursEvery;
                scheduleToUpdate.FrequencyInterval         = 0;
                if (schedule.WeeklySunday)
                {
                    scheduleToUpdate.FrequencyInterval = +1;
                }
                if (schedule.WeeklyMonday)
                {
                    scheduleToUpdate.FrequencyInterval = +2;
                }
                if (schedule.WeeklyTuesday)
                {
                    scheduleToUpdate.FrequencyInterval = +4;
                }
                if (schedule.WeeklyWednesday)
                {
                    scheduleToUpdate.FrequencyInterval = +8;
                }
                if (schedule.WeeklyThursday)
                {
                    scheduleToUpdate.FrequencyInterval = +16;
                }
                if (schedule.WeeklyFriday)
                {
                    scheduleToUpdate.FrequencyInterval = +32;
                }
                if (schedule.WeeklySaturday)
                {
                    scheduleToUpdate.FrequencyInterval = +64;
                }
                scheduleToUpdate = setCommon(scheduleToUpdate, schedule);
                break;

            case "Monthly":
                scheduleToUpdate.FrequencyTypes            = FrequencyTypes.Monthly;
                scheduleToUpdate.FrequencyRecurrenceFactor = schedule.MonthlyFrequency;
                scheduleToUpdate.FrequencyInterval         = schedule.MonthlyDayNo;
                scheduleToUpdate = setCommon(scheduleToUpdate, schedule);
                break;

            case "MonthlyRelative":
                scheduleToUpdate.FrequencyTypes = FrequencyTypes.MonthlyRelative;
                if (schedule.MonthlyRelativeSubFreq == "Sunday")
                {
                    scheduleToUpdate.FrequencyInterval = 1;
                }
                if (schedule.MonthlyRelativeSubFreq == "Monday")
                {
                    scheduleToUpdate.FrequencyInterval = 2;
                }
                if (schedule.MonthlyRelativeSubFreq == "Tuesday")
                {
                    scheduleToUpdate.FrequencyInterval = 3;
                }
                if (schedule.MonthlyRelativeSubFreq == "Wednesday")
                {
                    scheduleToUpdate.FrequencyInterval = 4;
                }
                if (schedule.MonthlyRelativeSubFreq == "Thursday")
                {
                    scheduleToUpdate.FrequencyInterval = 5;
                }
                if (schedule.MonthlyRelativeSubFreq == "Friday")
                {
                    scheduleToUpdate.FrequencyInterval = 6;
                }
                if (schedule.MonthlyRelativeSubFreq == "Saturday")
                {
                    scheduleToUpdate.FrequencyInterval = 7;
                }
                if (schedule.MonthlyRelativeSubFreq == "Weekdays")
                {
                    scheduleToUpdate.FrequencyInterval = 9;
                }
                if (schedule.MonthlyRelativeSubFreq == "WeekEnds")
                {
                    scheduleToUpdate.FrequencyInterval = 10;
                }
                if (schedule.MonthlyRelativeSubFreq == "EveryDay")
                {
                    scheduleToUpdate.FrequencyInterval = 8;
                }
                switch (schedule.MonthlyRelativeSubFreq)
                {
                case "First":
                    scheduleToUpdate.FrequencyRelativeIntervals = FrequencyRelativeIntervals.First;
                    break;

                case "Second":
                    scheduleToUpdate.FrequencyRelativeIntervals = FrequencyRelativeIntervals.Second;
                    break;

                case "Third":
                    scheduleToUpdate.FrequencyRelativeIntervals = FrequencyRelativeIntervals.Third;
                    break;

                case "Fourth":
                    scheduleToUpdate.FrequencyRelativeIntervals = FrequencyRelativeIntervals.Fourth;
                    break;

                case "Last":
                    scheduleToUpdate.FrequencyRelativeIntervals = FrequencyRelativeIntervals.Last;
                    break;
                }
                scheduleToUpdate.FrequencyRecurrenceFactor = schedule.MonthlyRelativeFreq;
                scheduleToUpdate = setCommon(scheduleToUpdate, schedule);
                break;

            case "AutoStart":
                scheduleToUpdate.FrequencyTypes             = FrequencyTypes.AutoStart;
                scheduleToUpdate.FrequencyInterval          = 0;
                scheduleToUpdate.FrequencyRecurrenceFactor  = 0;
                scheduleToUpdate.FrequencyRelativeIntervals = 0;
                scheduleToUpdate.FrequencySubDayInterval    = 0;
                scheduleToUpdate.FrequencySubDayTypes       = FrequencySubDayTypes.Unknown;
                break;

            case "OnIdle":
                scheduleToUpdate.FrequencyTypes             = FrequencyTypes.OneTime;
                scheduleToUpdate.FrequencyInterval          = 0;
                scheduleToUpdate.FrequencyRecurrenceFactor  = 0;
                scheduleToUpdate.FrequencyRelativeIntervals = 0;
                scheduleToUpdate.FrequencySubDayInterval    = 0;
                scheduleToUpdate.FrequencySubDayTypes       = FrequencySubDayTypes.Unknown;
                break;
            }

            scheduleToUpdate.Alter();
            scheduleToUpdate.Refresh();
        }
        public JobScheduleDetailsModel getScheduleDetails(string serverName, Guid jobID, Guid scheduleUID)
        {
            ConnectSqlServer        connection = new ConnectSqlServer();
            Server                  dbServer   = connection.Connect(serverName);
            JobScheduleDetailsModel schedule   = new JobScheduleDetailsModel();
            Job job = dbServer.JobServer.GetJobByID(jobID);

            var jobschedule = job.JobSchedules[scheduleUID];

            schedule.IsEnabled         = jobschedule.IsEnabled;
            schedule.Name              = jobschedule.Name;
            schedule.ScheduleFrequency = jobschedule.FrequencyTypes.ToString();
            schedule.ServerName        = serverName;
            schedule.JobID             = jobID;
            schedule.ScheduleUID       = scheduleUID;
            schedule = setDefaults(schedule);

            switch (jobschedule.FrequencyTypes.ToString())
            {
            case "OneTime":
                schedule.OneTimeStartDate      = jobschedule.ActiveStartDate;
                schedule.OneTimeStartTimeOfDay = jobschedule.ActiveStartTimeOfDay;
                break;

            case "Daily":
                schedule.DailyRecursEvery = jobschedule.FrequencyInterval;
                break;

            case "Weekly":
                WeekDays days = (WeekDays)jobschedule.FrequencyInterval;
                schedule.WeeklyRecursEvery = jobschedule.FrequencyRecurrenceFactor;
                if (days.HasFlag(WeekDays.Sunday))
                {
                    schedule.WeeklySunday = true;
                }
                if (days.HasFlag(WeekDays.Monday))
                {
                    schedule.WeeklyMonday = true;
                }
                if (days.HasFlag(WeekDays.Tuesday))
                {
                    schedule.WeeklyTuesday = true;
                }
                if (days.HasFlag(WeekDays.Wednesday))
                {
                    schedule.WeeklyWednesday = true;
                }
                if (days.HasFlag(WeekDays.Thursday))
                {
                    schedule.WeeklyThursday = true;
                }
                if (days.HasFlag(WeekDays.Friday))
                {
                    schedule.WeeklyFriday = true;
                }
                if (days.HasFlag(WeekDays.Saturday))
                {
                    schedule.WeeklySaturday = true;
                }
                break;

            case "Monthly":
                schedule.MonthlyDayNo     = jobschedule.FrequencyInterval;
                schedule.MonthlyFrequency = jobschedule.FrequencyRecurrenceFactor;
                break;

            case "MonthlyRelative":
                MonthlyRelativeWeekDays monthdays = (MonthlyRelativeWeekDays)jobschedule.FrequencyInterval;
                schedule.MonthlyRelativeFreq           = jobschedule.FrequencyRecurrenceFactor;
                schedule.MonthlyRelativeFreqSubDayType = jobschedule.FrequencyRelativeIntervals.ToString();
                if (monthdays.HasFlag(MonthlyRelativeWeekDays.Sunday))
                {
                    schedule.MonthlyRelativeSubFreq = "Sunday";
                }
                if (monthdays.HasFlag(MonthlyRelativeWeekDays.Monday))
                {
                    schedule.MonthlyRelativeSubFreq = "Monday";
                }
                if (monthdays.HasFlag(MonthlyRelativeWeekDays.Tuesday))
                {
                    schedule.MonthlyRelativeSubFreq = "Tuesday";
                }
                if (monthdays.HasFlag(MonthlyRelativeWeekDays.Wednesday))
                {
                    schedule.MonthlyRelativeSubFreq = "Wednesday";
                }
                if (monthdays.HasFlag(MonthlyRelativeWeekDays.Thursday))
                {
                    schedule.MonthlyRelativeSubFreq = "Thursday";
                }
                if (monthdays.HasFlag(MonthlyRelativeWeekDays.Friday))
                {
                    schedule.MonthlyRelativeSubFreq = "Friday";
                }
                if (monthdays.HasFlag(MonthlyRelativeWeekDays.Saturday))
                {
                    schedule.MonthlyRelativeSubFreq = "Saturday";
                }
                if (monthdays.HasFlag(MonthlyRelativeWeekDays.WeekDays))
                {
                    schedule.MonthlyRelativeSubFreq = "WeekDays";
                }
                if (monthdays.HasFlag(MonthlyRelativeWeekDays.WeekEnds))
                {
                    schedule.MonthlyRelativeSubFreq = "WeekEnds";
                }
                if (monthdays.HasFlag(MonthlyRelativeWeekDays.EveryDay))
                {
                    schedule.MonthlyRelativeSubFreq = "EveryDay";
                }
                break;

            default:
                schedule.OneTimeStartDate      = jobschedule.ActiveStartDate;
                schedule.OneTimeStartTimeOfDay = jobschedule.ActiveStartTimeOfDay;
                break;
            }

            if (jobschedule.ActiveEndTimeOfDay.Hours == 23 && jobschedule.ActiveEndTimeOfDay.Minutes == 59 && jobschedule.ActiveEndTimeOfDay.Seconds == 59)
            {
                schedule.DailyFreqOccursOnce     = true;
                schedule.DailyFreqOccursOnceTime = jobschedule.ActiveStartTimeOfDay;
            }
            else
            {
                schedule.DailyFreqOccursOnce   = false;
                schedule.DailyFreqOccursEvery  = jobschedule.FrequencySubDayInterval;
                schedule.DailyFreqSubDay       = jobschedule.FrequencySubDayTypes.ToString();
                schedule.DailyFreqStartingTime = jobschedule.ActiveStartTimeOfDay;
                schedule.DailyFreqEndingTime   = jobschedule.ActiveEndTimeOfDay;
            }
            schedule.DurationStartDate = jobschedule.ActiveStartDate;
            schedule.DurationEndDate   = jobschedule.ActiveEndDate;
            if (jobschedule.ActiveEndDate == DateTime.MaxValue.Date)
            {
                schedule.DurationNoEndDate = true;
            }

            return(schedule);
        }