public LocalDirectory(LocalFileSystem fileSystem, LocalNodeAddress address)
     : base(fileSystem, address)
 {
     this.directoryInfo = new DirectoryInfo(address.AbsoluteNativePath);
 }
Esempio n. 2
0
        private void InitializeFsw()
        {
            lock (this)
            {
                if (this.fileSystemWatcherInitialised)
                {
                    return;
                }

                WeakReference weakref;
                EventHandler <LocalFileSystemEventArgs> handler = null;

                weakref = new WeakReference(this);

                handler = delegate(object sender, LocalFileSystemEventArgs eventArgs)
                {
                    LocalFileSystem _this = (LocalFileSystem)weakref.Target;

                    if (_this == null)
                    {
                        LocalFileSystem.DirectoryDeleted -= handler;

                        return;
                    }

                    string s;

                    s = (((LocalDirectory)eventArgs.Directory).directoryInfo.FullName);

                    if (this.PathsEqual(((LocalNodeAddress)this.RootAddress).AbsoluteNativePath, s, s.Length))
                    {
                        // This allows the directory to be deleted

                        this.fileSystemWatcherDirectory.EnableRaisingEvents = false;
                        this.fileSystemWatcherFile.EnableRaisingEvents      = false;

                        // TODO: Use file system watcher from level above to allow
                        // events to still be fired if the directory gets recreated
                    }
                };

                LocalFileSystem.DirectoryDeleted += handler;

                // We need two different watchers since we need to determine if the renamed/created/deleted events
                // occured on a file or a directory.
                // Changed events occur on both dirs and files regardless of the NotifyFilters setting so the
                // File watcher will be responsible for handling that.

                DriveInfo driveInfo;

                try
                {
                    driveInfo = new DriveInfo(((LocalNodeAddress)this.RootAddress).AbsoluteNativePath);
                }
                catch (ArgumentException)
                {
                    driveInfo = null;
                }

                if (driveInfo == null || (driveInfo != null && driveInfo.DriveType != DriveType.Removable))
                {
                    if (!Directory.Exists(((LocalNodeAddress)this.RootAddress).AbsoluteNativePath))
                    {
                        // TODO: Use directory above

                        return;
                    }

                    string path;

                    path = ((LocalNodeAddress)this.RootAddress).AbsoluteNativePath;

                    path = path.TrimEnd('/', '\\');

                    if (Environment.OSVersion.Platform != PlatformID.Unix)
                    {
                        if (Path.GetDirectoryName(path) != null)
                        {
                            path = Path.GetDirectoryName(path);
                        }
                    }

                    if (!path.EndsWith(Path.DirectorySeparatorChar.ToString()))
                    {
                        path += Path.DirectorySeparatorChar;
                    }

                    this.fileSystemWatcherFile = new FileSystemWatcher(path);
                    this.fileSystemWatcherFile.InternalBufferSize    = 64 * 1024 /* 128K buffer */;
                    this.fileSystemWatcherFile.IncludeSubdirectories = true;
                    this.fileSystemWatcherFile.NotifyFilter          =
                        NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.FileName                         /* Files only */
                        | NotifyFilters.LastAccess | NotifyFilters.LastWrite /*| NotifyFilters.Security | NotifyFilters.Size*/;

                    this.fileSystemWatcherFile.Renamed += new RenamedEventHandler(FileSystemWatcher_Renamed);
                    this.fileSystemWatcherFile.Changed += new FileSystemEventHandler(FileSystemWatcher_Changed);
                    this.fileSystemWatcherFile.Created += new FileSystemEventHandler(FileSystemWatcher_Created);
                    this.fileSystemWatcherFile.Deleted += new FileSystemEventHandler(FileSystemWatcher_Deleted);
                    this.fileSystemWatcherFile.Error   += new ErrorEventHandler(FileSystemWatcher_Error);

                    this.fileSystemWatcherDirectory = new FileSystemWatcher(path);
                    this.fileSystemWatcherDirectory.InternalBufferSize    = 64 * 1024;
                    this.fileSystemWatcherDirectory.IncludeSubdirectories = true;
                    this.fileSystemWatcherDirectory.NotifyFilter          =
                        NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName                         /* Dirs only */
                        | NotifyFilters.LastAccess | NotifyFilters.LastWrite /*| NotifyFilters.Security | NotifyFilters.Size*/;

                    this.fileSystemWatcherDirectory.Filter   = "*";
                    this.fileSystemWatcherDirectory.Renamed += new RenamedEventHandler(FileSystemWatcher_Renamed);
                    this.fileSystemWatcherDirectory.Created += new FileSystemEventHandler(FileSystemWatcher_Created);
                    this.fileSystemWatcherDirectory.Deleted += new FileSystemEventHandler(FileSystemWatcher_Deleted);
                    //fileSystemWatcherDirectory.Changed += new FileSystemEventHandler(FileSystemWatcher_Changed);
                    this.fileSystemWatcherDirectory.Error += new ErrorEventHandler(FileSystemWatcher_Error);

                    this.fileSystemWatcherInitialised = true;
                }
            }
        }
 public LocalFile(LocalFileSystem fileSystem, LocalNodeAddress address)
     : base(address, fileSystem)
 {
     this.FileSystem = fileSystem;
     this.fileInfo   = new FileInfo(address.AbsoluteNativePath);
 }
		public LocalDirectory(LocalFileSystem fileSystem, LocalNodeAddress address)
			: base(fileSystem, address)
		{
			this.directoryInfo = new DirectoryInfo(address.AbsoluteNativePath);
		}
		public LocalFile(LocalFileSystem fileSystem, LocalNodeAddress address)
			: base(address, fileSystem)
		{
			this.FileSystem = fileSystem;
			this.fileInfo = new FileInfo(address.AbsoluteNativePath);
		}