Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 /// <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);
     }
 }
Exemplo n.º 3
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));
     }
 }
Exemplo n.º 4
0
 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);
     }
 }
Exemplo n.º 7
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);
                }
            }
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
 /// <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;
     }
 }
Exemplo n.º 11
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);
                }
            }
        }
Exemplo n.º 12
0
 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));
     }
 }