Esempio n. 1
0
 public Logger(FileManagerOptions options)
 {
     archivator              = new Archivator(options);
     sourceWatcher           = new FileSystemWatcher(options["Source"]);
     archiveWatcher          = new FileSystemWatcher(options["Archive"]);
     sourceWatcher.Created  += SourceWatcher_CreatedAsync;
     archiveWatcher.Renamed += TargetWatcher_RenamedAsync;
 }
Esempio n. 2
0
 private void OnCreated(object sender, FileSystemEventArgs e)
 {
     ThreadPool.QueueUserWorkItem(async state =>
     {
         //GC.Collect(2);
         string pathInTargetDirectory = await SendToTargetDirectory(e.FullPath);
         var archivator = new Archivator();
         archivator.UnZip(e.FullPath, pathInTargetDirectory);
     });
 }
Esempio n. 3
0
        private async Task <string> SendToTargetDirectory(string oldPath)
        {
            return(await Task.Run(() =>
            {
                try
                {
                    var file = File.ReadAllBytes(oldPath);

                    var encryption = new Encryption();
                    var cryptedFile = encryption.Crypt(file);

                    var archivator = new Archivator();
                    string newPath = encryption.GetCryptedFilePath(
                        archivator.GetFilePathInTargetDirectoryByTime(new FileInfo(oldPath), true)) + ".gz";

                    string tempPath = Path.Combine(
                        "C:\\Users\\quasar\\source\\repos\\Service1\\bin\\Debug\\",
                        "temp123");

                    new FileStream(tempPath, FileMode.Create)
                    .WriteTo(cryptedFile)
                    .CompressFromFile(newPath)
                    .Dispose();

                    return newPath;
                }
                catch (Exception e)
                {
                    using (var writer = new StreamWriter(Options.PathOptions.Templog, true))
                    {
                        writer.WriteLine(e.Message);
                        writer.Flush();
                    }
                }

                return "";
            }));
        }
Esempio n. 4
0
        internal Extractor(string targetDirectory, byte[] aesKey, byte[] aesIV)
        {
            this._targetDirectory = targetDirectory;
            try
            {
                _encryptorOptions = Watcher.SystemConfiguration.GetConfigurationClass(new EncryptorOptions());
                _aesKey           = _encryptorOptions.GetOption <string>("aesKey").Select(c => (byte)c).ToArray();
            }
            catch
            {
                this._aesKey = aesKey;
            }
            try
            {
                _aesIV = _encryptorOptions.GetOption <string>("aesIV").Select(c => (byte)c).ToArray();
            }
            catch
            {
                this._aesIV = aesIV;
            }
            this._encryptor  = new Encryptor();
            this._archivator = new Archivator();
            try
            {
                _archivatorOptions = Watcher.SystemConfiguration.GetConfigurationClass(new ArchivatorOptions());
            }
            catch
            {
                Logger.RecordStatus("Warning, archivator options was not found in the config");
            }
            try
            {
                _archivator.IsNeedToLogArchivator = _archivatorOptions.GetOption <bool>("NeedToLog");
            }
            catch
            {
                Logger.RecordStatus("Warning, archivator need to log option was not found in the config");
                _archivator.IsNeedToLogArchivator = true;
            }
            try
            {
                _compressorOptions           = Watcher.SystemConfiguration.GetConfigurationClass(new CompressorOptions());
                _archivator.CompressionLevel = _compressorOptions.GetOption <int>("CompressingLevel").ToString();
            }
            catch
            {
                try
                {
                    _archivator.CompressionLevel = _compressorOptions.GetOption <string>("CompressingLevel");
                }
                catch
                {
                    _archivator.CompressionLevel = "Optimal";
                }
            }

            if (_archivatorOptions.GetOption <bool>("NeedToArchieve"))
            {
                ArchiveOldFiles(_targetDirectory);
            }
        }