コード例 #1
0
 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}");
     }
 }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
        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;
        }
コード例 #4
0
ファイル: FileTextWatcher.cs プロジェクト: stjeong/Utilities
        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);
        }