protected override void PerformJob(Job job, IProgressReceiver progressReceiver, CancellationToken cancellationToken) { job.KeywordStatus = KeywordStatus.NotFound; if (!File.Exists(job.FileSearched)) { progressReceiver.SendProgress("File '{0}' not found!", job.FileSearched); } else { try { using (var sr = File.OpenText(job.FileSearched)) { long lineCount = 1; while (!sr.EndOfStream) { cancellationToken.ThrowIfCancellationRequested(); var line = sr.ReadLine(); lineCount++; if (line.Contains(job.Keyword)) { job.KeywordStatus = KeywordStatus.Found; progressReceiver.SendProgress("Keyword found on line {0} of file {1}", lineCount, job.FileSearched); break; } } } } catch (Exception ex) { progressReceiver.SendProgress("Error searching file: {0}", ex.Message); } } }
public void Execute(Job job, IProgressReceiver progressReceiver, CancellationToken cancellationToken) { var stopwatch = new Stopwatch(); try { job.DateStarted = DateTime.UtcNow; stopwatch.Start(); PerformJob(job, progressReceiver, cancellationToken); } catch (Exception ex) { progressReceiver.SendProgress("Error performing job on worker {0}: {1}", Thread.CurrentThread.ManagedThreadId, ex.Message); } finally { stopwatch.Stop(); job.TimeTaken = stopwatch.Elapsed; } }
protected override void PerformJob(Job job, IProgressReceiver progressReceiver, CancellationToken cancellationToken) { var items = new List <string>(); foreach (var prop in job.GetType().GetProperties()) { cancellationToken.ThrowIfCancellationRequested(); // note: only handles simple types if (prop.CanRead) { items.Add(GetKeyValue(prop.Name, prop.GetValue(job))); } } if (progressReceiver != null) { progressReceiver.SendProgress(String.Concat("{ ", String.Join(",", items), " }")); } job.KeywordStatus = KeywordStatus.NotFound; Thread.Sleep(100); // HACK: this job is unfair to file searcher which seems to never run }