Exemplo n.º 1
0
        public static IEnumerable <string> ListIds(
            IAmazonS3 _s3Client,
            string _bucketName,
            string _databaseName,
            string _collectionName)
        {
            string prefix = S3NamingHelper.GetCollection(_databaseName, _collectionName);

            ListObjectsRequest request = new ListObjectsRequest
            {
                BucketName = _bucketName,
                Prefix     = prefix
            };

            Task <ListObjectsResponse> task = _s3Client.ListObjectsAsync(request);

            Task.WaitAll(task);

            ListObjectsResponse response = task.Result;

            List <string> ids = new List <string>();

            foreach (var s3object in response.S3Objects)
            {
                string id = Path.GetFileNameWithoutExtension(s3object.Key);
                ids.Add(id);
            }

            return(ids);
        }
Exemplo n.º 2
0
        public static async Task <Stream> ReadPage(
            IAmazonS3 _s3Client,
            string _bucketName,
            string _databaseName,
            uint _pageNumber)
        {
            string key = S3NamingHelper.GetPageFile(_databaseName, _pageNumber);

            GetObjectRequest request = new GetObjectRequest()
            {
                BucketName = _bucketName,
                Key        = key
            };

            GetObjectResponse response = await _s3Client.GetObjectAsync(request);

            return(response.ResponseStream);
        }
Exemplo n.º 3
0
        public static async Task <Stream> ReadBinary(
            IAmazonS3 _s3Client,
            string _bucketName,
            string _databaseName,
            string _collectionName,
            string _id)
        {
            string key = S3NamingHelper.GetBinaryFile(_databaseName, _collectionName, _id);

            GetObjectRequest request = new GetObjectRequest()
            {
                BucketName = _bucketName,
                Key        = key
            };

            GetObjectResponse response = await _s3Client.GetObjectAsync(request);

            return(response.ResponseStream);
        }
Exemplo n.º 4
0
        public static Stream ReadDocument(
            IAmazonS3 _s3Client,
            string _bucketName,
            string _databaseName,
            string _collectionName,
            string _id)
        {
            string key = S3NamingHelper.GetDocument(_databaseName, _collectionName, _id);

            GetObjectRequest request = new GetObjectRequest()
            {
                BucketName = _bucketName,
                Key        = key
            };

            Task <GetObjectResponse> task = _s3Client.GetObjectAsync(request);

            Task.WaitAll(task);

            return(task.Result.ResponseStream);
        }
Exemplo n.º 5
0
        public static void WritePage(
            IAmazonS3 _s3Client,
            string _bucketName,
            string _databaseName,
            uint _pageNumber,
            Stream _dataStream)
        {
            string key = S3NamingHelper.GetPageFile(_databaseName, _pageNumber);

            PutObjectRequest request = new PutObjectRequest()
            {
                BucketName  = _bucketName,
                Key         = key,
                ContentType = "application/binary",
                InputStream = _dataStream
            };

            Task <PutObjectResponse> task = _s3Client.PutObjectAsync(request);

            Task.WaitAll(task);
        }
Exemplo n.º 6
0
        public static void WriteBinary(
            IAmazonS3 _s3Client,
            string _bucketName,
            string _databaseName,
            string _collectionName,
            string _id,
            string _contentType,
            Stream _dataStream)
        {
            string key = S3NamingHelper.GetBinaryFile(_databaseName, _collectionName, _id);

            PutObjectRequest request = new PutObjectRequest()
            {
                BucketName  = _bucketName,
                Key         = key,
                ContentType = _contentType,
                InputStream = _dataStream
            };

            Task <PutObjectResponse> task = _s3Client.PutObjectAsync(request);

            Task.WaitAll(task);
        }