예제 #1
0
        public void OnFailure(CustomRestoreAgent agent, Models.Restore restore, Exception exception)
        {
            IsRunning = false;

            var message = string.Format("Restore failed: {0}", exception != null ? exception.Message : "Canceled?");

            Report.AddErrorMessage(message);
            Error(message);
            //StatusInfo.Update(RestoreStatusLevel.ERROR, message);

            restore.DidFail();
            _daoRestore.Update(restore);

            OnUpdate(new RestoreOperationEvent {
                Status = RestoreOperationStatus.Failed, Message = message
            });
        }
예제 #2
0
        public void OnCancelation(CustomBackupAgent agent, Models.Backup backup, Exception exception)
        {
            IsRunning = false;

            var message = string.Format("Backup canceled: {0}", exception != null ? exception.Message : "Exception not informed");

            Report.AddErrorMessage(message);
            Error(message);
            //StatusInfo.Update(BackupStatusLevel.ERROR, message);

            backup.WasCanceled();
            _daoBackup.Update(backup);

            OnUpdate(new BackupOperationEvent {
                Status = BackupOperationStatus.Canceled, Message = message
            });
        }
예제 #3
0
        public void OnFailure(CustomBackupAgent agent, Models.Backup backup, Exception exception)
        {
            IsRunning = false;

            logger.Log(LogLevel.Error, exception, "Caught exception: {0}", exception.Message);

            var message = string.Format("Backup failed: {0}", exception != null ? exception.Message : "Exception not informed");

            Report.AddErrorMessage(message);
            Error(message);
            //StatusInfo.Update(BackupStatusLevel.ERROR, message);

            backup.DidFail();
            _daoBackup.Update(backup);

            OnUpdate(new BackupOperationEvent {
                Status = BackupOperationStatus.Failed, Message = message
            });
        }
예제 #4
0
        public void OnFinish(CustomRestoreAgent agent, Models.Restore restore, Exception ex = null)
        {
            IsRunning = false;

            switch (CurrentState)
            {
            default:
            {
                var message = string.Format("Restore failed: {0}", ex.Message);
                Warn(message);
                //StatusInfo.Update(RestoreStatusLevel.WARN, message);
                Report.AddErrorMessage(ex.Message);

                Report.OperationStatus = OperationStatus.FAILED;
                restore.DidFail();
                _daoRestore.Update(restore);
                OnUpdate(new RestoreOperationEvent {
                        Status = RestoreOperationStatus.Failed, Message = message
                    });

                break;
            }

            case RestoreOperationState.FINISHING:
            {
                TransferResults.Statistics stats = agent.Results.Stats;

                var message = string.Format(
                    "Restore finished! Stats: {0} completed, {1} failed, {2} canceled, {3} pending, {4} running",
                    stats.Completed, stats.Failed, stats.Canceled, stats.Pending, stats.Running);
                Info(message);
                //StatusInfo.Update(RestoreStatusLevel.OK, message);

                switch (agent.Results.OverallStatus)
                //switch (backup.Status)
                {
                default: throw new InvalidOperationException("Unexpected TransferStatus");

                case TransferStatus.CANCELED:
                    Report.OperationStatus = OperationStatus.CANCELED;
                    restore.WasCanceled();
                    _daoRestore.Update(restore);
                    OnUpdate(new RestoreOperationEvent {
                            Status = RestoreOperationStatus.Canceled, Message = message
                        });
                    break;

                case TransferStatus.FAILED:
                    Report.OperationStatus = OperationStatus.FAILED;
                    restore.DidFail();
                    _daoRestore.Update(restore);
                    OnUpdate(new RestoreOperationEvent {
                            Status = RestoreOperationStatus.Failed, Message = message
                        });
                    break;

                case TransferStatus.COMPLETED:
                    Report.OperationStatus = OperationStatus.COMPLETED;
                    restore.DidComplete();
                    _daoRestore.Update(restore);
                    OnUpdate(new RestoreOperationEvent {
                            Status = RestoreOperationStatus.Finished, Message = message
                        });
                    break;
                }

                break;
            }
            }

            Report.StartedAt  = Restore.StartedAt;
            Report.FinishedAt = Restore.FinishedAt.Value;
        }
