public async Task StopJob() { if (await _jobManager.GetJob(JobName) != null) { await _jobManager.Cancel(JobName); IsJobRunning = false; } }
public bool Cancel(long id) { if (_jobManager.Cancel(id)) { Interlocked.Decrement(ref _jobUnExcute); return(true); } return(false); }
public ListPageViewModel(INavigationService navigationService, IJobManager jobManager, IDialogService dialogService, ILogger <ViewModelBase> logger, IConnectivity connectivity) : base(navigationService, dialogService, logger, connectivity) { this._jobManager = jobManager; //this.Create = _navigationService.NavigateCommand("CreateJob"); this.LoadJobs = ReactiveCommand.CreateFromTask(async() => { var jobs = await jobManager.GetJobs(); this.Jobs = jobs .Select(x => new CommandItem { Text = x.Type.Name, Detail = $"上次运行:{x.LastRunUtc?.ToLocalTime().ToString("G") ?? "永久运行"}", PrimaryCommand = ReactiveCommand.CreateFromTask(() => jobManager.Run(x.Identifier)), SecondaryCommand = ReactiveCommand.CreateFromTask(async() => { await jobManager.Cancel(x.Identifier); this.LoadJobs.Execute(null); }) }) .ToList(); }); this.BindBusyCommand(this.LoadJobs); this.RunAllJobs = ReactiveCommand.CreateFromTask(async() => { if (!await this.AssertJobs()) { return; } if (this._jobManager.IsRunning) { _dialogService.ShortAlert("作业管理器已在运行"); } else { await this._jobManager.RunAll(); _dialogService.ShortAlert("作业批处理已启动"); } }); this.CancelAllJobs = ReactiveCommand.CreateFromTask(async _ => { if (!await this.AssertJobs()) { return; } var confirm = await _dialogService.ShowConfirmAsync("是否确实要取消所有作业?"); if (confirm) { await this._jobManager.CancelAll(); this.LoadJobs.Execute(null); } }); }
public ListViewModel(IJobManager jobManager, INavigationService navigator, IUserDialogs dialogs) { this.jobManager = jobManager; this.dialogs = dialogs; this.Create = navigator.NavigateCommand("CreateJob"); this.LoadJobs = ReactiveCommand.CreateFromTask(async() => { var jobs = await jobManager.GetJobs(); this.Jobs = jobs .Select(x => new CommandItem { Text = x.Identifier, Detail = x.LastRunUtc?.ToLocalTime().ToString("G") ?? "Never Run", PrimaryCommand = ReactiveCommand.CreateFromTask(() => jobManager.Run(x.Identifier)), SecondaryCommand = ReactiveCommand.CreateFromTask(async() => { await jobManager.Cancel(x.Identifier); this.LoadJobs.Execute(); }) }) .ToList(); }); this.BindBusyCommand(this.LoadJobs); this.RunAllJobs = ReactiveCommand.CreateFromTask(async() => { if (!await this.AssertJobs()) { return; } if (this.jobManager.IsRunning) { await dialogs.Alert("Job Manager is already running"); } else { await this.jobManager.RunAll(); dialogs.Toast("Job Batch Started"); } }); this.CancelAllJobs = ReactiveCommand.CreateFromTask(async _ => { if (!await this.AssertJobs()) { return; } var confirm = await dialogs.Confirm("Are you sure you wish to cancel all jobs?"); if (confirm) { await this.jobManager.CancelAll(); this.LoadJobs.Execute(); } }); }
public ListViewModel(IJobManager jobManager, IUserDialogs dialogs) { this.jobManager = jobManager; this.dialogs = dialogs; this.LoadJobs = ReactiveCommand.CreateFromTask(async() => { var jobs = await jobManager.GetJobs(); this.Jobs = jobs .Select(x => new CommandItem { Text = x.Identifier, Detail = x.LastRunUtc?.ToLocalTime().ToString("R") ?? "Never Run", PrimaryCommand = ReactiveCommand.CreateFromTask(async() => { try { using (dialogs.Loading("Running Job " + x.Identifier)) await jobManager.Run(x.Identifier); } catch (Exception ex) { dialogs.Alert(ex.ToString()); } }), SecondaryCommand = ReactiveCommand.CreateFromTask(() => jobManager.Cancel(x.Identifier) ) }) .ToList(); this.RaisePropertyChanged(nameof(this.Jobs)); }); this.BindBusyCommand(this.LoadJobs); this.RunAllJobs = ReactiveCommand.CreateFromTask(async() => { if (!await this.AssertJobs()) { return; } if (this.jobManager.IsRunning) { dialogs.Alert("Job Manager is already running"); } else { dialogs.Toast("Job Batch Started"); await this.jobManager.RunAll(); } }); this.CancelAllJobs = ReactiveCommand.CreateFromTask(async _ => { if (!await this.AssertJobs()) { return; } var confirm = await dialogs.ConfirmAsync("Are you sure you wish to cancel all jobs?"); if (confirm) { await this.jobManager.CancelAll(); this.LoadJobs.Execute(); } }); }