示例#1
0
        /// <summary>
        /// 开始Job操作
        /// </summary>
        /// <param name="name"></param>
        public async static void Start(string name)
        {
            var currentJobInfo = DataManager.Current.JobInfos.First(c => c.Name == name);

            if (currentJobInfo.Status == JobStatusType.Stop)
            {
                JobManager.GetSchedule(name).Enable();
                JobInfoManager.Refresh();
            }
            else if (currentJobInfo.Status == JobStatusType.Obsolete)
            {
                var clickresult = await DialogManager.ShowMessageAsync(Application.Current.MainWindow as MetroWindow, "务已经过期", "是否重新建立新的任务(保持原设置)", MessageDialogStyle.AffirmativeAndNegative);

                if (clickresult == MessageDialogResult.Negative)
                {
                    return;
                }
                JobInfoManager.RemoveJob(currentJobInfo);

                var isSuccess = RunSchedule(currentJobInfo.ScheduleInfo);
                if (isSuccess)
                {
                    var isCreateJobSuccess = JobInfoManager.CreateJob(currentJobInfo.ScheduleInfo);
                    if (isCreateJobSuccess)
                    {
                        //MessageBox.Show("任务启用成功");
                        JobInfoManager.Refresh();
                        Messenger.Default.Send <string>("", MessengerToken.CLOSEWINDOW);
                    }
                    else
                    {
                        MessageBox.Show("任务启用失败");
                    }
                }
                else
                {
                    MessageBox.Show("任务启用失败");
                }
            }

            else
            {
                MessageBox.Show("任务已经在启用状态");
            }
        }
示例#2
0
        /// <summary>
        /// 删除Job操作
        /// </summary>
        /// <param name="name"></param>
        public static void Dorp(string name)
        {
            var currentJob = DataManager.Current.JobInfos.First(c => c.Name == name);

            if (currentJob.Status == JobStatusType.Pending)
            {
                JobManager.RemoveJob(name);
                var result = JobInfoManager.RemoveJob(currentJob);
                if (result)
                {
                    MessageBox.Show("任务删除成功");
                }
            }
            else if (currentJob.Status == JobStatusType.Obsolete)
            {
                var result = JobInfoManager.RemoveJob(currentJob);
                if (result)
                {
                    MessageBox.Show("任务删除成功");
                }
            }
            Refresh();
        }