public async Task <string> UploadAsync(IBlobContainer payloadContainer) { using (var stream = new MemoryStream()) { using (var zip = new ZipArchive(stream, ZipArchiveMode.Create, true)) { string basePath = DirectoryInfo.FullName; basePath = basePath.TrimEnd('/', '\\'); foreach (FileInfo file in DirectoryInfo.EnumerateFiles("*", SearchOption.AllDirectories)) { string relativePath = file.FullName.Substring(basePath.Length + 1); // +1 prevents it from including the leading backslash string zipEntryName = relativePath.Replace('\\', '/'); // Normalize slashes if (!string.IsNullOrEmpty(ArchiveEntryPrefix)) { zipEntryName = ArchiveEntryPrefix + "/" + zipEntryName; } zip.CreateEntryFromFile(file.FullName, zipEntryName); } } stream.Position = 0; Uri zipUri = await payloadContainer.UploadFileAsync(stream, $"{Guid.NewGuid()}.zip"); return(zipUri.AbsoluteUri); } }
private void AssumeBlobContainerIsInitialised() { this.blobContainer = Substitute.For <IBlobContainer>(); this.blockBlob = Substitute.For <IBlockBlob>(); this.blobContainer.GetBlockBlob(Key) .Returns(this.blockBlob); }
/// <summary> /// Initializes a new instance of the <see cref="BlobStorageTransmissionSender"/> class. /// </summary> /// <param name="container">A <c>BLOB</c> <c>Storage</c> container instance.</param> /// <param name="logger">A logger instance</param> /// <exception cref="ArgumentNullException"> /// <paramref name="container"/> must not be <c>null</c>. /// </exception> public BlobStorageTransmissionSender( IBlobContainer container, ILogger <BlobStorageTransmissionSender> logger) { _container = container ?? throw new ArgumentNullException(nameof(container)); _errorLogger = new ErrorLogger <BlobStorageTransmissionSender>(logger); }
public CrudContainerManager( IBlobContainer <T> productPictureContainer, IOptions <AzureStorageAccountOptions> azureStorageAccountOptions) { _azureStorageAccountOptions = azureStorageAccountOptions; _productPictureContainer = productPictureContainer; }
public TenantStore(IBlobContainer<Tenant> tenantBlobContainer, IBlobContainer<byte[]> logosBlobContainer) { Trace.WriteLine(string.Format("Called constructor in TenantStore"), "UNITY"); this.tenantBlobContainer = tenantBlobContainer; this.logosBlobContainer = logosBlobContainer; }
private void Initialize(string spoolId, int pageSize, TimeSpan?lifeTime = null) { Debug.Assert(!string.IsNullOrWhiteSpace(spoolId)); Debug.Assert(pageSize > 0); IsInitialized = true; _spoolId = "spooldata" + spoolId; _pageSize = pageSize; if (lifeTime.HasValue) { _lifeTime = lifeTime; } _pageData = Catalog.Preconfigure() .Add(BlobContainerLocalConfig.ContainerName, _spoolId) .Add(BlobContainerLocalConfig.OptionalAccess, EntityAccess.ContainerPublic.ToString()) .ConfiguredResolve <IBlobContainer <IEnumerable <TData> > >(); if (_lifeTime.HasValue) { _pageData.SetExpire(_lifeTime.Value); } _spoolTrackingData = Catalog.Preconfigure() .Add(BlobContainerLocalConfig.ContainerName, TrackingContainer) .Add(BlobContainerLocalConfig.OptionalAccess, EntityAccess.Private.ToString()) .ConfiguredResolve <IBlobContainer <SpoolTracking> >(); _spoolTrackingData.SetExpire(_lifeTime.Value); }
private static async Task ExpectDownloadModelAsync(IBlobContainer modelContainer, Guid modelId) { await modelContainer.Received(1) .DownloadBlobAsync(ModelsProvider.GetModelBlobName(modelId), Arg.Any <Stream>(), Arg.Any <CancellationToken>()); }
public async Task UploadStream( IBlobContainer containerName, string path, Stream stream, string contentType, IDictionary <string, string>?metadata = null) { var blobContainer = await GetBlobContainer(containerName); var blob = blobContainer.GetBlockBlobClient(path); _logger.LogInformation($"Uploading {containerName}/{path}"); if (stream.CanSeek) { stream.Seek(0, SeekOrigin.Begin); } await blob.UploadAsync( content : stream, httpHeaders : new BlobHttpHeaders { ContentType = contentType, }, metadata : metadata ); }
public VersionManager( IBlobContainer <VersionContainer> container, IVersionRepository versionRepository) { VersionBlobContainer = container; VersionRepository = versionRepository; }
public FileSystemAppService( IBlobContainer <FileSystemContainer> blobContainer, IBlobContainerConfigurationProvider blobContainerConfigurationProvider) { BlobContainer = blobContainer; BlobContainerConfigurationProvider = blobContainerConfigurationProvider; }
public async Task <bool> IsAppendSupported(IBlobContainer containerName, string path) { var blobContainer = await GetBlobContainer(containerName); var blob = blobContainer.GetAppendBlobClient(path); if (await blob.ExistsAsync()) { return(true); } try { await blob.CreateIfNotExistsAsync(); return(true); } catch (StorageException e) { if (e.Message.Contains("Storage Emulator")) { // Storage Emulator doesn't support AppendBlob return(false); } throw; } }
private static IBlobDirectory GetBlobDirectory(IBlobContainer blobContainer) { var directoryName = AzureResourceUniqueNameCreator.CreateUniqueBlobDirectoryName(); var blobDirectory = blobContainer.GetBlobDirectory(directoryName); return(blobDirectory); }
public Function3Worker( ILoger <Function3Worker> logger, IStreamBlobReader reader, IFeedReader feedReader, IQueue <ChannelUpdate> queue, IBlobPathGenerator pathGenerator, IBlobContainer blobContainer, ISerializer serializer, INewsWriter newsWriter, IHashSum hasher) { Ensure.NotNull(logger, nameof(logger)); Ensure.NotNull(reader, nameof(reader)); Ensure.NotNull(feedReader, nameof(feedReader)); Ensure.NotNull(queue, nameof(queue)); Ensure.NotNull(pathGenerator, nameof(pathGenerator)); Ensure.NotNull(blobContainer, nameof(blobContainer)); Ensure.NotNull(serializer, nameof(serializer)); Ensure.NotNull(newsWriter, nameof(newsWriter)); this.logger = logger; this.reader = reader; this.feedReader = feedReader; this.queue = queue; this.pathGenerator = pathGenerator; this.blobContainer = blobContainer; this.serializer = serializer; this.newsWriter = newsWriter; this.hasher = hasher; }
public TenantStore(IBlobContainer <Tenant> tenantBlobContainer, IBlobContainer <byte[]> logosBlobContainer) { Trace.WriteLine(string.Format("Called constructor in TenantStore"), "UNITY"); this.tenantBlobContainer = tenantBlobContainer; this.logosBlobContainer = logosBlobContainer; }
public Function2Worker( ILoger <Function2Worker> log, IChannelsDownloadsReader downloadsReader, IBlobPathGenerator blobPathGenerator, IHttpDownloader httpDownloader, IBlobContainer blobContainer, IChannelsDownloadsWriter downloadsWriter, ISerializer serializer, IHashSum hasher) { Ensure.NotNull(log, nameof(log)); Ensure.NotNull(downloadsReader, nameof(downloadsReader)); Ensure.NotNull(blobPathGenerator, nameof(blobPathGenerator)); Ensure.NotNull(httpDownloader, nameof(httpDownloader)); Ensure.NotNull(blobContainer, nameof(blobContainer)); Ensure.NotNull(downloadsWriter, nameof(downloadsWriter)); Ensure.NotNull(serializer, nameof(serializer)); Ensure.NotNull(hasher, nameof(hasher)); this.log = log; this.downloadsReader = downloadsReader; this.blobPathGenerator = blobPathGenerator; this.httpDownloader = httpDownloader; this.blobContainer = blobContainer; this.downloadsWriter = downloadsWriter; this.serializer = serializer; this.hasher = hasher; }
public Blob(string blobName, IBlobClient blobClient, IBlobContainer container, IBlobDirectory blobDirectory) { _blobName = blobName; _exists = false; _blobContainer = container; _blobClient = blobClient; _blobDirectory = blobDirectory; }
public static IReturnsResult <IBlobStorageService> SetupDeleteBlob( this Mock <IBlobStorageService> service, IBlobContainer container, string path) { return(service.Setup(s => s.DeleteBlob(container, path)) .Returns(Task.CompletedTask)); }
public DocumentStore(IEventSource eventSource, IHashAlgorithm hashAlgorithm, ITable <DocumentMetadata> table, IBlobContainer blobContainer, ICompressor compressor) { _eventSource = eventSource; _hashAlgorithm = hashAlgorithm; _table = table; _blobContainer = blobContainer; _compressor = compressor; }
public async Task DeleteBlob(IBlobContainer containerName, string path) { var blob = await GetBlobClient(containerName, path); _logger.LogInformation($"Deleting blob {containerName}/{path}"); await blob.DeleteIfExistsAsync(); }
public TestPetImagesClient(ICosmosContainer accountContainer, ICosmosContainer imageContainer, IBlobContainer blobContainer, IMessagingClient messagingClient) { this.AccountContainer = accountContainer; this.ImageContainer = imageContainer; this.BlobContainer = blobContainer; this.MessagingClient = messagingClient; }
public IBlobContainer CreateBlobContainerInstance(string accountName, string containerName) { IBlobContainer operationStatus = this.sharedStorageManager.CreateBlobContainerInstance(accountName, containerName); operationStatus.OperationStatus = this.OperationStatus; operationStatus.ProviderInjection = this.ProviderInjection; return(operationStatus); }
public ImageController(IAccountContainer accountContainer, IImageContainer imageContainer, IBlobContainer blobContainer, IMessagingClient messagingClient) { this.AccountContainer = accountContainer; this.ImageContainer = imageContainer; this.BlobContainer = blobContainer; this.MessagingClient = messagingClient; }
public async Task <ISentJob> SendAsync(Action <string> log = null) { IBlobHelper storage; if (string.IsNullOrEmpty(StorageAccountConnectionString)) { storage = new ApiBlobHelper(HelixApi.Storage); } else { storage = new ConnectionStringBlobHelper(StorageAccountConnectionString); } IBlobContainer storageContainer = await storage.GetContainerAsync(TargetContainerName); var jobList = new List <JobListEntry>(); List <string> correlationPayloadUris = (await Task.WhenAll(CorrelationPayloads.Select(p => p.UploadAsync(storageContainer, log)))).ToList(); jobList = (await Task.WhenAll( _workItems.Select(async w => { var entry = await w.SendAsync(storageContainer, TargetContainerName, log); entry.CorrelationPayloadUris = correlationPayloadUris; return(entry); } ))).ToList(); string jobListJson = JsonConvert.SerializeObject(jobList); Uri jobListUri = await storageContainer.UploadTextAsync( jobListJson, $"job-list-{Guid.NewGuid()}.json"); string jobStartIdentifier = Guid.NewGuid().ToString("N"); JobCreationResult newJob = await HelixApi.RetryAsync( () => JobApi.NewAsync( new JobCreationRequest( Source, Type, Build, _properties.ToImmutableDictionary(), jobListUri.ToString(), TargetQueueId, storageContainer.Uri, storageContainer.ReadSas, storageContainer.WriteSas) { Creator = Creator, MaxRetryCount = MaxRetryCount ?? 0, JobStartIdentifier = jobStartIdentifier, }), ex => log?.Invoke($"Starting job failed with {ex}\nRetrying...")); return(new SentJob(JobApi, newJob)); }
/// <summary> /// Adds <c>Azure BLOB Storage</c> telemetry attachment transmission services to the service collection. /// </summary> /// <param name="container">A <see cref="IBlobContainer"/> instance.</param> /// <param name="descriptor">An attachment descriptor instance.</param> public static Task UploadAsync(this IBlobContainer container, AttachmentDescriptor descriptor) { if (container == null) { throw new ArgumentNullException(nameof(container)); } return(container.UploadAsync(descriptor, CancellationToken.None)); }
public static IReturnsResult <IBlobStorageService> SetupCheckBlobExists( this Mock <IBlobStorageService> service, IBlobContainer container, string path, bool exists) { return(service.Setup(s => s.CheckBlobExists(container, path)) .ReturnsAsync(exists)); }
public static IReturnsResult <IBlobStorageService> SetupDownloadBlobText( this Mock <IBlobStorageService> service, IBlobContainer container, string path, string blobText) { return(service.Setup(s => s.DownloadBlobText(container, path)) .ReturnsAsync(blobText)); }
public async Task Run(IDictionary <string, object> parameters) { IBlobClient client = _blobClientFactory.CreateBlobClient(); IBlobContainer container = client.GetContainerReference(_containerName); await container.CreateIfNotExistsAsync((BlobRequestOptions)parameters["options"]); IBlockBlob blob = container.GetBlockBlobReference((string)parameters["blobPath"]); await blob.UploadFromFileAsync((string)parameters["filePath"], (string)parameters["contentType"]); }
public async Task <string> UploadAsync(IBlobContainer payloadContainer, Action <string> log) { using (var stream = File.OpenRead(Archive.FullName)) { Uri zipUri = await payloadContainer.UploadFileAsync(stream, $"{Archive.Name}"); return(zipUri.AbsoluteUri); } }
public async Task <string> UploadAsync(IBlobContainer payloadContainer) { using (var stream = new FileStream(Archive.FullName, FileMode.Open)) { Uri zipUri = await payloadContainer.UploadFileAsync(stream, $"{Archive.Name}"); return(zipUri.AbsoluteUri); } }
private static void ProvideBlob(IBlobContainer blobContainer, string name, string sourceFilePath) { blobContainer.DownloadBlobAsync(name, Arg.Any <string>(), Arg.Any <CancellationToken>()) .Returns(args => { File.Copy(sourceFilePath, args[1] as string); return(Task.FromResult(0)); }); }
public BlogPostPublicAppService( IBlogRepository blogRepository, IBlogPostRepository blogPostRepository, IBlobContainer <BlogPostCoverImageContainer> blobContainer) { BlogRepository = blogRepository; BlogPostRepository = blogPostRepository; BlobContainer = blobContainer; }
public void Write(IBlobContainer blobContainer, string blobAddress) { if (blobContainer == null) { throw new ArgumentNullException("blobContainer"); } if (FileContentStream == null) { throw new InvalidOperationException(string.Format("Cannot {0} prior to initializing from a template.", MethodBase.GetCurrentMethod().Name)); } blobContainer.UploadFromStream(blobAddress, FileContentStream, ContentType); }
public SurveyAnswerStore( ITenantStore tenantStore, ISurveyAnswerContainerFactory surveyAnswerContainerFactory, IMessageQueue<SurveyAnswerStoredMessage> standardSurveyAnswerStoredQueue, IMessageQueue<SurveyAnswerStoredMessage> premiumSurveyAnswerStoredQueue, IBlobContainer<List<string>> surveyAnswerIdsListContainer) { Trace.WriteLine(string.Format("Called constructor in SurveyAnswerStore"), "UNITY"); this.tenantStore = tenantStore; this.surveyAnswerContainerFactory = surveyAnswerContainerFactory; this.standardSurveyAnswerStoredQueue = standardSurveyAnswerStoredQueue; this.premiumSurveyAnswerStoredQueue = premiumSurveyAnswerStoredQueue; this.surveyAnswerIdsListContainer = surveyAnswerIdsListContainer; }
private static void CleanupContainer(IBlobContainer container) { Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Cleaning up container '{0}' of all aged blobs.", container.Name), "Information"); try { container.DeleteAged(DateTime.UtcNow.AddDays(-1 * 2)); Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Cleaned container '{0}' successfully.", container.Name), "Information"); } catch (BlobException e) { Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Failed cleaning container '{0}' due to error:\r\n{1}", container.Name, e.ToString()), "Warning"); } }
public Container(IBlobContainer provider) { _provider = provider; }