private void OnCreated(object sender, FileSystemEventArgs e) { using (IDbConnection db = _factory.OpenDbConnection()) { var info = new FileInfo(e.FullPath); var file = new WatchedFile { Path = e.FullPath, LastReadFileSize = 0, CurrentFileSize = info.Length }; db.Insert<WatchedFile>(file); } }
/// <summary> /// Try to pick a file off the queue. It might be that something else already started working. /// If so, return false so we can ignore it. /// </summary> /// <param name="file"></param> /// <returns></returns> public bool StartProcessing(WatchedFile file) { using (IDbConnection db = _factory.OpenDbConnection()) { file.Processing = true; return (db.UpdateOnly <WatchedFile>(file, ev => ev.Update(f => f.Processing).Where(f => f.Id == file.Id && !f.Processing)) > 0); } }
private void OnChanged(object sender, FileSystemEventArgs e) { using (IDbConnection db = _factory.OpenDbConnection()) { var info = new FileInfo(e.FullPath); WatchedFile file = new WatchedFile { CurrentFileSize = info.Length }; db.UpdateOnly<WatchedFile>(file, ev => ev.Update(f => f.CurrentFileSize).Where(f => f.Path == e.FullPath)); } }
public void StopProcessing(WatchedFile file) { using (IDbConnection db = _factory.OpenDbConnection()) { file.Processing = false; file.LastReadFileSize = file.CurrentFileSize; db.UpdateOnly <WatchedFile>(file, ev => ev.Update(new List <string> { "Processing", "LastReadFileSize" }).Where(f => f.Id == file.Id)); } }
private void OnChanged(object sender, FileSystemEventArgs e) { using (IDbConnection db = _factory.OpenDbConnection()) { var info = new FileInfo(e.FullPath); WatchedFile file = new WatchedFile { CurrentFileSize = info.Length }; db.UpdateOnly <WatchedFile>(file, ev => ev.Update(f => f.CurrentFileSize).Where(f => f.Path == e.FullPath)); } }
private void OnCreated(object sender, FileSystemEventArgs e) { using (IDbConnection db = _factory.OpenDbConnection()) { var info = new FileInfo(e.FullPath); var file = new WatchedFile { Path = e.FullPath, LastReadFileSize = 0, CurrentFileSize = info.Length }; db.Insert <WatchedFile>(file); } }
/// <summary> /// Create or check an initial index of files since last time we started /// </summary> private void Initialize(string baseDirectory, bool includeSubdirectories = true) { DirectoryInfo directory = new DirectoryInfo(baseDirectory); //foreach (FileInfo file in directory.GetFiles()) //{ var files = directory.GetFiles(); Parallel.ForEach(files, new ParallelOptions { MaxDegreeOfParallelism = MaxFileThreadsAtOneTime }, file => { using (IDbConnection db = _factory.OpenDbConnection()) { var wf = db.QuerySingle <WatchedFile>(new { Path = file.FullName }); if (null == wf) { // create the file since it didn't exist wf = new WatchedFile { Path = file.FullName, LastReadFileSize = 0, CurrentFileSize = file.Length }; db.Insert <WatchedFile>(wf); } else if (file.Length != wf.CurrentFileSize) { // update file size if necessary wf.CurrentFileSize = file.Length; db.UpdateOnly <WatchedFile>(wf, ev => ev.Update(f => f.CurrentFileSize).Where(f => f.Path == file.FullName)); } } }); if (includeSubdirectories) { foreach (DirectoryInfo di in directory.GetDirectories()) { this.Initialize(di.FullName, includeSubdirectories); } } }
public void ParseLog(WatchedFile file) { Stopwatch watch = new Stopwatch(); watch.Start(); long lines = 0; string line; var thisFilePlugins = _plugins.Where(p => p.Enabled && p.BeforeFile(file.Path)); log.InfoFormat("Starting file: {0}", file.Path); if (thisFilePlugins.Count() > 0) { using (var logFile = new LogFileReader(file.Path)) { if (file.LastReadFileSize > 0) { logFile.Seek(file.LastReadFileSize); } while ((line = logFile.ReadLine()) != null) { foreach (var plugin in thisFilePlugins) { plugin.ParseLine(file.Path, line); } lines++; } foreach (var plugin in thisFilePlugins) { plugin.AfterFile(file.Path); } } } log.InfoFormat("{0} lines processed in {1}.", lines, watch.Elapsed); }
public void ParseLog(WatchedFile file) { Stopwatch watch = new Stopwatch(); watch.Start(); long lines = 0; string line; var thisFilePlugins = _plugins.Where(p => p.Enabled && p.BeforeFile(file.Path)); log.InfoFormat("Starting file: {0}", file.Path); if (thisFilePlugins.Count() > 0) { using (var logFile = new LogFileReader(file.Path)) { if (file.LastReadFileSize > 0) logFile.Seek(file.LastReadFileSize); while ((line = logFile.ReadLine()) != null) { foreach (var plugin in thisFilePlugins) { plugin.ParseLine(file.Path, line); } lines++; } foreach (var plugin in thisFilePlugins) { plugin.AfterFile(file.Path); } } } log.InfoFormat("{0} lines processed in {1}.", lines, watch.Elapsed); }
/// <summary> /// Try to pick a file off the queue. It might be that something else already started working. /// If so, return false so we can ignore it. /// </summary> /// <param name="file"></param> /// <returns></returns> public bool StartProcessing(WatchedFile file) { using (IDbConnection db = _factory.OpenDbConnection()) { file.Processing = true; return db.UpdateOnly<WatchedFile>(file, ev => ev.Update(f => f.Processing).Where(f => f.Id == file.Id && !f.Processing)) > 0; } }
/// <summary> /// Create or check an initial index of files since last time we started /// </summary> private void Initialize(string baseDirectory, bool includeSubdirectories = true) { DirectoryInfo directory = new DirectoryInfo(baseDirectory); //foreach (FileInfo file in directory.GetFiles()) //{ var files = directory.GetFiles(); Parallel.ForEach(files, new ParallelOptions { MaxDegreeOfParallelism = MaxFileThreadsAtOneTime }, file => { using (IDbConnection db = _factory.OpenDbConnection()) { var wf = db.QuerySingle<WatchedFile>(new { Path = file.FullName }); if (null == wf) { // create the file since it didn't exist wf = new WatchedFile { Path = file.FullName, LastReadFileSize = 0, CurrentFileSize = file.Length }; db.Insert<WatchedFile>(wf); } else if (file.Length != wf.CurrentFileSize) { // update file size if necessary wf.CurrentFileSize = file.Length; db.UpdateOnly<WatchedFile>(wf, ev => ev.Update(f => f.CurrentFileSize).Where(f => f.Path == file.FullName)); } } }); if (includeSubdirectories) { foreach (DirectoryInfo di in directory.GetDirectories()) { this.Initialize(di.FullName, includeSubdirectories); } } }
public void StopProcessing(WatchedFile file) { using (IDbConnection db = _factory.OpenDbConnection()) { file.Processing = false; file.LastReadFileSize = file.CurrentFileSize; db.UpdateOnly<WatchedFile>(file, ev => ev.Update(new List<string> { "Processing", "LastReadFileSize" }).Where(f => f.Id == file.Id)); } }