private void W_Created(object sender, FileSystemEventArgs e) { Helpers.mainCTX.Send(_ => { Helpers.ConsoleWrite(string.Format("[{0}]{1} : {2}", DateTime.Now.ToString(), e.FullPath, e.ChangeType)); if (!IsIgnored(e.FullPath)) { FilesTree.AddFile(e.FullPath); } }, null); }
private void W_Renamed(object sender, RenamedEventArgs e) { Helpers.mainCTX.Send(_ => { //попросим обновить файл, и т.к. событие может произойти несколько раз, установим флаг проверки даты изменения Helpers.ConsoleWrite(string.Format("[{0}]{1} => {2} : {3}", DateTime.Now.ToString(), e.OldFullPath, e.FullPath, e.ChangeType)); if (!IsIgnored(e.OldFullPath) || !IsIgnored(e.FullPath)) { if (_SolutionsFiles.Contains(e.OldFullPath)) { _SolutionsFiles.Remove(e.OldFullPath); _SolutionsFiles.Add(e.FullPath); } FilesTree.Remove(e.OldFullPath); var f = FilesTree.AddFile(e.FullPath); if (string.Equals(Selected?.FullPath, e.FullPath, StringComparison.InvariantCultureIgnoreCase)) { Selected = f; } } }, null); }
void AddFiles(ICollection <string> files, Action <string, int> callback = null) { EditingEnabled = false; var cts = new CancellationTokenSource(); FilesTree.BeginUpdate(); try { callback?.Invoke(null, files.Count); int cnt = 0; string currentFile = string.Empty; Task.Run(() => { while (!cts.IsCancellationRequested) { Task.Delay(1000); callback?.Invoke(currentFile, cnt); } }); //System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch(); //w.Start(); foreach (var f in files) { currentFile = f; ++cnt; FilesTree.AddFile(f); } //w.Stop(); } finally { cts.Cancel(); FilesTree.EndUpdate(); EditingEnabled = true; FilterFiles(); GC.Collect(); } }