예제 #5
0
        protected async void DoRestore(CustomRestoreAgent agent, Models.Restore restore, RestoreOperationOptions options)
        {
            try
            {
                CurrentState = RestoreOperationState.STARTING;
                OnStart(agent, restore);

                // Mount all network mappings and abort if there is any network mapping failure.
                CurrentState = RestoreOperationState.MAPPING_NETWORK_DRIVES;
                Helper.MountAllNetworkDrives();

                // Execute pre-actions
                CurrentState = RestoreOperationState.EXECUTING_PRE_ACTIONS;
                Helper.ExecutePreActions();

                //
                // Scanning
                //

                CurrentState = RestoreOperationState.SCANNING_FILES;
                LinkedList <CustomVersionedFile> filesToProcess = null;
                {
                    Task <PathScanResults <CustomVersionedFile> > filesToProcessTask = GetFilesToProcess(restore);

                    {
                        var message = string.Format("Scanning files started.");
                        Info(message);
                        //StatusInfo.Update(BackupStatusLevel.INFO, message);
                        OnUpdate(new RestoreOperationEvent {
                            Status = RestoreOperationStatus.ScanningFilesStarted, Message = message
                        });
                    }

                    try
                    {
                        await filesToProcessTask;
                    }
                    catch (Exception ex)
                    {
                        if (ex.IsCancellation())
                        {
                            string message = string.Format("Scanning files was canceled.");

                            Report.AddErrorMessage(message);
                            logger.Warn(message);
                        }
                        else
                        {
                            string message = string.Format("Caught exception during scanning files: {0}", ex.Message);

                            Report.AddErrorMessage(message);
                            logger.Log(LogLevel.Error, ex, message);
                        }

                        if (filesToProcessTask.IsFaulted || filesToProcessTask.IsCanceled)
                        {
                            if (filesToProcessTask.IsCanceled)
                            {
                                OnCancelation(agent, restore, ex);                                 // filesToProcessTask.Exception
                            }
                            else
                            {
                                OnFailure(agent, restore, ex);                                 // filesToProcessTask.Exception
                            }
                            return;
                        }
                    }

                    filesToProcess = filesToProcessTask.Result.Files;

                    {
                        foreach (var entry in filesToProcessTask.Result.FailedFiles)
                        {
                            Report.AddErrorMessage(entry.Value);
                        }

                        if (filesToProcessTask.Result.FailedFiles.Count > 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine("Scanning failed for the following drives/files/directories:");
                            foreach (var entry in filesToProcessTask.Result.FailedFiles)
                            {
                                sb.AppendLine(string.Format("  Path: {0} - Reason: {1}", entry.Key, entry.Value));
                            }
                            Warn(sb.ToString());
                        }

                        var message = string.Format("Scanning files finished.");
                        Info(message);
                        //StatusInfo.Update(BackupStatusLevel.INFO, message);
                        OnUpdate(new RestoreOperationEvent {
                            Status = RestoreOperationStatus.ScanningFilesFinished, Message = message
                        });
                    }
                }

                //
                // Versioning
                //

                CurrentState = RestoreOperationState.VERSIONING_FILES;
                {
                    Task versionerTask = DoVersionFiles(restore, filesToProcess);

                    {
                        var message = string.Format("Processing files started.");
                        Info(message);
                        //StatusInfo.Update(RestoreStatusLevel.INFO, message);
                        OnUpdate(new RestoreOperationEvent {
                            Status = RestoreOperationStatus.ProcessingFilesStarted, Message = message
                        });
                    }

                    try
                    {
                        await versionerTask;
                    }
                    catch (Exception ex)
                    {
                        if (ex.IsCancellation())
                        {
                            string message = string.Format("Processing files was canceled.");

                            Report.AddErrorMessage(message);
                            logger.Warn(message);
                        }
                        else
                        {
                            string message = string.Format("Caught exception during processing files: {0}", ex.Message);

                            Report.AddErrorMessage(message);
                            logger.Log(LogLevel.Error, ex, message);
                        }

                        if (versionerTask.IsFaulted || versionerTask.IsCanceled)
                        {
                            Versioner.Undo();
                            if (versionerTask.IsCanceled)
                            {
                                OnCancelation(agent, restore, ex);                                 // versionerTask.Exception
                            }
                            else
                            {
                                OnFailure(agent, restore, ex);                                 // versionerTask.Exception
                            }
                            return;
                        }
                    }

                    agent.Files = Versioner.FilesToTransfer;

                    {
                        var message = string.Format("Processing files finished.");
                        Info(message);
                        //StatusInfo.Update(BackupStatusLevel.INFO, message);
                        OnUpdate(new RestoreOperationEvent {
                            Status = RestoreOperationStatus.ProcessingFilesFinished, Message = message
                        });
                    }

                    {
                        agent.Results.Stats.BytesTotal = agent.EstimatedTransferSize;

                        var message = string.Format("Estimated restore size: {0} files, {1}",
                                                    agent.Files.Count(), FileSizeUtils.FileSizeToString(agent.EstimatedTransferSize));
                        Info(message);
                    }
                }

                //
                // Transfer files
                //

                CurrentState = RestoreOperationState.TRANSFERRING_FILES;
                {
                    Task <TransferResults> transferTask = agent.Start();
                    Report.TransferResults = transferTask.Result;

                    {
                        var message = string.Format("Transfer files started.");
                        Info(message);
                    }

                    try
                    {
                        await transferTask;
                    }
                    catch (Exception ex)
                    {
                        if (ex.IsCancellation())
                        {
                            string message = string.Format("Transfer files was canceled.");

                            Report.AddErrorMessage(message);
                            logger.Warn(message);
                        }
                        else
                        {
                            string message = string.Format("Caught exception during transfer files: {0}", ex.Message);

                            Report.AddErrorMessage(message);
                            logger.Log(LogLevel.Error, ex, message);
                        }

                        if (transferTask.IsFaulted || transferTask.IsCanceled)
                        {
                            if (transferTask.IsCanceled)
                            {
                                OnCancelation(agent, restore, ex);                                 // transferTask.Exception
                            }
                            else
                            {
                                OnFailure(agent, restore, ex);                                 // transferTask.Exception
                            }
                            return;
                        }
                    }

                    {
                        var message = string.Format("Transfer files finished.");
                        Info(message);
                    }
                }

                CurrentState = RestoreOperationState.EXECUTING_POST_ACTIONS;
                Helper.ExecutePostActions(Report.TransferResults);

                CurrentState = RestoreOperationState.FINISHING;
                OnFinish(agent, restore);
            }
            catch (Exception ex)
            {
                OnFinish(agent, restore, ex);
            }
        }
