Пример #1
0
        private void OnRenamed(object sender, RenamedEventArgs e)
        {
            ConsoleCaller.WriteSimpleLine("Root file name changed!");
            ConsoleCaller.WriteSimpleLine($"File: {e.OldFullPath} renamed to {e.FullPath}");
            DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath);

            save.CreateSaveState(dir.FullName);
        }
Пример #2
0
 public void CreateSaveState(string sourceDir)
 {
     try
     {
         DateTime      cur       = DateTime.Now;
         string        date      = cur.ToString("yyyyMMddHHmmss");
         DirectoryInfo subFolder = new DirectoryInfo(Path.Combine(saveFolder.FullName, date));
         subFolder.Create();
         CopyFilesToDir(sourceDir, subFolder.FullName);
     }
     catch (Exception e)
     {
         ConsoleCaller.WriteSimpleLine($"Oops! Something went wrong! Error - {e.ToString()}");
         return;
     }
     ConsoleCaller.WriteSimpleLine("Save sucessed!");
     ConsoleCaller.WriteSimpleLine("");
 }
Пример #3
0
 public void LoadSpecificDate(string sourceDir, string toLoad)
 {
     if (!Directory.Exists(Path.Combine(saveFolder.FullName, toLoad)))
     {
         ConsoleCaller.WriteSimpleLine("There is no folder with such name!");
         return;
     }
     try
     {
         DeleteAllFiles(sourceDir);
         CopyFilesToDir(Path.Combine(saveFolder.FullName, toLoad), sourceDir);
     }
     catch (Exception e)
     {
         ConsoleCaller.WriteSimpleLine($"Oops! Something went wrong! Error - {e.ToString()}");
         return;
     }
     ConsoleCaller.WriteSimpleLine("Load sucessed!");
     ConsoleCaller.WriteSimpleLine("");
 }
Пример #4
0
        static void Main(string[] args)
        {
            ConsoleCaller.WriteSimpleLine("Choose programm state - to watch or to load(1 or 2):");

            BigBrother eay = new BigBrother(@"C:\Users\Emelman\source\repos\EPAM\12_Basic\Task_02\folderToWatch");
            int        key;

            int.TryParse(Console.ReadLine(), out key);
            switch (key)
            {
            case 1:
                ConsoleCaller.WriteSimpleLine("Start to Observe");
                eay.CreateObserver();
                break;

            case 2:
                ConsoleCaller.WriteSimpleLine("Please, print date you seek. Format - yyyyMMddHHmmss - year month day hour minutes seconds");
                string   toLoad = ConsoleCaller.ReadSimpleLine();
                DateTime dt;
                while (!DateTime.TryParseExact(toLoad, "yyyyMMddHHmmss", null, System.Globalization.DateTimeStyles.None, out dt))
                {
                    ConsoleCaller.WriteSimpleLine("Invalid date, please try again. Pattern is yyyyMMddHHmmss");
                    toLoad = ConsoleCaller.ReadSimpleLine();
                }
                eay.LoadSavedState(toLoad);
                break;

            default:
                ConsoleCaller.WriteSimpleLine("Dont have such option!");
                break;
            }

            ConsoleCaller.WriteSimpleLine("Press \'q\' to quit the sample.");
            while (Console.Read() != 'q')
            {
                ;
            }
        }
Пример #5
0
        private void OnChanged(object sender, FileSystemEventArgs e)
        {
            DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath);

            if (lastWriteTime != lastRead)
            {
                lastRead = lastWriteTime;
                if (e.ChangeType == WatcherChangeTypes.Created)
                {
                    ConsoleCaller.WriteSimpleLine("New File cretaed!");
                }
                else if (e.ChangeType == WatcherChangeTypes.Changed)
                {
                    ConsoleCaller.WriteSimpleLine("Some thing changed!");
                }
                else if (e.ChangeType == WatcherChangeTypes.Deleted)
                {
                    ConsoleCaller.WriteSimpleLine("File deleted!");
                }
                ConsoleCaller.WriteSimpleLine("File: " + e.FullPath + " " + e.ChangeType);
                save.CreateSaveState(dir.FullName);
            }
        }