Beispiel #1
0
 public ETLOptions(FolderOptions foldersOptions, LogOptions logOptions,
                   ArchiveOptions archiveOptions, CrypterOptions crypterOptions)
 {
     ArchiveOptions = archiveOptions;
     CrypterOptions = crypterOptions;
     LogOptions     = logOptions;
     FolderOptions  = foldersOptions;
 }
Beispiel #2
0
 public Options(string sourcePath, string targetPath, string logFilePath, ArchiveOptions archiveOptions, bool needToEncrypt)
 {
     SourcePath     = sourcePath;
     TargetPath     = targetPath;
     LogFilePath    = logFilePath;
     ArchiveOptions = archiveOptions;
     NeedToEncrypt  = needToEncrypt;
 }
Beispiel #3
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);
                }
            }
        }
Beispiel #4
0
 public static void Compress(string path, string cpath, ArchiveOptions archiveOptions)
 {
     try
     {
         using (FileStream sourceStream = new FileStream(path, FileMode.OpenOrCreate))
         {
             using (FileStream targetStream = File.Create(cpath))
             {
                 using (GZipStream compressionStream = new GZipStream(targetStream, archiveOptions.CompressionLevel))
                 {
                     sourceStream.CopyTo(compressionStream);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         throw;
     }
 }
Beispiel #5
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();
                    }
                }
            }
        }