示例#1
0
        static void RollbackChanges(FileChangeInfo fileInfo)
        {
            switch (fileInfo.ChangeFileMode)
            {
            case WatcherChangeTypes.Renamed:
                File.Move(fileInfo.FullPath, fileInfo.OldFullPath);
                break;

            case WatcherChangeTypes.Changed:
                using (StreamWriter sw = new StreamWriter(fileInfo.FullPath, false, Encoding.Default))
                {
                    sw.Write(fileInfo.OldContent);
                }
                break;

            case WatcherChangeTypes.Deleted:
                using (StreamWriter sw = new StreamWriter(fileInfo.FullPath, false, Encoding.Default))
                {
                    sw.Write(fileInfo.OldContent);
                }
                break;

            case WatcherChangeTypes.Created:
                File.Delete(fileInfo.FullPath);
                break;
            }
        }
示例#2
0
        private static void OnRenamed(object source, RenamedEventArgs e)
        {
            Console.WriteLine($"File: {e.OldFullPath} renamed to {e.FullPath}");
            FileChangeInfo FileLog = new FileChangeInfo(e.Name, e.FullPath, e.OldFullPath, DateTime.Now, e.ChangeType, "", "");

            BackupList.Add(DateTime.Now, FileLog);
            DataProvider.Serialized(path);
            DataProvider.DeSerialized(path);
        }
示例#3
0
        public static void ProcessFile(string path)
        {
            string content;
            string fileName;

            content  = GetFileContent(path);
            fileName = Path.GetFileName(path);
            FileChangeInfo FileLog = new FileChangeInfo(fileName, path, "", DateTime.Now, WatcherChangeTypes.Created, content, content);

            Watcher.BackupList.Add(DateTime.Now, FileLog);
        }
示例#4
0
        // Define the event handlers.
        private static void OnChanged(object source, FileSystemEventArgs e)
        {
            string content;
            string oldContent;

            oldContent = BackupList.LastOrDefault(n => n.Key < DateTime.Now && n.Value.FullPath == e.FullPath).Value.Content;
            Console.WriteLine($"File: {e.FullPath} {e.ChangeType}");
            if (e.ChangeType != WatcherChangeTypes.Deleted)
            {
                content = DataProvider.GetFileContent(e.FullPath);
            }
            else
            {
                content = "";
            }
            FileChangeInfo FileLog = new FileChangeInfo(e.Name, e.FullPath, "", DateTime.Now, e.ChangeType, content, oldContent);

            BackupList.Add(DateTime.Now, FileLog);
            DataProvider.Serialized(path);
            DataProvider.DeSerialized(path);
        }