public bool Execute() { var startTime = DateTime.Now; try { m_CurrentCancellationToken = new CancellationTokenSource(); var cancellationToken = m_CurrentCancellationToken.Token; using (var prg = m_App.CreateProgress()) { LogMessage("Preparing job"); var jobItems = PrepareJob(); JobSet?.Invoke(jobItems, startTime); for (int i = 0; i < jobItems.Length; i++) { cancellationToken.ThrowIfCancellationRequested(); var jobItem = jobItems[i]; prg.SetStatus($"Processing {jobItem.FilePath}"); var res = TryProcessFile(jobItem, cancellationToken); ProgressChanged?.Invoke(jobItem, res); prg.Report((double)(i + 1) / (double)jobItems.Length); } } return(true); } catch (OperationCanceledException) { throw new JobCancelledException(); } catch (Exception ex) { m_Logger.Log(ex); return(false); } finally { JobCompleted?.Invoke(DateTime.Now - startTime); } }
public Task <bool> ExecuteAsync() { var startTime = DateTime.Now; try { using (var prg = m_App.CreateProgress()) { LogMessage("Preparing job"); var jobItems = PrepareJob(); JobSet?.Invoke(jobItems, startTime); for (int i = 0; i < jobItems.Length; i++) { var jobItem = jobItems[i]; prg.SetStatus($"Processing {jobItem.FilePath}"); var res = TryProcessFile(jobItem, default); ProgressChanged?.Invoke(jobItem, res); prg.Report((double)i / (double)jobItems.Length); } } return(Task.FromResult(true)); } catch { return(Task.FromResult(false)); } finally { JobCompleted?.Invoke(DateTime.Now - startTime); } }
private void OnJobScopeSet(IJobItem[] files, DateTime startTime) => JobSet?.Invoke(files, startTime);