public void AddTextFile(string path, string content) { var d = PathUtils.SplitDirAndFile(path, out var ff).ToString(); var f = ff.ToString(); if (_content.TryGetValue(new KeyValuePair <string, string>(d, f), out var file)) { if (file == null) { throw new Exception("Cannot add file because it is already dir " + path); } file._lastWriteTimeUtc = DateTime.UtcNow; file._content = content; file._length = (ulong)Encoding.UTF8.GetByteCount(content); return; } CreateDir(d); _content[new KeyValuePair <string, string>(d, f)] = new FakeFile { _content = content, _length = (ulong)Encoding.UTF8.GetByteCount(content), _lastWriteTimeUtc = DateTime.UtcNow }; OnFileChange?.Invoke(path); }
private void OnChanged(object sender, FileSystemEventArgs e) { if (!e.Name.Contains(DateTime.Now.ToString("yyyy-MM-dd"))) { return; // Only logs for today } OnFileChange?.Invoke(e); }
private void OnChanged(object sender, FileSystemEventArgs e) { if (e.FullPath.Contains("~") && e.FullPath.Contains("TMP")) { return; } if (string.IsNullOrWhiteSpace(Path.GetFileName(e.FullPath))) { return; } switch (e.ChangeType) { case WatcherChangeTypes.Created: OnFileCreate?.Invoke(e); break; case WatcherChangeTypes.Deleted: OnFileDelete?.Invoke(e); break; case WatcherChangeTypes.Changed: OnFileChange?.Invoke(e); break; case WatcherChangeTypes.Renamed: break; case WatcherChangeTypes.All: break; default: return; } }
private void NotifyChange(string fullPath) { // Only report file changes OnFileChange?.Invoke(this, fullPath); }
private void fileSystemWatcher_Changed(object sender, FileSystemEventArgs e) { OnFileChange?.Invoke(sender, e); }