Esempio n. 1
0
        private static void OnChanged(object source, FileSystemEventArgs e)
        {
            while (true)
            {
                try
                {
                    if (!Directory.Exists(e.FullPath))
                    {
                        DateTime dateTimeOfChange = DateTime.Now;
                        string   dateForLog       = dateTimeOfChange.ToString(Constants.dateFormat);
                        string   logGuid          = Guid.NewGuid().ToString();
                        logger.WriteChangeOfFile(e, dateForLog, logGuid);

                        string nameFile   = ($"{dateForLog}_{logGuid}.txt");
                        string pathToCopy = Path.Combine(SettingsFromConfig.ReadSetting(Constants.folderForCopyFilesKey), nameFile);
                        File.Copy(e.FullPath, pathToCopy);
                        return;
                    }
                }
                catch
                {
                    Thread.Sleep(1);
                }
            }
        }
Esempio n. 2
0
        public void BackupForChange(LogItem item)
        {
            string nameSourceFile = ($"{LogItem.DateFromLogToString(item.TimeOfChanges)}_{item.LogGuide}.txt");
            string soursePath     = Path.Combine(SettingsFromConfig.ReadSetting(Constants.folderForCopyFilesKey), nameSourceFile);

            File.Copy(soursePath, item.NewPathToFile, true);
        }
Esempio n. 3
0
 public static void PrepareForTracking(string trackingDirectory)
 {
     if (!Directory.Exists(Constants.CopiedFolderPath))
     {
         Directory.CreateDirectory(Constants.CopiedFolderPath);
         CopyFilesAndFolders(trackingDirectory, Constants.CopiedFolderPath);
     }
     if (!File.Exists(Constants.LogFilePath))
     {
         File.Create(Constants.LogFilePath).Close();
     }
     if (!Directory.Exists(SettingsFromConfig.ReadSetting(Constants.folderForCopyFilesKey)))
     {
         Directory.CreateDirectory(SettingsFromConfig.ReadSetting(Constants.folderForCopyFilesKey));
     }
 }