/* * DOWNLOADER */ private void _downloadNextFile() { if (_files.Count <= 0) { return; } _downloading = true; _currentFile = _files.Dequeue(); OnFileChanged?.Invoke(this, _currentFile.FileName); var filePath = Path.GetFullPath("./") + _currentFile.FileName; if (File.Exists(filePath)) { File.Delete(filePath); } else { Directory.CreateDirectory(Path.GetDirectoryName(filePath)); } _fd = new FileDownloader(_currentFile.URL, _currentFile.FileName); _fd.MaxBytesPerSecond = Convert.ToInt64(Util.GetRealBytesPerSecondsFromValue( Convert.ToDouble(IniLoader.Instance.Read("MaxBytesPerSecond", "Settings") ?? "100.0"), 100)); _fd.OnProgress += _downloadProgressChanged; _fd.OnFinish += _downloadComplete; _fd.Start(); }
async UniTask OnChanged(object source, FileSystemEventArgs args, string root) { await UniTask.SwitchToMainThread(); //Change if (File.Exists(args.FullPath) || Directory.Exists(args.FullPath)) { //Directory change if (File.GetAttributes(args.FullPath) == FileAttributes.Directory) { OnDirectoryChanged?.Invoke(args.FullPath, root); } //File change else { string fileExtension = $"*{Path.GetExtension(args.FullPath)}"; for (int i = 0; i < FileExtensions.Length; i++) { if (fileExtension == FileExtensions[i]) { OnFileChanged?.Invoke(args.FullPath, root); break; } } } } //Remove else { OnDeleted?.Invoke(args.FullPath, root); } }
public WatchedFile(string path) { FullPath = path; var dirname = Path.GetDirectoryName(path); var filename = Path.GetFileName(path); if (Utils.EnsureDirectory(dirname)) { m_watcher = new FileSystemWatcher(dirname, filename); m_watcher.NotifyFilter = NotifyFilters.LastWrite; m_watcher.Changed += (o, e) => { // This event is triggered multiple times. We defer its // handling so that it is not called more than once every // 500 milliseconds. if (OnFileChanged?.GetInvocationList().Length > 0) { m_reload_timer.Change(500, Timeout.Infinite); } }; m_watcher.EnableRaisingEvents = true; m_reload_timer = new Timer(o => { Logger.Info($"File {filename} changed, reloading."); OnFileChanged?.Invoke(); }); } }
private void ProcessCommand(uint commandCode) { switch (commandCode) { case (uint)NppMsg.NPPN_READY: OnReady?.Invoke(); break; case (uint)NppMsg.NPPN_TBMODIFICATION: _funcItems.RefreshItems(); SetToolBarIcons(); break; case (uint)SciMsg.SCN_CHARADDED: break; case (uint)NppMsg.NPPN_SHUTDOWN: OnShutDown?.Invoke(); _funcItems.Dispose(); break; case (uint)NppMsg.NPPN_FILESAVED: OnFileSaved?.Invoke(); break; case (uint)NppMsg.NPPN_BUFFERACTIVATED: OnFileChanged?.Invoke(); break; } }
private async Task OnChanged(string fullPath, WatcherChangeTypes changeType, bool isAFolder) { _logger.LogInformation($"{nameof(OnChanged)}: Handling change = {changeType} for = {fullPath} which is a folder = {isAFolder}"); switch (changeType) { case WatcherChangeTypes.Deleted: if (OnFileDeleted != null) { await OnFileDeleted.Invoke(fullPath, isAFolder); } break; case WatcherChangeTypes.Changed: if (OnFileChanged != null) { await OnFileChanged.Invoke(fullPath, isAFolder); } break; case WatcherChangeTypes.Created: if (OnFileCreated != null) { await OnFileCreated.Invoke(fullPath, isAFolder); } break; } }
private void mapsetFileWatcher_Changed(object sender, FileSystemEventArgs e) => scheduler.Schedule(e.FullPath, (key) => { if (disposedValue) return; if (Path.GetExtension(e.Name) == ".osu") Trace.WriteLine($"Watched mapset file {e.ChangeType.ToString().ToLowerInvariant()}: {e.FullPath}"); OnFileChanged?.Invoke(sender, e); });
/// <summary> /// When timer elapsed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Timer_Elapsed(object sender, ElapsedEventArgs e) { _info.Refresh(); if (_lastModifiedDate < _info.LastWriteTimeUtc) { _lastModifiedDate = _info.LastWriteTimeUtc; OnFileChanged?.Invoke(); } }
public void SendChanged(object sender, FileChangedArgs arg) { try { UIDevice.CurrentDevice.InvokeOnMainThread(() => { OnFileChanged?.Invoke(sender, arg); }); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"EXCEPTION: {this?.GetType()?.Name}.SendChanged({sender?.GetType()?.Name}, {arg}): {ex.Message}\n{ex.StackTrace}"); } }
public static Int64 CountLine(String dir, String fileExt) { DirectoryChangedEventArgs args = new DirectoryChangedEventArgs(); args.DirectoryPath = dir; Int64 lineCount = 0; // 先遍历所有文件 string[] files; try { files = System.IO.Directory.GetFiles(dir); } catch (Exception ex) { args.IsOpenSuccess = false; args.ErrMessage = ex.Message; OnDirectoryChanged?.Invoke(args); return(0); } args.IsOpenSuccess = true; OnDirectoryChanged?.Invoke(args); if (files != null && files.Length > 0) { foreach (string file in files) { if (file.EndsWith(fileExt)) { Int32 tmpCount = CountFileLine(file); lineCount += tmpCount; OnFileChanged?.Invoke(file, tmpCount); } } } string[] dirs = System.IO.Directory.GetDirectories(dir); if (dirs != null && dir.Length > 0) { foreach (string d in dirs) { lineCount += CountLine(d, fileExt); } } return(lineCount); }
//File Sync /// <summary> /// Starts a file watching thread detecting changes /// </summary> public void StartFileWatch() { if (IsWatchingFile) { return; } IsWatchingFile = true; bool isNetworking = IsNetworked; new Thread(() => { while (IsWatchingFile) { List <BlendFarmFileSession> sessions = GetSessions(); foreach (BlendFarmFileSession session in sessions) { try { if (new FileInfo(session.BlendFile).LastWriteTime.Ticks != session.FileID || isNetworking != IsNetworked) { if (isNetworking != IsNetworked) { session.FileID = -1; } isNetworking = IsNetworked; if (!Syncing && (CurrentTask == null || AlwaysUpdateFile)) { UpdateFileVersion(session.BlendFile, isNetworking); OnFileChanged?.Invoke(this); } } } catch (Exception ex) { Console.WriteLine($"File Watch exception: [{ex.GetType().Name}] {ex.Message}"); } } Thread.Sleep(WatchInterval); } }).Start(); }
private void watcher_Changed(object sender, FileSystemEventArgs e) { Trace.WriteLine($"File {e.ChangeType.ToString().ToLowerInvariant()}: {e.FullPath}"); scheduler.Schedule(e.FullPath, (key) => { if (disposedValue) { return; } lock (watchedFilenames) if (!watchedFilenames.Contains(e.FullPath)) { return; } Trace.WriteLine($"Watched file {e.ChangeType.ToString().ToLowerInvariant()}: {e.FullPath}"); OnFileChanged?.Invoke(sender, e); }); }
void ProcessDirectory(string path, string root) { OnDirectoryChanged?.Invoke(path, root); //Recursive branching string[] subFolders = Directory.GetDirectories(path); for (int i = 0; i < subFolders.Length; i++) { ProcessDirectory(subFolders[i], root); } for (int i = 0; i < FileExtensions.Length; i++) { string[] files = Directory.GetFiles(path, FileExtensions[i]); for (int j = 0; j < files.Length; j++) { OnFileChanged?.Invoke(files[j], root); } } }
//File Sync /// <summary> /// Starts a file watching thread detecting changes /// </summary> public void StartFileWatch() { if (IsWatchingFile) { return; } IsWatchingFile = true; new Thread(() => { while (IsWatchingFile) { if (new FileInfo(BlendFile).LastWriteTime.Ticks != FileID) { if (!Syncing && (CurrentTask == null || AlwaysUpdateFile)) { UpdateFileVersion(); OnFileChanged?.Invoke(this); } } Thread.Sleep(WatchInterval); } }).Start(); }
public void FireFileChangedEvent(object sender, FileChangedEventArgs fileChangedEventArgs) { OnFileChanged?.Invoke(this, fileChangedEventArgs); }