private void OnDirectoryChanged() { if (DirectoryChanged != null) { DirectoryChanged.Invoke(this, EventArgs.Empty); } }
public DirectoryWatcher(string pathToDirectory, string filter, bool createIfNotExists, DirectoryChanged directoryChanged) { if (string.IsNullOrEmpty(pathToDirectory)) { throw new ArgumentNullException("pathToDirectory"); } else if (!Directory.Exists(pathToDirectory)) { if (createIfNotExists) { Directory.CreateDirectory(pathToDirectory); } else { throw new InvalidOperationException(pathToDirectory + "does not exist"); } } directoryPath = pathToDirectory; DirectoryChangedHandler = directoryChanged; fileSystemWatcher = new FileSystemWatcher(); fileSystemWatcher.Path = pathToDirectory; fileSystemWatcher.Filter = filter; fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite; fileSystemWatcher.Changed += new FileSystemEventHandler(OnChanged); fileSystemWatcher.EnableRaisingEvents = true; }
private void RecursivelyChangeTimeStamp(Folder folder, DateTime newDt) { // Change this folder. var diBefore = new DirectoryInfo(folder.FolderInfo.FullName); folder.FolderInfo.CreationTime = newDt; folder.FolderInfo.LastAccessTime = newDt; folder.FolderInfo.LastWriteTime = newDt; DirectoryChanged?.Invoke(diBefore, folder.FolderInfo); // Change files in this folder. foreach (var file in folder.Files) { var fiBefore = new FileInfo(file.FullName); file.CreationTime = newDt; file.LastAccessTime = newDt; file.LastWriteTime = newDt; FileChanged.Invoke(fiBefore, file); } // Change files in subfolders. foreach (var subfolder in folder.SubFolders) { RecursivelyChangeTimeStamp(subfolder, newDt); } }
public void Search(string path, string searchPattern, bool searchSubDirectories = false) { if (searchSubDirectories) { var allDirectories = Directory.GetDirectories(path, "*.*", SearchOption.AllDirectories); var completedDirectories = 0; var totalDirectories = allDirectories.Length + 1; foreach (var directory in allDirectories) { DirectoryChanged?.Invoke(this, new SearchDirectoryArgs(directory, totalDirectories, completedDirectories++)); SearchDirectory(directory, searchPattern); } DirectoryChanged?.Invoke(this, new SearchDirectoryArgs(path, totalDirectories, completedDirectories++)); SearchDirectory(path, searchPattern); } else { SearchDirectory(path, searchPattern); } }
public string Move(string name) { var old_path = CurrentPath; var sep = Path.DirectorySeparatorChar; var path = name.Replace(':', sep).Replace('/', sep); path = Path.GetFullPath(Path.Combine(CurrentPath, path)); name = ""; if (File.Exists(path)) { name = Path.GetFileName(path); path = Path.GetDirectoryName(path); } if (!Directory.Exists(path)) { return(null); } if (!path.StartsWith(RootDirectory)) { return(null); } if (old_path != path) { CurrentDirectory = path.Replace(RootDirectory, ""); if (CurrentDirectory.Length > 0 && CurrentDirectory[0] == sep) { CurrentDirectory = CurrentDirectory.Remove(0, 1); } DirectoryWatcher.Path = CurrentPath; DirectoryWatcher.EnableRaisingEvents = true; DirectoryChanged?.Invoke(this, new WalkerEventArgs(old_path, path)); } return(name); }
private async Task <T> ProcessDirectoryChanges <T>(T item) where T : FileSystemItem { var serializedDirectory = new FileSystemDirectorySerializer().Serialize(FileSystemItems.Values.Where(p => p.HasParent)); await LocalStorageRepository.SetItem(LocalStorageDirectoryFileName, serializedDirectory); DirectoryChanged?.Invoke(this, EventArgs.Empty); return(item); }
void IRCallbacks.DirectoryChanged() { if (_processingChangeDirectoryCommand) { DirectoryChanged?.Invoke(this, EventArgs.Empty); _processingChangeDirectoryCommand = false; } }
private void FireEvent(string path) { DirectoryChanged evt = Changed; if (evt != null) { evt(path); } }
private void Watcher_Created(object sender, FileSystemEventArgs e) { watcher.EnableRaisingEvents = true; FileEvent = "New file: " + e.Name; if (!IsFileLocked(e.FullPath)) { LastWriteTime = DateTime.Now; ArchiveName = FilesDestinationDirectory + "\\" + DateTime.Now.ToShortDateString() + " - " + DateTime.Now.Hour.ToString() + "h " + DateTime.Now.Minute.ToString() + "m " + DateTime.Now.Second.ToString() + "s " + ".zip"; isChanging = false; DirectoryChanged?.Invoke(this, EventArgs.Empty); } }
public SolutionExplorerView() { InitializeComponent(); openScriptingDirectoryButton.Click += (o, e) => { if (directoryBrowserDialog.ShowDialog(this) == DialogResult.OK) { DirectoryChanged?.Invoke(this, new DirectorySelectedEventArgs(directoryBrowserDialog.SelectedPath)); } }; }
public void RegisterEvents(DataChanged dataChanged, DirectoryChanged directoryChanged, DirectoryNameChanged directoryNameChanged, NavigateFiles navigateFiles, GetAllFilesDelegate ListAllCheckedFiles, GetAllFilesDelegate ListSelectedDirectory) { foreach (IPictureDetailControllerBase p in this) { p.DataChangedEvent += dataChanged; p.DirectoryChangedEvent += directoryChanged; p.DirectoryNameChangedEvent += directoryNameChanged; p.NavigateFilesEvent += navigateFiles; p.SetGetAllFilesDelegate(ListAllCheckedFiles, ListSelectedDirectory); } }
protected override void OnDoWork(DoWorkEventArgs e) { // ... while (_directories.Count != 0 || _queue.Count != 0) { _debugger.Trace(); // First, clearing queue... while (_queue.Count > 0) { // Retireving path and going level up var key = Path.GetDirectoryName(_queue.Dequeue()) + Path.DirectorySeparatorChar; // Depending on existence of key, adding or updating time if (!_directories.ContainsKey(key)) { _directories.Add(key, _unixTime.Now); } else { _directories[key] = _unixTime.Now; } } // ... var path = string.Empty; // Searching for expired row. foreach (var pair in _directories) { if (_unixTime.Difference(pair.Value + 5) > 0) { path = pair.Key; break; } } // Invoking event & removing expired row if (!string.IsNullOrEmpty(path)) { _directories.Remove(path); DirectoryChanged?.Invoke(this, new DirectoryChangedEventArgs(path)); } } }
public bool Load(string root) { root = Path.GetFullPath(root); if (!Directory.Exists(root)) { return(false); } string old_path = RootDirectory; RootDirectory = root; CurrentDirectory = ""; DirectoryWatcher.Path = RootDirectory; DirectoryWatcher.EnableRaisingEvents = true; DirectoryChanged?.Invoke(this, new WalkerEventArgs(old_path, RootDirectory)); return(true); }
public static IDisposable Watch(string directory, DirectoryChanged callback) { var watcher = Get(directory); FileSystemEventHandler onCreated = (sender, e) => { var local = FileUtils.TryToGetRelativePath(e.FullPath, directory); if (local == string.Empty) { callback(null); } else if (local != null) { callback(e.FullPath); } }; FileSystemEventHandler onChanged = (sender, e) => { var local = FileUtils.TryToGetRelativePath(e.FullPath, directory); if (!string.IsNullOrEmpty(local)) { callback(e.FullPath); } }; FileSystemEventHandler onDeleted = (sender, e) => { var local = FileUtils.TryToGetRelativePath(e.FullPath, directory); if (local == string.Empty) { callback(null); } else if (local != null) { callback(e.FullPath); } }; RenamedEventHandler onRenamed = (sender, e) => { var localOld = FileUtils.TryToGetRelativePath(e.OldFullPath, directory); var localNew = FileUtils.TryToGetRelativePath(e.FullPath, directory); if (localOld == string.Empty || localNew == string.Empty) { callback(null); } else { if (localNew != null) { callback(e.FullPath); } if (localOld != null) { callback(e.OldFullPath); } } }; watcher.Created += onCreated; watcher.Changed += onChanged; watcher.Deleted += onDeleted; watcher.Renamed += onRenamed; return(new Holder <IDisposable>(watcher, d => { var w = (FileSystemWatcher)d; w.Created -= onCreated; w.Changed -= onChanged; w.Deleted -= onDeleted; w.Renamed -= onRenamed; Release(w); })); }
private void OnDirectoryChanged(DirectoryChangedEventArgs e) { DirectoryChanged?.Invoke(this, e); }
private static IDisposable SetWatcher(string directory, DirectoryChanged callback) { var watcher = Get(directory); void OnCreated(object sender, FileSystemEventArgs e) { var local = FileUtils.GetPathWithin(e.FullPath, directory); if (local == string.Empty) { callback(null); } else if (local != null) { callback(e.FullPath); } } void OnChanged(object sender, FileSystemEventArgs e) { var local = FileUtils.GetPathWithin(e.FullPath, directory); if (!string.IsNullOrEmpty(local)) { callback(e.FullPath); } } void OnDeleted(object sender, FileSystemEventArgs e) { var local = FileUtils.GetPathWithin(e.FullPath, directory); if (local == string.Empty) { callback(null); } else if (local != null) { callback(e.FullPath); } } void OnRenamed(object sender, RenamedEventArgs e) { var localOld = FileUtils.GetPathWithin(e.OldFullPath, directory); var localNew = FileUtils.GetPathWithin(e.FullPath, directory); if (localOld == string.Empty || localNew == string.Empty) { callback(null); } else { if (localNew != null) { callback(e.FullPath); } if (localOld != null) { callback(e.OldFullPath); } } } watcher.Created += OnCreated; watcher.Changed += OnChanged; watcher.Deleted += OnDeleted; watcher.Renamed += OnRenamed; return(new Holder <IDisposable>(watcher, d => { var w = (FileSystemWatcher)d; w.Created -= OnCreated; w.Changed -= OnChanged; w.Deleted -= OnDeleted; w.Renamed -= OnRenamed; Release(w); })); }
public static IDisposable WatchDirectory(string directory, DirectoryChanged callback) { return(SetWatcher(Path.GetDirectoryName(directory) ?? "", callback)); }
protected virtual void OnDirectoryChanged(DirectoryChangedEventArgs e) { DirectoryChanged?.Invoke(this, e); }
private void DirectoryWatcher_Changed(object sender, EventArgs e) { var path = Path.Combine(RootDirectory, CurrentDirectory); DirectoryChanged?.Invoke(this, new WalkerEventArgs(path, path)); }
void IRCallbacks.DirectoryChanged() { DirectoryChanged?.Invoke(this, EventArgs.Empty); }
public void RaiseDirectoryChanged(string path) { DirectoryChanged?.Invoke(this, path); }
/// <summary> /// Executed when search changes the current directory. /// </summary> /// <param name="directory">The directory.</param> protected virtual void OnDirectoryChanged(string directory) { DirectoryChanged?.Invoke(directory); }
public static void CallDirectoryChanged() { DirectoryChanged?.Invoke(); }
protected virtual void OnDirectoryChanged() { DirectoryChanged?.Invoke(this, null); }