private async Task <List <SourceItem> > GetSourceBlobs(int accountIndex) { var blobs = new List <SourceItem>(); BlobContainerClient container = new BlobContainerClient(_config.Sources.Split("|")[accountIndex], _config.ContainerName); //create the container if needed await container.CreateIfNotExistsAsync(); await container.SetAccessPolicyAsync(PublicAccessType.Blob); //get all the blobs in the container await foreach (var item in container.GetBlobsAsync()) { blobs.Add(new SourceItem() { Account = accountIndex, FileName = item.Name }); } //if the container is empty fill it while (_config.NumFiles > blobs.Count()) { string fileName = $"{Guid.NewGuid().ToString().Replace("-", "").ToLower()}.obj"; await container.UploadBlobAsync(fileName, new MemoryStream(_randomBytes.Generate())); blobs.Add(new SourceItem() { Account = accountIndex, FileName = fileName }); } //return the list of blobs return(blobs); }
/// <inheritdoc cref="IOwinResponseMapper.MapAsync"/> public async Task MapAsync(ResponseMessage responseMessage, IResponse response) { if (responseMessage == null) { return; } byte[] bytes; switch (responseMessage.FaultType) { case FaultType.EMPTY_RESPONSE: bytes = IsFault(responseMessage) ? new byte[0] : GetNormalBody(responseMessage); break; case FaultType.MALFORMED_RESPONSE_CHUNK: bytes = GetNormalBody(responseMessage) ?? new byte[0]; if (IsFault(responseMessage)) { bytes = bytes.Take(bytes.Length / 2).Union(_randomizerBytes.Generate()).ToArray(); } break; default: bytes = GetNormalBody(responseMessage); break; } var statusCodeType = responseMessage.StatusCode?.GetType(); switch (statusCodeType) { case Type typeAsIntOrEnum when typeAsIntOrEnum == typeof(int) || typeAsIntOrEnum == typeof(int?) || typeAsIntOrEnum.GetTypeInfo().IsEnum: response.StatusCode = MapStatusCode((int)responseMessage.StatusCode); break; case Type typeAsString when typeAsString == typeof(string): // Note: this case will also match on null int.TryParse(responseMessage.StatusCode as string, out int result); response.StatusCode = MapStatusCode(result); break; default: break; } SetResponseHeaders(responseMessage, response); if (bytes != null) { await response.Body.WriteAsync(bytes, 0, bytes.Length); } }
/// <inheritdoc cref="IOwinResponseMapper.MapAsync"/> public async Task MapAsync(ResponseMessage responseMessage, IResponse response) { if (responseMessage == null) { return; } byte[] bytes; switch (responseMessage.FaultType) { case FaultType.EMPTY_RESPONSE: bytes = IsFault(responseMessage) ? new byte[0] : GetNormalBody(responseMessage); break; case FaultType.MALFORMED_RESPONSE_CHUNK: bytes = GetNormalBody(responseMessage) ?? new byte[0]; if (IsFault(responseMessage)) { bytes = bytes.Take(bytes.Length / 2).Union(_randomizerBytes.Generate()).ToArray(); } break; default: bytes = GetNormalBody(responseMessage); break; } switch (responseMessage.StatusCode) { case int statusCodeAsInteger: response.StatusCode = MapStatusCode(statusCodeAsInteger); break; case string statusCodeAsString: // Note: this case will also match on null int.TryParse(statusCodeAsString, out int result); response.StatusCode = MapStatusCode(result); break; } SetResponseHeaders(responseMessage, response); if (bytes != null) { await response.Body.WriteAsync(bytes, 0, bytes.Length); } }
/// <inheritdoc cref="IOwinResponseMapper.MapAsync"/> public async Task MapAsync(ResponseMessage responseMessage, IResponse response) { if (responseMessage == null) { return; } byte[] bytes; switch (responseMessage.FaultType) { case FaultType.EMPTY_RESPONSE: bytes = IsFault(responseMessage) ? new byte[0] : GetNormalBody(responseMessage); break; case FaultType.MALFORMED_RESPONSE_CHUNK: bytes = GetNormalBody(responseMessage) ?? new byte[0]; if (IsFault(responseMessage)) { bytes = bytes.Take(bytes.Length / 2).Union(_randomizerBytes.Generate()).ToArray(); } break; default: bytes = GetNormalBody(responseMessage); break; } response.StatusCode = responseMessage.StatusCode; SetResponseHeaders(responseMessage, response); if (bytes != null) { await response.Body.WriteAsync(bytes, 0, bytes.Length); } }