private void AddFileToZipFile (IFileInfo fileInfo, ZipOutputStream zipOutputStream, ZipNameTransform nameTransform) { var fileStream = GetFileStream (fileInfo); var fileLength = fileInfo.Length; if (fileStream == null) return; var zipEntry = CreateZipFileEntry (fileInfo, nameTransform); zipOutputStream.PutNextEntry (zipEntry); using (fileStream) { var streamCopier = new StreamCopier(); streamCopier.TransferProgress += (sender, args) => OnZippingProgress (args, fileInfo.FullName); if (!streamCopier.CopyStream (fileStream, zipOutputStream)) { zipEntry.Size = -1; throw new AbortException(); } } _currentFileIndex++; _currentTotalValueExcludingCurrentFileValue += fileLength; }
public void SetUp () { _streamCopier = new StreamCopier(); }
/// <summary> /// Task execution override /// </summary> protected override void DoExecute() { // prepare the restore plugin for the session // and mark it as in-progress using (var txn = new TransactionScope(TransactionScopeOption.Required, TimeSpan.MaxValue)) { this.restore = this.Archive.PrepareRestore(this.Session); if (this.Session.State == SkyFloe.Restore.SessionState.Pending) { this.Session.State = SkyFloe.Restore.SessionState.InProgress; this.Archive.RestoreIndex.UpdateSession(this.Session); } txn.Complete(); } this.limiter = new IO.RateLimiter(this.Session.RateLimit); this.copier = new IO.StreamCopier(); for (; ; ) { this.Canceler.ThrowIfCancellationRequested(); // fetch and restore the next pending entry var entry = this.Archive.RestoreIndex.LookupNextEntry(this.Session); if (entry == null) break; RestoreEntry(entry); } // there are no more pending restore entries, so complete the session this.Session.State = SkyFloe.Restore.SessionState.Completed; this.Archive.RestoreIndex.UpdateSession(this.Session); }
/// <summary> /// Initializes a new archive instance /// </summary> /// <param name="s3"> /// The connected AWS S3 client /// </param> /// <param name="glacier"> /// The connected AWS Glacier client /// </param> /// <param name="vault"> /// The name of the Glacier vault for the archive /// </param> /// <param name="bucket"> /// The name of the S3 bucket containing the backup index /// </param> /// <param name="name"> /// The name of the archive /// </param> public GlacierArchive( Amazon.S3.AmazonS3 s3, Amazon.Glacier.AmazonGlacierClient glacier, String vault, String bucket, String name) { this.s3 = s3; this.glacier = glacier; this.vault = vault; this.bucket = bucket; this.name = name; // connect to the restore index var restoreIndexPath = new IO.Path( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SkyFloe", "AwsGlacier", name, "restore.db" ); IO.FileSystem.CreateDirectory(restoreIndexPath.Parent); this.restoreIndex = (IO.FileSystem.GetMetadata(restoreIndexPath).Exists) ? Sqlite.RestoreIndex.Open(restoreIndexPath) : Sqlite.RestoreIndex.Create(restoreIndexPath, new Restore.Header()); this.copier = new IO.StreamCopier(); }