コード例 #1
0
ファイル: HddStorage.cs プロジェクト: drweb86/butil-migration
        public override void Open(LogBase log)
        {
            if (log == null)
            {
                throw new ArgumentNullException("log");
            }

            log.ProcedureCall("Open");
            Log = log;

            if (DeleteBUtilFilesInDestinationFolderBeforeBackup)
            {
                log.WriteLine(LoggingEvent.Debug,
                              string.Format(CultureInfo.CurrentCulture, _DeletingBUtilImagesInTargetFolderBeforeBackup, DestinationFolder));

                string [] filesToDelete = null;

                try
                {
                    filesToDelete = Directory.GetFiles(DestinationFolder, "*" + Files.ImageFilesExtension);
                }
                catch (DirectoryNotFoundException e)
                {
                    log.WriteLine(LoggingEvent.Warning, e.Message);
                    return;
                }

                if (filesToDelete.Length > 0)
                {
                    for (int i = 0; i < filesToDelete.Length; i++)
                    {
                        log.WriteLine(LoggingEvent.Debug, "X " + filesToDelete[i]);
                        try
                        {
                            File.Delete(filesToDelete[i]);
                        }
                        catch (UnauthorizedAccessException e)
                        {
                            log.WriteLine(LoggingEvent.Warning,
                                          string.Format(CultureInfo.CurrentCulture, _CANNOTDELETEDUETOACESSVIOLATIONS, filesToDelete[i], e.Message));
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: FtpStorage.cs プロジェクト: drweb86/butil-migration
        public override void Open(LogBase log)
        {
            log.ProcedureCall("Open");
            Log = log;

            _connection = new FtpConnection();
            _connection.SetLogOnInformation(User, Password);
            _connection.ServerLocation = this.RemoteHostServer;
            _connection.IsPassive      = !this.FtpModeIsActive;

            if (_deleteBUtilFilesInDestinationFolderBeforeBackup)
            {
                log.WriteLine(LoggingEvent.Debug, string.Format(CultureInfo.CurrentCulture, _DeletingAllBUtilImageFilesFromTargetFolder, DestinationFolder));

                string [] filesToDelete = null;

                try
                {
                    filesToDelete = _connection.GetFileList(DestinationFolder);
                }
                catch (Exception e)
                {
                    log.WriteLine(LoggingEvent.Warning, e.Message);
                    return;
                }

                foreach (string file in filesToDelete)
                {
                    if (file.EndsWith(Files.ImageFilesExtension))
                    {
                        log.WriteLine(LoggingEvent.Debug, "X " + file);
                        try
                        {
                            _connection.DeleteFtp(file);
                        }
                        catch (Exception e)
                        {
                            log.WriteLine(LoggingEvent.Warning, string.Format(CultureInfo.CurrentCulture, _CannotDeleteFileDueToFormatString, file, e.Message));
                        }
                    }
                }
            }
        }
コード例 #3
0
        public void DoJob()
        {
            try
            {
                bool succesfull = true;
                if (_storage.RequireSecurity && (!_enableEncryption))
                {
                    _log.WriteLine(LoggingEvent.Error, string.Format(CultureInfo.InstalledUICulture, Translation.Current[399], _storage.StorageName));
                    succesfull = false;
                }
                else
                {
                    _log.WriteLine(LoggingEvent.Debug, string.Format(CultureInfo.InstalledUICulture, "Processing storage '{0}'", _storage.StorageName));

                    try
                    {
                        notify(new CopyingToStorageNotificationEventArgs(_storage, ProcessingState.InProgress));
                        _storage.Open(_log);
                        _log.WriteLine(LoggingEvent.Debug, "Storage opened successfully");
                        _storage.Process(_imageFileToCopy);
                        _log.WriteLine(LoggingEvent.Debug, "File was copyied to storage successfully");
                    }
                    catch (LogException e)
                    {
                        _log.WriteLine(LoggingEvent.Error, string.Format(CultureInfo.InstalledUICulture, Translation.Current[404], _storage.StorageName, e.Message));
                        succesfull = false;
                    }
                    catch (Exception exc)                            // ok
                    {
                        if (exc is ThreadInterruptedException)
                        {
                            _log.WriteLine(LoggingEvent.Error, string.Format("Copying to storage {0} aborted by user", _storage.Hint));
                        }

                        _log.WriteLine(LoggingEvent.Error, string.Format(CultureInfo.InstalledUICulture, Translation.Current[406], _storage.StorageName, exc.Message));
                        succesfull = false;
                    }
                }
                notify(new CopyingToStorageNotificationEventArgs(_storage, succesfull ? ProcessingState.FinishedSuccesfully : ProcessingState.FinishedWithErrors));
            }
            catch (ThreadInterruptedException)
            {
                _log.WriteLine(LoggingEvent.Error, string.Format("Copying to storage {0} aborted by user", _storage.Hint));
            }
            finally
            {
                if (_finished != null)
                {
                    _finished.Invoke(this, new JobThreadEventArgs(Thread.CurrentThread));
                }
            }
        }
コード例 #4
0
        public void DoJob()
        {
            bool succesfull = false;

            try
            {
                notify(new ImagePackingNotificationEventArgs(ProcessingState.InProgress));

                reserveFileForBackupImage();
                ImageCreator imagePacker = new ImageCreator(_imageFile.FileName, new ImageHeader(_metarecords));
                imagePacker.Pack(true);
                succesfull = true;
            }
            catch (FileNotFoundException e)
            {
                _log.WriteLine(LoggingEvent.Error, string.Format(Translation.Current[611], e.Message));
                _log.WriteLine(LoggingEvent.Debug, e.ToString());
            }
            catch (IOException e)
            {
                _log.WriteLine(LoggingEvent.Error, string.Format(Translation.Current[579], _imageFile.FileName, e.Message));
                _log.WriteLine(LoggingEvent.Debug, e.ToString());
            }
            catch (ThreadInterruptedException)
            {
                _log.WriteLine(LoggingEvent.Error, Translation.Current[578]);
            }
            finally
            {
                notify(new ImagePackingNotificationEventArgs(succesfull ? ProcessingState.FinishedSuccesfully: ProcessingState.FinishedWithErrors));

                if (_finished != null)
                {
                    _finished.Invoke(this, new JobThreadEventArgs(Thread.CurrentThread));
                }
            }
        }
コード例 #5
0
        public void DoJob()
        {
            _log.WriteLine(LoggingEvent.Debug, _taskName);

            bool    succesfull = false;
            Process program    = new Process();

            program.StartInfo = new ProcessStartInfo(_taskInfo.Program, _taskInfo.Arguments);
            program.StartInfo.WorkingDirectory = Path.GetDirectoryName(_taskInfo.Program);

            try
            {
                program.Start();

                notify(ProcessingState.InProgress);

                setPriorityHelper(program);

                // FIXME: This is a workaround of .Net 2 bugs with processing ThreadAbortException and ThreadInterruptException
                // both bugs were posted to MS
                // this code is subject to be removed when those bugs will be fixed or on updating to next .Net version
                while (!program.HasExited)
                {
                    Thread.Sleep(100);
                }
                // program.WaitForExit();

                succesfull = true;
            }
            catch (ThreadInterruptedException)
            {
                succesfull = false;
                _finished  = null;
                _log.WriteLine(LoggingEvent.Debug, _taskName + "Aborting...");
                try
                {
                    program.Kill();
                    _log.WriteLine(LoggingEvent.Debug, _taskName + "Aborted");
                }
                catch (InvalidOperationException e)
                {
                    _log.WriteLine(LoggingEvent.Error,
                                   string.Format(CultureInfo.CurrentCulture, _taskName + Translation.Current[592], _taskInfo.Program, e.Message));
                    _log.WriteLine(LoggingEvent.Debug, _taskName + e.ToString());
                }
                catch (Win32Exception e)
                {
                    _log.WriteLine(LoggingEvent.Error,
                                   string.Format(CultureInfo.CurrentCulture, _taskName + Translation.Current[592], _taskInfo.Program, e.Message));
                    _log.WriteLine(LoggingEvent.Debug, _taskName + e.ToString());
                }
            }
            catch (ObjectDisposedException e)
            {
                _log.WriteLine(LoggingEvent.Error,
                               string.Format(CultureInfo.CurrentCulture, _taskName + Translation.Current[593], _taskInfo.Program, e.Message));
                _log.WriteLine(LoggingEvent.Debug, _taskName + e.ToString());
            }
            catch (Win32Exception e)
            {
                _log.WriteLine(LoggingEvent.Error,
                               string.Format(CultureInfo.CurrentCulture, _taskName + Translation.Current[593], _taskInfo.Program, e.Message));
                _log.WriteLine(LoggingEvent.Debug, _taskName + e.ToString());
            }
            finally
            {
                notify(succesfull ? ProcessingState.FinishedSuccesfully: ProcessingState.FinishedWithErrors);

                if (_finished != null)
                {
                    _finished.Invoke(this, new JobThreadEventArgs(Thread.CurrentThread));
                }
            }

            _log.WriteLine(LoggingEvent.Debug, _taskName + "Finished");
        }
コード例 #6
0
        public void DoJob()
        {
            _log.WriteLine(LoggingEvent.Debug, _packingParameter.ToString() + ":started");
            bool succesfull = false;

            using (Process compressionProcess = createCompressProcess(_packingParameter.Arguments))
            {
                try
                {
                    compressionProcess.Start();
                    Thread thread = new Thread(new ParameterizedThreadStart(readOutput));
                    thread.Start(compressionProcess.StandardOutput);

                    notify(new PackingNotificationEventArgs(_packingParameter.ItemToCompress, ProcessingState.InProgress));
                    setPriorityHelper(compressionProcess);

                    // FIXME: This is a workaround of .Net 2 bugs with processing ThreadAbortException and ThreadInterruptException
                    // both bugs were posted to MS
                    // this code is subject to be removed when those bugs will be fixed

                    while (!compressionProcess.HasExited)
                    {
                        Thread.Sleep(100);
                    }

                    while (thread.IsAlive)
                    {
                        Thread.Sleep(1000);
                    }

                    succesfull = isSuccessfull7ZipPacking(compressionProcess.ExitCode);
                    _log.ProcessPackerMessage(_compressionOutput, succesfull);
                    notify(new PackingNotificationEventArgs(_packingParameter.ItemToCompress, succesfull ? ProcessingState.FinishedSuccesfully: ProcessingState.FinishedWithErrors));
                }
                catch (ThreadInterruptedException)
                {
                    succesfull = false;
                    _finished  = null;
                    _log.WriteLine(LoggingEvent.Debug, _packingParameter.ItemToCompress.Target + ": Packing task is aborting...");

                    try
                    {
                        compressionProcess.Kill();
                        _log.WriteLine(LoggingEvent.Debug, _packingParameter.ItemToCompress.Target + ": Packing task is aborted");
                    }
                    catch (InvalidOperationException e)
                    {
                        _log.WriteLine(LoggingEvent.Error,
                                       string.Format(CultureInfo.CurrentCulture, _packingParameter.ItemToCompress.Target + ":" + Translation.Current[467], e.Message));
                    }
                    catch (Win32Exception e)
                    {
                        _log.WriteLine(LoggingEvent.Error,
                                       string.Format(CultureInfo.CurrentCulture, _packingParameter.ItemToCompress.Target + ":" + Translation.Current[467], e.Message));
                    }
                }
                catch (ObjectDisposedException e)
                {
                    _log.WriteLine(LoggingEvent.Error,
                                   string.Format(CultureInfo.CurrentCulture,
                                                 _packingParameter.ItemToCompress.Target + ": " + Translation.Current[469],
                                                 e.Message));
                }
                catch (Win32Exception e)
                {
                    _log.WriteLine(LoggingEvent.Error,
                                   string.Format(CultureInfo.CurrentCulture,
                                                 _packingParameter.ItemToCompress.Target + ": " + Translation.Current[469],
                                                 e.Message));
                }
                finally
                {
                    if (_finished != null)
                    {
                        _finished.Invoke(this, new JobThreadEventArgs(Thread.CurrentThread));
                    }
                }
            }

            _log.WriteLine(LoggingEvent.Debug, _packingParameter.ToString() + ":finished");
        }
コード例 #7
0
        /// <summary>
        /// Stops backup process immidietly. This is not secure variant and works fine for storages only. For stopping compression it needs to be reworked
        /// </summary>
        public void StopForcibly()
        {
            _log.ProcedureCall("StopForcibly::start");

            _aborting = true;
            _log.WriteLine(LoggingEvent.Error, _backupAbortedByUser);
            // cleaning tasls about copying
            _afterBackupEventManager.Abort();
            _beforeBackupEventManager.Abort();
            _compressionManager.Abort();
            _copyManager.Abort();
            _imageCreationManager.Abort();

            // Alarming that all finished
            if (_onBackupFinished != null)
            {
                _onBackupFinished.Invoke();
            }
        }