/// <summary> /// Implements the Dispose pattern /// </summary> /// <param name="disposing">Whether this object is being disposed via a call to Dispose /// or garbage collected.</param> protected virtual void Dispose(bool disposing) { if (!this._isDisposed) { if (disposing && _shouldDispose) { if (TransferAgent != null) { TransferAgent.Dispose(); TransferAgent = null; } if (CancellationTokenSource != null) { CancellationTokenSource.Dispose(); CancellationTokenSource = null; } } this._isDisposed = true; } }
private async void DoRun() { _IsRunning = true; SaveSettings(); AsyncHelper.SettingsMaxThreadCount = Decimal.ToInt32(nudParallelism.Value); if (_TransferAgent != null) { _TransferAgent.Dispose(); } transferListControl1.ClearTransfers(); AWSCredentials awsCredentials = new BasicAWSCredentials(tbAccessKey.Text, tbSecretKey.Text); TransferAgentOptions options = new TransferAgentOptions(); if (CancelTokenSource != null) { CancelTokenSource.Dispose(); } CancelTokenSource = new CancellationTokenSource(); _TransferAgent = new S3TransferAgent(options, awsCredentials, tbBucketName.Text, CancelTokenSource.Token); _TransferAgent.RemoteRootDir = "backup-99"; switch (_Operation) { case OperationType.BACKUP: { _BackupAgent = new CustomBackupAgent(_TransferAgent); _BackupAgent.Results.Monitor = transferListControl1; /* * _BackupAgent.Results.Failed += (object sender, TransferFileProgressArgs args, Exception e) => * { * Warn("Failed {0}", args.FilePath); * }; * _BackupAgent.Results.Canceled += (object sender, TransferFileProgressArgs args, Exception e) => * { * Warn("Canceled {0}", args.FilePath); * }; * _BackupAgent.Results.Completed += (object sender, TransferFileProgressArgs args) => * { * Info("Completed {0}", args.FilePath); * }; * _BackupAgent.Results.Started += (object sender, TransferFileProgressArgs args) => * { * Info("Started {0}", args.FilePath); * }; * _BackupAgent.Results.Progress += (object sender, TransferFileProgressArgs args) => * { * Info("Progress {0}% {1} ({2}/{3} bytes)", * args.PercentDone, args.FilePath, args.TransferredBytes, args.TotalBytes); * }; */ LinkedList <CustomVersionedFile> sources = new LinkedList <CustomVersionedFile>(); if (cbSimulateFailure.Checked) { sources.AddLast(new CustomVersionedFile(@"C:\pagefile.sys")); } DirectoryInfo dir = new DirectoryInfo(txtSourceDirectory.Text); if (dir != null) { foreach (FileInfo file in dir.GetFiles()) { sources.AddLast(new CustomVersionedFile(file.FullName)); } } _BackupAgent.Files = sources; Info("Estimate backup size: {0} files, {1} bytes", _BackupAgent.Results.Stats.Total, FileSizeUtils.FileSizeToString(_BackupAgent.EstimatedTransferSize)); Task task = _BackupAgent.Start(); try { await task; } catch (Exception ex) { if (ex.IsCancellation()) { Info(ex.Message); } else { Error(ex.Message); } } break; } case OperationType.RESTORE: { _RestoreAgent = new CustomRestoreAgent(_TransferAgent); _RestoreAgent.Results.Monitor = transferListControl1; // TODO(jweyrich): These are statically hardcoded for now, but they should be dynamic. // To make them dynamic we need to execute a Sync operation to discover them first. LinkedList <CustomVersionedFile> sources = new LinkedList <CustomVersionedFile>(); sources.AddLast(new CustomVersionedFile(@"C:\pagefile.sys")); sources.AddLast(new CustomVersionedFile(@"C:\Teste\a.txt")); sources.AddLast(new CustomVersionedFile(@"C:\Teste\b.txt")); sources.AddLast(new CustomVersionedFile(@"C:\Teste\bash.exe")); sources.AddLast(new CustomVersionedFile(@"C:\Teste\c.txt")); sources.AddLast(new CustomVersionedFile(@"C:\Teste\e.txt")); _RestoreAgent.Files = sources; Info("Estimate backup size: {0} files, {1} bytes", _RestoreAgent.Results.Stats.Total, FileSizeUtils.FileSizeToString(_RestoreAgent.EstimatedTransferSize)); Task task = _RestoreAgent.Start(); try { await task; } catch (Exception ex) { if (ex.IsCancellation()) { Info(ex.Message); } else { Error(ex.Message); } } break; } } OnFinish(); }