예제 #6
0
        public void OnFinish(CustomSynchronizationAgent agent, Models.Synchronization sync, Exception ex = null)
        {
            IsRunning = false;

            switch (CurrentState)
            {
            default:
            {
                var message = string.Format("Synchronization failed: {0}", ex.Message);
                Warn(message);
                //StatusInfo.Update(SyncStatusLevel.WARN, message);
                Report.AddErrorMessage(ex.Message);

                Report.OperationStatus = OperationStatus.FAILED;
                sync.DidFail();
                _daoSynchronization.Update(sync);
                OnUpdate(new SyncOperationEvent {
                        Status = SyncOperationStatus.Failed, Message = message
                    });

                break;
            }

            case SyncOperationState.FINISHING:
            {
                SyncResults.Statistics stats = agent.Results.Stats;
                var message = string.Format("Synchronization finished! Stats: {0} files", stats.FileCount);
                Info(message);
                //StatusInfo.Update(SyncStatusLevel.OK, message);

                // TODO(jweyrich): Handle overall failure and cancelation during Sync?
                sync.DidComplete();
                _daoSynchronization.Update(sync);
                OnUpdate(new SyncOperationEvent {
                        Status = SyncOperationStatus.Finished, Message = message
                    });

                /*
                 * switch (agent.Results.OverallStatus)
                 * //switch (sync.Status)
                 * {
                 *      default: throw new InvalidOperationException("Unexpected TransferStatus");
                 *      case TransferStatus.CANCELED:
                 *              Report.OperationStatus = OperationStatus.CANCELED;
                 *              sync.WasCanceled();
                 *              _daoSynchronization.Update(sync);
                 *              OnUpdate(new SyncOperationEvent { Status = SyncOperationStatus.Canceled, Message = message });
                 *              break;
                 *      case TransferStatus.FAILED:
                 *              Report.OperationStatus = OperationStatus.FAILED;
                 *              sync.DidFail();
                 *              _daoSynchronization.Update(sync);
                 *              OnUpdate(new SyncOperationEvent { Status = SyncOperationStatus.Failed, Message = message });
                 *              break;
                 *      case TransferStatus.COMPLETED:
                 *              Report.OperationStatus = OperationStatus.COMPLETED;
                 *              sync.DidComplete();
                 *              _daoSynchronization.Update(sync);
                 *              OnUpdate(new SyncOperationEvent { Status = SyncOperationStatus.Finished, Message = message });
                 *              break;
                 * }
                 */

                break;
            }
            }
        }