private Microsoft.Win32.TaskScheduler.Action GetAction(Schedule schedule) { if (schedule.ScheduleType.TypeOfSchedule == ScheduleType.ScheduleTypes.BackupDatabase) { Microsoft.Win32.TaskScheduler.ExecAction action = new Microsoft.Win32.TaskScheduler.ExecAction(); ScheduleTypes.BackupDatabase b = schedule.ScheduleType as ScheduleTypes.BackupDatabase; action.Path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "BackupDatabase.exe"); action.WorkingDirectory = System.IO.Path.GetDirectoryName(Application.ExecutablePath); action.Arguments = string.Format("\"BackupPath={0}\" \"BackupName={1}\" \"SetNameType={2}\"", b.SaveTo, b.FileName, (int)b.SetNameType); return(action); } else if (schedule.ScheduleType.TypeOfSchedule == ScheduleType.ScheduleTypes.ExecuteProgram) { Microsoft.Win32.TaskScheduler.ExecAction action = new Microsoft.Win32.TaskScheduler.ExecAction(); ScheduleTypes.ExecuteProgram e = schedule.ScheduleType as ScheduleTypes.ExecuteProgram; action.Path = e.FilePath; action.WorkingDirectory = System.IO.Path.GetDirectoryName(e.FilePath); action.Arguments = e.Parameter; return(action); } else if (schedule.ScheduleType.TypeOfSchedule == ScheduleType.ScheduleTypes.ShowMessage) { Microsoft.Win32.TaskScheduler.ExecAction action = new Microsoft.Win32.TaskScheduler.ExecAction(); ScheduleTypes.ShowMessage s = schedule.ScheduleType as ScheduleTypes.ShowMessage; action.Path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "ShowMessage.exe"); action.WorkingDirectory = System.IO.Path.GetDirectoryName(Application.ExecutablePath); action.Arguments = string.Format("\"MessageTitle={0}\" \"MessageBody={1}\"", s.MessageTitle, s.MessageBody); return(action); } throw new Exception(); }
public AddEditSchedule(Njit.TaskScheduler.ScheduleType.ScheduleTypes allowedScheduleTypes, Schedule schedule) : this(allowedScheduleTypes) { txtName.Text = schedule.Name; txtDescription.Text = schedule.Description; comboBoxScheduleType.SelectedItem = comboBoxScheduleType.Items.Cast <ScheduleType>().Where(t => t.Title == schedule.ScheduleType.Title).Single(); comboBoxRepeat.SelectedItem = comboBoxRepeat.Items.Cast <ScheduleRepeat>().Where(t => t.Title == schedule.RepeatType.Title).Single(); ScheduleRepeat selectedScheduleRepeat = (ScheduleRepeat)comboBoxRepeat.SelectedItem; if (selectedScheduleRepeat.TypeOfRepeat == ScheduleRepeat.ScheduleRepeats.NoRepeat) { ScheduleRepeatTypes.NoRepeat st = (schedule.RepeatType as ScheduleRepeatTypes.NoRepeat); txtStartDateNoRepeat.Text = st.StartDate; txtStartTimeNoRepeat.Text = st.StartTime; } else if (selectedScheduleRepeat.TypeOfRepeat == ScheduleRepeat.ScheduleRepeats.Daily) { ScheduleRepeatTypes.Daily st = (schedule.RepeatType as ScheduleRepeatTypes.Daily); txtStartDateDaily.Text = st.StartDate; txtEndDateDaily.Text = st.EndDate; txtTimeDaily.Text = st.ExecuteTime; } else if (selectedScheduleRepeat.TypeOfRepeat == ScheduleRepeat.ScheduleRepeats.Weekly) { ScheduleRepeatTypes.Weekly st = (schedule.RepeatType as ScheduleRepeatTypes.Weekly); txtStartDateWeekly.Text = st.StartDate; txtStartTimeWeekly.Text = st.StartTime; txtEndDateWeekly.Text = st.EndDate; txtEndTimeWeekly.Text = st.EndTime; txtTimeWeekly.Text = st.ExecuteTime; weekdaysSelect.SelectedWeeks = st.WeekDays; } else if (selectedScheduleRepeat.TypeOfRepeat == ScheduleRepeat.ScheduleRepeats.Monthly) { ScheduleRepeatTypes.Monthly st = (schedule.RepeatType as ScheduleRepeatTypes.Monthly); txtStartDateMonthly.Text = st.StartDate; txtStartTimeMonthly.Text = st.StartTime; txtEndDateMonthly.Text = st.EndDate; txtEndTimeMonthly.Text = st.EndTime; txtTimeMonthly.Text = st.ExecuteTime; txtMonthDay.Text = st.MonthDay.ToString(); monthsSelect.SelectedMonths = st.Months; } ScheduleType selectedScheduleType = (ScheduleType)comboBoxScheduleType.SelectedItem; if (selectedScheduleType.TypeOfSchedule == ScheduleType.ScheduleTypes.BackupDatabase) { ScheduleTypes.BackupDatabase st = (schedule.ScheduleType as ScheduleTypes.BackupDatabase); //SetDatabaseName(new SqlConnectionStringBuilder(ScheduleTypes.BackupDatabase.ConnectionString)); txtBackupPath.Text = st.SaveTo; txtBackupName.Text = st.FileName; comboBoxSetBackupNameType.SelectedIndex = (int)st.SetNameType; } else if (selectedScheduleType.TypeOfSchedule == ScheduleType.ScheduleTypes.ExecuteProgram) { ScheduleTypes.ExecuteProgram st = (schedule.ScheduleType as ScheduleTypes.ExecuteProgram); txtProgramFilePath.Text = st.FilePath; txtProgramParameter.Text = st.Parameter; } else if (selectedScheduleType.TypeOfSchedule == ScheduleType.ScheduleTypes.ShowMessage) { ScheduleTypes.ShowMessage st = (schedule.ScheduleType as ScheduleTypes.ShowMessage); txtMessageTitle.Text = st.MessageTitle; txtMessageBody.Text = st.MessageBody; } }