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}"); } }
private void FileChanged_Action(object s, FileChangedArgs f) { bool watchStatus = watcher.EnableRaisingEvents; try { string findStrRaw = textBox_FindWhat.Text; string[] findStrings = findStrRaw.Replace(" ", "").Split(';'); string newStr = textBox_ReplaceWith.Text; if (findStrings == null || newStr == null) { logLines.Insert(0, DateTime.Now.ToString() + "Cannot replace any words"); return; } string content; using (StreamReader sr = new StreamReader(f.ChangedFile.FullName)) { content = sr.ReadToEnd(); } foreach (var findStr in findStrings) { content = content.Replace(findStr, newStr); } isFileModified = true; watcher.EnableRaisingEvents = false; lock (watcher) { using (StreamWriter sw = new StreamWriter(f.ChangedFile.FullName)) { sw.Write(content); } logLines.Insert(0, DateTime.Now.ToString() + " Data is modified" + Environment.NewLine); } } catch (Exception e) { logLines.Insert(0, DateTime.Now.ToString() + " **ERROR** " + e.ToString() + Environment.NewLine); return; } finally { isFileModified = false; watcher.EnableRaisingEvents = watchStatus; } }
void watcher_Detected(object sender, FileSystemEventArgs e) { watcher.EnableRaisingEvents = false; string logTextLine = string.Format("{0} {1}: {2}.{3}", DateTime.Now, e.ChangeType, e.Name, Environment.NewLine); logLines.Insert(0, logTextLine); if (e.ChangeType == WatcherChangeTypes.Changed) { FileChangedArgs fca = new FileChangedArgs(); fca.ChangedFile = new FileInfo(e.FullPath); if (FileChanged != null) { var fileChangedEvent = new EventHandler <FileChangedArgs>(FileChanged); fileChangedEvent(null, fca); } } watcher.EnableRaisingEvents = true; }
protected virtual void OnLinedAdded(List<string> lines, long position, bool clearAll) { if (LineAdded == null) { return; } FileChangedArgs args = new FileChangedArgs { Lines = lines, Position = position, ClearAll = clearAll }; LineAdded(this, args); }