コード例 #1
0
        private void ProcessFileWatcherEvent(FileSystemEventArgs e)
        {
            FileWatcherEventArgs args = new FileWatcherEventArgs();

            args.FileName  = e.Name;
            args.EventName = e.ChangeType.ToString();
            args.EventTime = DateTime.Now;
            OnFileProcess?.Invoke(this, args);
            //
            string time_string =
                String.Format("{0:D4}-{1:D2}-{2:D2} {3:D2}:{4:D2}:{5:D2}:{6:D4}",
                              args.EventTime.Year, args.EventTime.Month, args.EventTime.Day, args.EventTime.Hour, args.EventTime.Minute, args.EventTime.Second, args.EventTime.Millisecond);
            string s = String.Format("{0,-24} - {1,-10} - {2,-255}", time_string, args.EventName, args.FileName);

            _logger.WriteLine(s);
            //
            string destFileName   = Path.Combine(_watcherParams.OutputDir, e.Name);
            string sourceFileName = e.FullPath;

            //
            if (!File.Exists(destFileName) && e.ChangeType == WatcherChangeTypes.Created)
            {
                _queueTaskWorker.AddToQueue(args);
            }
            else if (File.Exists(destFileName) && e.ChangeType == WatcherChangeTypes.Deleted)
            {
                File.Delete(destFileName);
            }
            else if (File.Exists(destFileName) && e.ChangeType == WatcherChangeTypes.Changed)
            {
                _queueTaskWorker.AddToQueue(args);
            }
        }