Beispiel #1
0
        private void CheckTasks(object obj)
        {
            using (var context = new DataAccess.AppContext())
            {
                var jobs = context.Jobs.ToList();

                foreach (var job in jobs)
                {
                    if (job.TaskDate <= DateTime.Now)
                    {
                        switch (job.RepeatMode)
                        {
                        case 0:
                            job.TaskDate = job.TaskDate.AddDays(7);
                            break;

                        case 1:
                            job.TaskDate = job.TaskDate.AddMonths(1);
                            break;

                        case 2:
                            job.TaskDate = job.TaskDate.AddYears(1);
                            break;
                        }

                        switch (job.JobType)
                        {
                        case 0:
                            SendEmail();
                            MessageBox.Show("Задача \"Отправка Email\" выполнена");
                            break;

                        case 1:
                            DownloadFile();
                            MessageBox.Show("Задача \"Скачка файла\" выполнена");
                            break;

                        case 2:
                            MoveFile();
                            MessageBox.Show("Задача \"Перемещение каталога\" выполнена");
                            break;
                        }
                    }
                }
                context.SaveChanges();
            }
        }
Beispiel #2
0
        private void TaskButtonClick(object sender, RoutedEventArgs e)
        {
            var job = new Job
            {
                TaskDate   = (DateTime)calendar.SelectedDate,
                JobType    = jobTypeComboBox.SelectedIndex,
                RepeatMode = repeatComboBox.SelectedIndex
            };

            using (var context = new DataAccess.AppContext())
            {
                context.Jobs.Add(job);
                context.SaveChanges();
            }

            MessageBox.Show("Задача запланирована");
        }