Ejemplo n.º 1
0
        public bool Watch(string path, string filter)
        {
            try
            {
                path   = ConvertPathToOSPath(path);
                filter = ConvertPathToOSPath(filter);

                // Check to see if this is a path to a file name
                IsFile = !Directory.Exists(path);
                if (IsFile)
                {
                    // Use the file name as the filter
                    filter = Path.GetFileName(path);
                    // Get the file directory to use as the path
                    path = Path.GetDirectoryName(path);
                }
                Watcher.EnableRaisingEvents = false;
                Watcher.Path   = path;
                Watcher.Filter = filter ?? "*.*";
                Watcher.EnableRaisingEvents = Enabled;
                return(true);
            }
            catch (Exception e)
            {
                var message = string.IsNullOrWhiteSpace(path)
          ? UI.Localization.LocalizeString("RhinoFileWatcher.Watch *error* empty path", 39)
          : string.Format(UI.Localization.LocalizeString("RhinoFileWatcher.Watch *error* parsing path name \"{0}\"", 40), path);
                RhinoApp.WriteLine(message);
                RhinoFileEventWatcherHooks.DumpException(e);
                return(false);
            }
        }
Ejemplo n.º 2
0
 internal RhinoFileWatcher(IntPtr pointerToIRhinoFileEventWatcher)
 {
     try
     {
         Pointer = pointerToIRhinoFileEventWatcher;
         Watcher = new FileSystemWatcher
         {
             // Disable watching
             EnableRaisingEvents = false,
             // Watch for changes in LastAccess and LastWrite times, and the renaming of files or directories.
             NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName,
         };
         // Add event handlers.
         Watcher.Changed += OnChanged;
         Watcher.Created += OnChanged;
         Watcher.Deleted += OnChanged;
         Watcher.Renamed += OnRenamed;
         // Make sure they watchers are shutdown when closing Rhino
         RhinoApp.Closing += (sender, args) => Dispose();
     }
     catch (Exception exception)
     {
         RhinoFileEventWatcherHooks.ReportException(exception);
     }
 }