/// <inheritdoc /> public async Task BeatAsync(CancellationToken cancellationToken) { bool isContainerNotFoundException = false; try { await _blob.UploadTextAsync(String.Empty, cancellationToken : cancellationToken); return; } catch (StorageException exception) { if (exception.IsNotFoundContainerNotFound()) { isContainerNotFoundException = true; } else { throw; } } Debug.Assert(isContainerNotFoundException, "Blob Container was not found"); await _blob.Container.CreateIfNotExistsAsync(cancellationToken); await _blob.UploadTextAsync(String.Empty, cancellationToken : cancellationToken); }
private async Task <bool> TryCreateAsync(IStorageBlockBlob blob, CancellationToken cancellationToken) { bool isContainerNotFoundException = false; try { await blob.UploadTextAsync(string.Empty, cancellationToken : cancellationToken); return(true); } catch (StorageException exception) { if (exception.RequestInformation != null) { if (exception.RequestInformation.HttpStatusCode == 404) { isContainerNotFoundException = true; } else if (exception.RequestInformation.HttpStatusCode == 409 || exception.RequestInformation.HttpStatusCode == 412) { // The blob already exists, or is leased by someone else return(false); } else { throw; } } else { throw; } } Debug.Assert(isContainerNotFoundException); await blob.Container.CreateIfNotExistsAsync(cancellationToken); try { await blob.UploadTextAsync(string.Empty, cancellationToken : cancellationToken); return(true); } catch (StorageException exception) { if (exception.RequestInformation != null && (exception.RequestInformation.HttpStatusCode == 409 || exception.RequestInformation.HttpStatusCode == 412)) { // The blob already exists, or is leased by someone else return(false); } else { throw; } } }
public async Task <bool> TryExecuteAsync(CancellationToken cancellationToken) { Dictionary <string, ParameterLog> logs = new Dictionary <string, ParameterLog>(); AddLogs(_watches, logs); string content = JsonConvert.SerializeObject(logs, JsonSerialization.Settings); try { if (_lastContent == content) { // If it hasn't change, then don't re upload stale content. return(true); } _lastContent = content; await _parameterLogBlob.UploadTextAsync(content, cancellationToken : cancellationToken); return(true); } catch (OperationCanceledException) { throw; } catch (Exception e) { // Not fatal if we can't update parameter status. // But at least log what happened for diagnostics in case it's an infrastructure bug. string msg = "---- Parameter status update failed ----"; _logger?.LogError(0, e, msg); return(false); } }
public static void UploadText(this IStorageBlockBlob blob, string content) { if (blob == null) { throw new ArgumentNullException("blob"); } blob.UploadTextAsync(content).GetAwaiter().GetResult(); }
/// <inheritdoc /> public async Task <string> EnqueueAsync(T message, CancellationToken cancellationToken) { await _blobContainer.CreateIfNotExistsAsync(cancellationToken); string blobName = BlobNames.GetConflictFreeDateTimeBasedBlobName(); IStorageBlockBlob blob = _blobContainer.GetBlockBlobReference(blobName); message.AddMetadata(blob.Metadata); string messageBody = JsonConvert.SerializeObject(message, JsonSerialization.Settings); await blob.UploadTextAsync(messageBody, cancellationToken : cancellationToken); return(blobName); }
public async Task UpdateLatestScanAsync(string storageAccountName, string containerName, DateTime latestScan) { string scanInfoLine; ScanInfo scanInfo = new ScanInfo { LatestScan = latestScan }; using (StringWriter stringWriter = new StringWriter()) { _serializer.Serialize(stringWriter, scanInfo); scanInfoLine = stringWriter.ToString(); } try { IStorageBlockBlob scanInfoBlob = GetScanInfoBlobReference(storageAccountName, containerName); await scanInfoBlob.UploadTextAsync(scanInfoLine); } catch { // best effort } }
private static Task UploadTextAsync(IStorageBlockBlob outputBlob, string contents, CancellationToken cancellationToken) { return outputBlob.UploadTextAsync(contents, cancellationToken: cancellationToken); }
private static Task UploadTextAsync(IStorageBlockBlob outputBlob, string contents, CancellationToken cancellationToken) { return(outputBlob.UploadTextAsync(contents, cancellationToken: cancellationToken)); }
private static async Task<bool> TryInitializeIdAsync(IStorageBlockBlob blob, Guid hostId, CancellationToken cancellationToken) { string text = hostId.ToString("N"); AccessCondition accessCondition = new AccessCondition { IfNoneMatchETag = "*" }; bool failedWithContainerNotFoundException = false; try { await blob.UploadTextAsync(text, encoding: null, accessCondition: accessCondition, options: null, operationContext: null, cancellationToken: cancellationToken); return true; } catch (StorageException exception) { if (exception.IsPreconditionFailed() || exception.IsConflict()) { return false; } else if (exception.IsNotFoundContainerNotFound()) { failedWithContainerNotFoundException = true; } else { throw; } } Debug.Assert(failedWithContainerNotFoundException); await blob.Container.CreateIfNotExistsAsync(cancellationToken); try { await blob.UploadTextAsync(text, encoding: null, accessCondition: accessCondition, options: null, operationContext: null, cancellationToken: cancellationToken); return true; } catch (StorageException retryException) { if (retryException.IsPreconditionFailed() || retryException.IsConflict()) { return false; } else { throw; } } }
private async Task<bool> TryCreateAsync(IStorageBlockBlob blob, CancellationToken cancellationToken) { AccessCondition accessCondition = new AccessCondition { IfNoneMatchETag = "*" }; bool isContainerNotFoundException = false; try { await blob.UploadTextAsync(String.Empty, encoding: null, accessCondition: accessCondition, options: null, operationContext: null, cancellationToken: cancellationToken); return true; } catch (StorageException exception) { if (exception.IsNotFoundContainerNotFound()) { isContainerNotFoundException = true; } else if (exception.IsConflictBlobAlreadyExists()) { return false; } else if (exception.IsPreconditionFailedLeaseIdMissing()) { return false; } else { throw; } } Debug.Assert(isContainerNotFoundException); await blob.Container.CreateIfNotExistsAsync(cancellationToken); try { await blob.UploadTextAsync(String.Empty, encoding: null, accessCondition: accessCondition, options: null, operationContext: null, cancellationToken: cancellationToken); return true; } catch (StorageException exception) { if (exception.IsConflictBlobAlreadyExists()) { return false; } else if (exception.IsPreconditionFailedLeaseIdMissing()) { return false; } else { throw; } } }
public async Task <bool> TryCreateAsync(IStorageBlockBlob blob, CancellationToken cancellationToken) { BlobReceipt.Incomplete.ToMetadata(blob.Metadata); AccessCondition accessCondition = new AccessCondition { IfNoneMatchETag = "*" }; bool isContainerNotFoundException = false; try { await blob.UploadTextAsync(String.Empty, encoding : null, accessCondition : accessCondition, options : null, operationContext : null, cancellationToken : cancellationToken); return(true); } catch (StorageException exception) { if (exception.IsNotFoundContainerNotFound()) { isContainerNotFoundException = true; } else if (exception.IsConflictBlobAlreadyExists()) { return(false); } else if (exception.IsPreconditionFailedLeaseIdMissing()) { return(false); } else { throw; } } Debug.Assert(isContainerNotFoundException); await blob.Container.CreateIfNotExistsAsync(cancellationToken); try { await blob.UploadTextAsync(String.Empty, encoding : null, accessCondition : accessCondition, options : null, operationContext : null, cancellationToken : cancellationToken); return(true); } catch (StorageException exception) { if (exception.IsConflictBlobAlreadyExists()) { return(false); } else if (exception.IsPreconditionFailedLeaseIdMissing()) { return(false); } else { throw; } } }
private static async Task <bool> TryCreateAsync(IStorageBlockBlob blob, CancellationToken cancellationToken) { bool isContainerNotFoundException = false; try { await blob.UploadTextAsync(string.Empty, cancellationToken : cancellationToken); return(true); } catch (StorageException exception) { if (exception.RequestInformation != null) { if (exception.RequestInformation.HttpStatusCode == 404) { isContainerNotFoundException = true; } else if (exception.RequestInformation.HttpStatusCode == 409 || exception.RequestInformation.HttpStatusCode == 412) { // The blob already exists, or is leased by someone else return(false); } else { throw; } } else { throw; } } Debug.Assert(isContainerNotFoundException); var container = blob.Container; try { await container.CreateIfNotExistsAsync(cancellationToken); } catch (StorageException exc) when(exc.RequestInformation.HttpStatusCode == 409 && string.Compare("ContainerBeingDeleted", exc.RequestInformation.ExtendedErrorInformation?.ErrorCode) == 0) { throw new StorageException("The host container is pending deletion and currently inaccessible."); } try { await blob.UploadTextAsync(string.Empty, cancellationToken : cancellationToken); return(true); } catch (StorageException exception) { if (exception.RequestInformation != null && (exception.RequestInformation.HttpStatusCode == 409 || exception.RequestInformation.HttpStatusCode == 412)) { // The blob already exists, or is leased by someone else return(false); } else { throw; } } }
private async Task<bool> TryCreateAsync(IStorageBlockBlob blob, CancellationToken cancellationToken) { bool isContainerNotFoundException = false; try { await blob.UploadTextAsync(string.Empty, cancellationToken: cancellationToken); return true; } catch (StorageException exception) { if (exception.RequestInformation != null) { if (exception.RequestInformation.HttpStatusCode == 404) { isContainerNotFoundException = true; } else if (exception.RequestInformation.HttpStatusCode == 409 || exception.RequestInformation.HttpStatusCode == 412) { // The blob already exists, or is leased by someone else return false; } else { throw; } } else { throw; } } Debug.Assert(isContainerNotFoundException); await blob.Container.CreateIfNotExistsAsync(cancellationToken); try { await blob.UploadTextAsync(string.Empty, cancellationToken: cancellationToken); return true; } catch (StorageException exception) { if (exception.RequestInformation != null && (exception.RequestInformation.HttpStatusCode == 409 || exception.RequestInformation.HttpStatusCode == 412)) { // The blob already exists, or is leased by someone else return false; } else { throw; } } }
private static async Task <bool> TryInitializeIdAsync(IStorageBlockBlob blob, Guid hostId, CancellationToken cancellationToken) { string text = hostId.ToString("N"); AccessCondition accessCondition = new AccessCondition { IfNoneMatchETag = "*" }; bool failedWithContainerNotFoundException = false; try { await blob.UploadTextAsync(text, encoding : null, accessCondition : accessCondition, options : null, operationContext : null, cancellationToken : cancellationToken); return(true); } catch (StorageException exception) { if (exception.IsPreconditionFailed() || exception.IsConflict()) { return(false); } else if (exception.IsNotFoundContainerNotFound()) { failedWithContainerNotFoundException = true; } else { throw; } } Debug.Assert(failedWithContainerNotFoundException); await blob.Container.CreateIfNotExistsAsync(cancellationToken); try { await blob.UploadTextAsync(text, encoding : null, accessCondition : accessCondition, options : null, operationContext : null, cancellationToken : cancellationToken); return(true); } catch (StorageException retryException) { if (retryException.IsPreconditionFailed() || retryException.IsConflict()) { return(false); } else { throw; } } }