public async Task <CloudPlatformResponse> PostBlobAsync(CloudPlatformRequest request)
        {
            AmazonWebServiceResponse response;

            if (request == null)
            {
                throw new ArgumentException("Request is null");
            }
            using (var client = new AmazonS3Client())
            {
                response = await client.PutObjectAsync(new PutObjectRequest()
                {
                    BucketName      = request.Source,
                    InputStream     = request.DataStream,
                    AutoCloseStream = false,
                    Key             = request.Key
                });

                var insertionTime = DateTime.UtcNow;
                if (!response.ResponseMetadata.Metadata.ContainsKey(ServerlessBenchmark.Constants.InsertionTime))
                {
                    response.ResponseMetadata.Metadata.Add(ServerlessBenchmark.Constants.InsertionTime, insertionTime.ToString("o"));
                }
            }
            return(AwsCloudPlatformResponse.PopulateFrom(response));
        }
        public CloudPlatformResponse DeleteBlobs(CloudPlatformRequest request)
        {
            var blobs = (IEnumerable <S3Object>)ListBlobs(request).Data;
            AmazonWebServiceResponse response = null;
            const int deleteLimit             = 1000;

            if (blobs.Any())
            {
                using (var client = new AmazonS3Client(new AmazonS3Config()))

                {
                    try
                    {
                        var keys = blobs.Select(blob => new KeyVersion {
                            Key = blob.Key
                        }).ToList();
                        int num = keys.Count;
                        do
                        {
                            Console.WriteLine("Deleting Blobs - Remaining:       {0}", num);
                            num -= (num < deleteLimit ? num : deleteLimit);
                            var takenKeys = keys.Take(deleteLimit).ToList();
                            response = client.DeleteObjects(new DeleteObjectsRequest()
                            {
                                BucketName = request.Source,
                                Objects    = takenKeys
                            });
                            keys = keys.Except(takenKeys).ToList();
                        } while (num > 0);
                    }
                    catch (DeleteObjectsException e)
                    {
                        DeleteObjectsResponse errorResponse = e.Response;
                        foreach (DeleteError deleteError in errorResponse.DeleteErrors)
                        {
                            Console.WriteLine("Error deleting item " + deleteError.Key);
                            Console.WriteLine(" Code - " + deleteError.Code);
                            Console.WriteLine(" Message - " + deleteError.Message);
                        }
                    }
                }
            }
            return(AwsCloudPlatformResponse.PopulateFrom(response));
        }
        public static AwsCloudPlatformResponse PopulateFrom(AmazonWebServiceResponse response)
        {
            if (response == null)
            {
                return(null);
            }
            string   insertionTime;
            DateTime insertionDateTime;

            response.ResponseMetadata.Metadata.TryGetValue(Constants.InsertionTime, out insertionTime);
            DateTime.TryParse(insertionTime, out insertionDateTime);
            var genericPlatformReponse = new AwsCloudPlatformResponse()
            {
                HttpStatusCode = response.HttpStatusCode,
                TimeStamp      = insertionDateTime
            };

            return(genericPlatformReponse);
        }