コード例 #1
0
 public FileSystemWatcherEventArgs(
     string name,
     string fullPath,
     FileSystemWatcherChangeType changeType)
 {
     this.Name = name;
     this.FullPath = fullPath;
     this.ChangeType = changeType;
 }
 public FileSystemWatcherRenameEventArgs(
     string name,
     string fullPath,
     FileSystemWatcherChangeType changeType,
     string oldName,
     string oldPath) : base(name, fullPath, changeType)
 {
     this.OldName = oldName;
     this.OldPath = oldPath;
 }
コード例 #3
0
 private void ReportChangeType(FileListEnum current,
                               CancellationToken token,
                               Action <object, WatcherCallbackArgs> report,
                               FileSystemWatcherChangeType changeType)
 {
     if (token.IsCancellationRequested)
     {
         throw new OperationCanceledException();
     }
     foreach (var file in current)
     {
         Trace.TraceInformation($"Reporting changes in directory: {_settings.ScanDirectory}  file: {file} changetype: {changeType}");
         report(this, new WatcherCallbackArgs(file.Key, changeType));
     }
 }
コード例 #4
0
        void CreateFileHelper(Func <string, FileStream> createFileBefore, Func <string, FileStream> createFileAfter, FileSystemWatcherChangeType type)
        {
            var scanDirectory = GetAndPrepareTempDirectory();

            FileStream fileBefore = createFileBefore?.Invoke(scanDirectory);


            var m = new ManualScanPhysicalFileSystemWatcher(new ManualScanPhysicalFileSystemWatcherSettings {
                ScanDirectory = scanDirectory, ScanSpeedInSeconds = 0
            });

            ManualResetEvent changeDetected  = new ManualResetEvent(false);
            ManualResetEvent scanInitialized = new ManualResetEvent(false);

            m.Open(new FilterAndCallbackArgument(String.Empty, (o, args) =>
            {
                if (args.ChangeType == type)
                {
                    changeDetected.Set();
                }
            },
                                                 o =>
            {
                scanInitialized.Set();
            }));

            var completedScan = scanInitialized.WaitOne(500);

            Assert.True(completedScan);

            FileStream file      = createFileAfter?.Invoke(scanDirectory);
            var        completed = changeDetected.WaitOne(500);

            Assert.True(completed);
            file?.Dispose();
            fileBefore?.Dispose();

            m.Dispose();

            DeleteAndReturnTempDirectoryName();
        }
コード例 #5
0
 public WatcherCallbackArgs(string fileName, FileSystemWatcherChangeType changeType)
 {
     FileName   = fileName;
     ChangeType = changeType;
 }
コード例 #6
0
 // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
 void CheckHelper(FilterAndCallbackArgument local, string fileName, ref FileEntry lastEntry, FileSystemWatcherChangeType ft)
 {
     local.ActionChanges(this, new WatcherCallbackArgs(fileName, ft));
     Assert.True(lastEntry?.FileName == fileName && lastEntry?.LastChanges == ft);
 }