예제 #1
0
파일: Program.cs 프로젝트: pivovard/ZCU
 /// <summary>
 /// Kdyz se zmeni sledovany soubor
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="evetArgs"></param>
 static void fw_Changed(object sender, FileWatcherChangedEventArgs evetArgs)
 {
     if(evetArgs.Type==FileWatcherChangedType.Modified) {
         int pos = evetArgs.ChangePosition;
         Console.WriteLine("Prvni zmena na bytu {0} z {1} na {2}", pos, evetArgs.OriginalData[pos], evetArgs.NewData[pos]);
     }
 }
예제 #2
0
파일: FileWatcher.cs 프로젝트: pivovard/ZCU
        void watcher_Changed(object sender, FileSystemEventArgs e)
        {
            using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                newData = new byte[fs.Length];
                fs.Read(newData, 0, (int)fs.Length);
            }

            if (Changed != null)
            {
                var eventArg = new FileWatcherChangedEventArgs()
                {
                    NewData = newData,
                    OriginalData = originalData,
                    Type = FileWatcherChangedType.None
                };

                if (newData.Length > originalData.Length)
                {
                    eventArg.Type = FileWatcherChangedType.Added;
                }
                else if (newData.Length < originalData.Length)
                {
                    eventArg.Type = FileWatcherChangedType.Removed;
                }
                else
                {
                    for (int i = 0; i < originalData.Length; i++)
                    {
                        if (newData[i] != originalData[i])
                        {
                            eventArg.Type = FileWatcherChangedType.Modified;
                            eventArg.ChangePosition = i;
                        }
                    }
                }

                if (eventArg.Type != FileWatcherChangedType.None)
                {
                    Changed(this, eventArg);
                }
            }
        }