コード例 #1
0
        public void StartWatch(ZipWatcherPreferences zipWatcherPreferences)
        {
            _zipWatcherPreferences = zipWatcherPreferences;

            if (!Directory.Exists(_zipWatcherPreferences.PathToWatch))
            {
                throw new Exception($"Folder does not exist: {_zipWatcherPreferences.PathToWatch}. Please create folder to watch");
            }

            _fSWatcher = new FileSystemWatcher();

            _fSWatcher.Path         = zipWatcherPreferences.PathToWatch;
            _fSWatcher.NotifyFilter =
                ((NotifyFilters)((((((((NotifyFilters.FileName |
                                        NotifyFilters.DirectoryName)
                                       | NotifyFilters.Attributes)
                                      | NotifyFilters.Size)
                                     | NotifyFilters.LastWrite)
                                    | NotifyFilters.LastAccess)
                                   | NotifyFilters.CreationTime)
                                  | NotifyFilters.Security)));

            _fSWatcher.EnableRaisingEvents   = true;
            _fSWatcher.IncludeSubdirectories = false;

            _zipFileTask = ZippingFiles();

            AllLogWriter.Instance.LogMessage($"Starting to Watch Folder {zipWatcherPreferences.PathToWatch}");

            _fSWatcher.Created += FSWatcher_Created;

            AllLogWriter.Instance.LogMessage($"Watching Folder {zipWatcherPreferences.PathToWatch}");
        }
コード例 #2
0
        /// <summary>
        /// Add a file to transfer to the transfer Queue
        /// Files will be transferred one at a time
        /// </summary>
        public void AddFileToTransferAsync(ZipEntity zipEntity, ZipWatcherPreferences zipWatcherPreferences)
        {
            zipEntity.RemoteOutputPath     = CalculateRemotePath(zipEntity, zipWatcherPreferences);
            zipEntity.RemoteOutputFileName = CalculateRemoteFileName(zipEntity, zipWatcherPreferences);
            AllLogWriter.Instance.LogMessage($"\nAdding file to Queue for transferring from: {zipEntity.ZipFileName} to  {zipEntity.RemoteOutputPath}");
            // zipEntity.RemoteOutputFolder=



            if (!(_isZipFileTaskRunning))
            {
                _zipFileTask = TransferringFiles();
            }

            _zipTranferQueue.Add(zipEntity);
        }
コード例 #3
0
        private void Call7zip(ZipWatcherPreferences zipWatcherPreferences, ZipEntity zipEntity)
        {
            Process sevenZip = new Process();

            if (!(string.IsNullOrEmpty(zipWatcherPreferences.PathTo7Zip)))
            {
                sevenZip.StartInfo.WorkingDirectory = zipWatcherPreferences.PathTo7Zip;
            }

            sevenZip.StartInfo.UseShellExecute        = false;
            sevenZip.StartInfo.RedirectStandardOutput = true;

            sevenZip.StartInfo.Arguments = $"/c {Path.Combine(zipWatcherPreferences.PathTo7Zip, "7z.exe")} a -m0=lzma2 -r -y \"{zipEntity.ZipFileName}\" \"{zipEntity.BackupFileName}\" ";
            sevenZip.StartInfo.FileName  = "cmd.exe";
            try
            {
                FileLogWriter.Instance.LogMessage("Starting 7zip");
                FileLogWriter.Instance.LogMessage($"7zip Commandline {Path.Combine(sevenZip.StartInfo.WorkingDirectory, "cmd.exe")} {sevenZip.StartInfo.Arguments} ");

                sevenZip.Start();
                _isSevenZipRunning = true;

                while (!(sevenZip.StandardOutput.EndOfStream) && _isSevenZipRunning)
                {
                    FileLogWriter.Instance.LogMessage($"\t{sevenZip.StandardOutput.ReadLine()}");
                }

                if (_isSevenZipRunning == true)
                {
                    sevenZip.WaitForExit();
                }

                FileLogWriter.Instance.LogMessage($"Finished Compressing {zipEntity.ZipFileName}");
                _isSevenZipRunning = false;
            }
            catch (Exception e)
            {
                AllLogWriter.Instance.LogErrorMessage(e.ToString());
            }
        }
コード例 #4
0
        /// <summary>
        /// Determines the name of the remote folder and filename to transfer
        /// </summary>
        /// <param name="zipEntity"></param>
        /// <param name=""></param>
        /// <returns></returns>
        private string CalculateRemoteFileName(ZipEntity zipEntity, ZipWatcherPreferences zipWatcherPreferences)
        {
            string fileName = Path.GetFileName(zipEntity.ZipFileName);

            return(Path.Combine(zipWatcherPreferences.EndResultPath, DateTime.Now.GetYearMonthDay(), fileName ?? throw new InvalidOperationException()));
        }
コード例 #5
0
 /// <summary>
 /// Determines the name of the remote folder to transfer the zip file
 /// </summary>
 /// <param name="zipEntity"></param>
 /// <param name=""></param>
 /// <returns></returns>
 private string CalculateRemotePath(ZipEntity zipEntity, ZipWatcherPreferences zipWatcherPreferences)
 {
     return(Path.Combine(zipWatcherPreferences.EndResultPath, DateTime.Now.GetYearMonthDay()));
 }