Exemple #1
0
        /// <summary>
        /// Update dump of the file on disks.
        /// </summary>
        /// <param name="fileId"></param>
        /// <param name="originalBlobBucket"></param>
        /// <param name="deleted">If true this is an operation of deletion of the artifact.</param>
        /// <returns></returns>
        private Boolean UpdateDumpOfFile(
            string fileId,
            GridFSBucket <String> originalBlobBucket,
            Boolean deleted)
        {
            var findIdFilter = Builders <GridFSFileInfo <string> > .Filter.Eq(x => x.Id, fileId);

            var source = originalBlobBucket.Find(findIdFilter).FirstOrDefault();

            if (source == null)
            {
                return(false); //source stream does not exists
            }
            if (!deleted)
            {
                using (var stream = originalBlobBucket.OpenDownloadStream(fileId))
                {
                    _store.Store(stream, source.Filename, fileId);
                }
            }
            else
            {
                _store.Delete(source.Filename, fileId);
            }

            return(true);
        }
Exemple #2
0
 /// <summary>
 /// Update dump of the file on disks.
 /// </summary>
 /// <param name="blobId"></param>
 /// <param name="originalBlobStore"></param>
 /// <param name="deleted">If true this is an operation of deletion of the artifact.</param>
 /// <returns></returns>
 private Boolean UpdateDumpOfFile(
     string blobId,
     IBlobStore originalBlobStore,
     Boolean deleted)
 {
     try
     {
         //Take descriptor even if the blob is deleted, because deleting a descriptor leav
         //blob in recycle bin, this imply that the blob should still be there
         var descriptor = originalBlobStore.GetDescriptor(new BlobId(blobId));
         if (!deleted)
         {
             using (var stream = descriptor.OpenRead())
             {
                 _store.Store(stream, descriptor.FileNameWithExtension, blobId);
             }
             Logger.Debug($"Blob {blobId} copied to backup store. FileName: {descriptor.FileNameWithExtension}");
         }
         else
         {
             _store.Delete(descriptor.FileNameWithExtension, blobId);
             Logger.Debug($"Blob {blobId} was deleted, delete from the backup store. FileName: {descriptor.FileNameWithExtension}");
         }
         return(true);
     }
     catch (Exception ex)
     {
         if (deleted == false)
         {
             Logger.Error($"Unable to backup blob {blobId} from original store. {ex.Message}", ex);
         }
         else
         {
             //Since the blob is deleted, issue a warning, because it could be that the backup started
             //late and the blob was already purged from recycle bin.
             Logger.Warn($"Unable to backup blob {blobId} from original store. {ex.Message}. Maybe the blob was already deleted by job.", ex);
         }
         return(false);
     }
 }