Exemplo n.º 1
0
 public ETLOptions(FolderOptions foldersOptions, LogOptions logOptions,
                   ArchiveOptions archiveOptions, CrypterOptions crypterOptions)
 {
     ArchiveOptions = archiveOptions;
     CrypterOptions = crypterOptions;
     LogOptions     = logOptions;
     FolderOptions  = foldersOptions;
 }
Exemplo n.º 2
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);

            CrypterOptions encryptionOptions  = optionsManager.GetOptions <CrypterOptions>() as CrypterOptions;
            ArchiveOptions archivationOptions = optionsManager.GetOptions <ArchiveOptions>() as ArchiveOptions;

            FileSystemWatcher watcher = new FileSystemWatcher();

            if (extansion != ".gz" && extansion != "")
            {
                if (encryptionOptions.NeedToEncrypt)
                {
                    Crypter.Encrypt(pathToFile);
                }

                string pathToArchive = Path.Combine(SDir, name + ".gz");
                Archiver.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(TDir, 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);
                Archiver.Decompress(newPathToArchive, newPathToFile);

                if (encryptionOptions.NeedToEncrypt)
                {
                    Crypter.Decrypt(newPathToFile);
                }
            }
        }
Exemplo n.º 3
0
 public Crypter(CrypterOptions options)
 {
     this.Options = options;
 }
Exemplo n.º 4
0
        private void Created(object sender, FileSystemEventArgs e)
        {
            int      key        = 17;
            string   pathToFile = e.FullPath;
            DateTime date       = File.GetLastWriteTime(pathToFile);
            string   name       = Path.GetFileNameWithoutExtension(pathToFile);
            string   extansion  = Path.GetExtension(pathToFile);

            CrypterOptions encryptionOptions  = optionsManager.GetOptions <CrypterOptions>() as CrypterOptions;
            ArchiveOptions archivationOptions = optionsManager.GetOptions <ArchiveOptions>() as ArchiveOptions;

            FileSystemWatcher watcher = new FileSystemWatcher();

            if (extansion != ".gz" && extansion != "")
            {
                string encryptedText = "";
                string decryptedText = "";
                string message       = "";
                if (encryptionOptions.NeedToEncrypt)
                {
                    using (StreamReader sr = new StreamReader(pathToFile))
                    {
                        message       = sr.ReadToEnd();
                        encryptedText = Crypter.Encrypt(message, key);
                        sr.Close();
                    }
                    using (StreamWriter sw = new StreamWriter(pathToFile, false, System.Text.Encoding.Default))
                    {
                        sw.WriteLine(encryptedText);
                        sw.Close();
                    }
                }

                string pathToArchive = Path.Combine(SDir, name + ".gz");
                Archiver.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(TDir, 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);
                Archiver.Decompress(newPathToArchive, newPathToFile);

                if (encryptionOptions.NeedToEncrypt)
                {
                    using (StreamReader sr = new StreamReader(newPathToFile))
                    {
                        string message1 = sr.ReadToEnd();
                        decryptedText = Crypter.Decrypt(encryptedText, key);
                        sr.Close();
                    }
                    using (StreamWriter sw = new StreamWriter(newPathToFile, false, System.Text.Encoding.Default))
                    {
                        sw.WriteLine(decryptedText);
                        sw.Close();
                    }
                }
            }
        }