示例#1
0
        private void Created(object sender, FileSystemEventArgs e)
        {
            string   pathToFile = e.FullPath;
            DateTime date       = File.GetLastWriteTime(pathToFile);
            string   name       = Path.GetFileNameWithoutExtension(pathToFile);
            string   extansion  = Path.GetExtension(pathToFile);

            EncryptionOptions encryptionOptions =
                optionsManager.GetOptions <EncryptionOptions>() as EncryptionOptions;
            ArchivationOptions archivationOptions =
                optionsManager.GetOptions <ArchivationOptions>() as ArchivationOptions;


            if (extansion != ".gz" && extansion != "")
            {
                byte[] key, iv;
                (key, iv) = Encryption.GenKeyIv();

                if (encryptionOptions.NeedToEncrypt)
                {
                    File.WriteAllBytes(pathToFile, Encryption.Encrypt(pathToFile, key, iv));
                }

                string pathToArchive = Path.Combine(source, name + ".gz");
                Archivation.Compress(pathToFile, pathToArchive, archivationOptions);


                File.Delete(pathToFile);

                if (!Directory.Exists(saveArchive))
                {
                    Directory.CreateDirectory(saveArchive);
                }

                string newPathToArchive = Path.Combine(saveArchive, name + ".gz");
                if (File.Exists(newPathToArchive))
                {
                    File.Delete(newPathToArchive);
                }
                File.Move(pathToArchive, newPathToArchive);


                string newPathToFile = Path.Combine(target, date.Year.ToString(),
                                                    date.Month.ToString(), date.Day.ToString());
                Directory.CreateDirectory(newPathToFile);

                newPathToFile = Path.Combine(newPathToFile, name + "_"
                                             + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + extansion);
                Archivation.Decompress(newPathToArchive, newPathToFile);

                if (encryptionOptions.NeedToEncrypt)
                {
                    File.WriteAllBytes(newPathToFile, Encryption.Decrypt(newPathToFile, key, iv));
                }
            }
        }
示例#2
0
        public Watcher()
        {
            manager  = new OptionsManager();
            crypter  = new Crypter(manager.GetOptions <CrypterOptions>() as CrypterOptions);
            archiver = new Archiver(manager.GetOptions <ArchiverOptions>() as ArchiverOptions);
            watcher  = new FileSystemWatcher(manager.Options.SourcePath, "*.*");

            watcher.Created += OnChanged;
            watcher.Changed += OnChanged;
            watcher.Renamed += OnChanged;
            watcher.Deleted += OnDeleted;

            watcher.EnableRaisingEvents   = true;
            watcher.IncludeSubdirectories = true;

            Logger = manager.Logger;
            archiver.Options.TargetLogger = Logger;
            crypter.Options.TargetLogger  = Logger;

            jsonWatcher                     = new FileSystemWatcher(manager.Options.Path, "appsettings.json");
            jsonWatcher.Created            += OnOptionsFileChanged;
            jsonWatcher.Changed            += OnOptionsFileChanged;
            jsonWatcher.Deleted            += OnOptionsFileChanged;
            jsonWatcher.EnableRaisingEvents = true;

            xmlWatcher          = new FileSystemWatcher(manager.Options.Path, "config.xml");
            xmlWatcher.Created += OnOptionsFileChanged;
            xmlWatcher.Changed += OnOptionsFileChanged;
            xmlWatcher.Deleted += OnOptionsFileChanged;
            if (manager.Options != manager.JSONOptions)
            {
                xmlWatcher.EnableRaisingEvents = true;
            }
            else
            {
                xmlWatcher.EnableRaisingEvents = false;
            }
        }
示例#3
0
        public Logger()
        {
            OptionsManager optionsManager = new OptionsManager(AppDomain.CurrentDomain.BaseDirectory);

            configOptions        = optionsManager.GetOptions <Options>();
            sourcePath           = configOptions.PathToDirectory.SourceDirectory;
            targetPath           = configOptions.PathToDirectory.TargetDirectory;
            watcher              = new FileSystemWatcher(sourcePath);
            watcher.NotifyFilter = NotifyFilters.LastAccess
                                   | NotifyFilters.LastWrite
                                   | NotifyFilters.FileName
                                   | NotifyFilters.DirectoryName;
            watcher.Filter   = "*.txt";
            watcher.Created += Watcher_Created;
        }
示例#4
0
        public Watcher()
        {
            string appDirectory = AppDomain.CurrentDomain.BaseDirectory;

            optionsManager = new OptionsManager(appDirectory);
            ETLOptions options = optionsManager.GetOptions <ETLOptions>() as ETLOptions;

            source               = options.WorkFoldersOptions.SourceDir;
            target               = options.WorkFoldersOptions.TargetDir;
            saveArchive          = options.ArchivationOptions.ArchiveDir;
            Logger.loggerOptions = options.LoggerOptions;
            Logger.loaded        = true;

            watcher          = new FileSystemWatcher(source);
            watcher.Created += Created;
        }