Esempio n. 1
0
        static void OnChanged(object source, FileSystemEventArgs e)
        {
            Console.WriteLine($"File: {e.FullPath} {e.ChangeType}");

            BackupCreation.CreateBackupDirectories(BackupCreation.GetAllFilesForBackups(Program.pathToOriginal), Program.pathToAllBackups);

            BackupCreation.CreateBackup(e.FullPath);
        }
Esempio n. 2
0
        private static string GetBackupDirectory(int docnum, string pathtooriginals, string pathtobackups)
        {
            string[] originalFiles   = BackupCreation.GetAllFilesForBackups(pathtooriginals);
            string   name            = Path.GetFileName(originalFiles[docnum]);
            string   pathToDirectory = string.Format(@"{0}{1}\", pathtobackups, name);

            return(pathToDirectory);
        }
Esempio n. 3
0
 public static void ShowOriginalFiles(string path)
 {
     string[] originalFiles = BackupCreation.GetAllFilesForBackups(path);
     for (int i = 0; i < originalFiles.Length; i++)
     {
         Console.WriteLine($"{i}   {originalFiles[i]}");
     }
 }
Esempio n. 4
0
        public static void FileRecover(int docnum, int versionum, string pathtooriginals, string pathtobackups)
        {
            string[] filesToBackup = Directory.GetFiles(GetBackupDirectory(docnum, pathtooriginals, pathtobackups));
            string   pathToFile    = string.Format(filesToBackup[versionum]);

            string[] originalFiles  = BackupCreation.GetAllFilesForBackups(pathtooriginals);
            string   name           = Path.GetFileName(originalFiles[docnum]);
            string   pathToOriginal = string.Format(@"{0}{1}", pathtooriginals, name);

            string[] strings = File.ReadAllLines(pathToFile);
            File.WriteAllLines(pathToOriginal, strings);
        }
Esempio n. 5
0
        public static void DoCase1()
        {
            FileSystemWatcher watcher = new FileSystemWatcher();

            watcher.Path     = Program.pathToOriginal;
            watcher.Filter   = "*.txt";
            watcher.Changed += OnChanged;
            watcher.Created += OnChanged;
            watcher.Deleted += OnChanged;
            watcher.Renamed += OnRenamed;

            string[] files = BackupCreation.GetAllFilesForBackups(Program.pathToOriginal);
            BackupCreation.CreateBackupDirectories(files, Program.pathToAllBackups);
            BackupCreation.CreateBackup(files, Program.pathToAllBackups);

            watcher.EnableRaisingEvents = true;

            Console.ReadKey();
        }
Esempio n. 6
0
        static void OnRenamed(object source, RenamedEventArgs e)
        {
            Console.WriteLine($"File: {e.OldFullPath} renamed to {e.FullPath}");

            BackupCreation.RenameDirectory(e.FullPath, e.OldFullPath);
        }