public void TestingAQueryWithVersioning()
        {
            string bucket = Guid.NewGuid().ToString();

            PutBucketRequestECS pbr = new PutBucketRequestECS()
            {
                BucketName = bucket,
            };

            pbr.SetMetadataSearchKeys(bucketMetadataSearchKeys);

            client.PutBucket(pbr);

            PutBucketVersioningRequest pbv = new PutBucketVersioningRequest()
            {
                BucketName       = bucket,
                VersioningConfig = new S3BucketVersioningConfig()
                {
                    Status = VersionStatus.Enabled
                }
            };

            client.PutBucketVersioning(pbv);

            for (int i = 0; i < 5; i++)
            {
                PutObjectRequest object_request = new PutObjectRequest()
                {
                    BucketName  = bucket,
                    Key         = string.Format("obj-{0}", i),
                    ContentBody = string.Format("This is sample content for object {0}.", i)
                };

                object_request.Metadata.Add("x-amz-meta-decimalvalue", Convert.ToString(i * 2));
                object_request.Metadata.Add("x-amz-meta-stringvalue", string.Format("sample-{0}", Convert.ToString(i)));

                client.PutObject(object_request);

                object_request.ContentBody = string.Format("This is sample content for object {0} after versioning has been enabled.", i);

                client.PutObject(object_request);
            }

            QueryObjectsRequest qor = new QueryObjectsRequest()
            {
                BucketName           = bucket,
                IncludeOlderVersions = true,
                Query = "x-amz-meta-decimalvalue>4"
            };

            var qor_respose = client.QueryObjects(qor);

            Assert.IsNotNull(qor_respose.ObjectMatches);
            Assert.AreEqual(4, qor_respose.ObjectMatches.Count);
            Assert.AreEqual(bucket, qor_respose.BucketName);

            CleanBucket(bucket);

            client.DeleteBucket(bucket);
        }
예제 #2
0
        public static void Main(string[] args)
        {
            // create the ECS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            // retrieve the object key and object content from the user
            Console.Write("Enter the object key: ");
            string key = Console.ReadLine();

            Console.Write("Enter the object content: ");
            string content = Console.ReadLine();

            // create object request with retrieved input
            PutObjectRequestECS request = new PutObjectRequestECS()
            {
                BucketName  = ECSS3Factory.S3_BUCKET,
                ContentBody = content,
                Key         = key
            };

            // create the object in demo bucket
            s3.PutObject(request);

            // print out object key/value for validation
            Console.WriteLine(string.Format("Created object {0}/{1} with content: {2}", ECSS3Factory.S3_BUCKET, key, content));
            Console.ReadLine();
        }
        public static void Initialize(TestContext testContext)
        {
            BasicAWSCredentials creds = new BasicAWSCredentials(ConfigurationManager.AppSettings["S3_ACCESS_KEY_ID"], ConfigurationManager.AppSettings["S3_SECRET_KEY"]);

            AmazonS3Config cc = new AmazonS3Config()
            {
                ForcePathStyle   = true,
                ServiceURL       = ConfigurationManager.AppSettings["S3_ENDPOINT"],
                SignatureVersion = ConfigurationManager.AppSettings["SIGNATURE_VERSION"],
                SignatureMethod  = SigningAlgorithm.HmacSHA1,
                UseHttp          = false,
            };

            client = new ECSS3Client(creds, cc);

            PutBucketRequestECS request = new PutBucketRequestECS()
            {
                BucketName = temp_bucket,
            };

            // Set the indexable search keys on the bucket.
            request.SetMetadataSearchKeys(bucketMetadataSearchKeys);
            string vpool_id = ConfigurationManager.AppSettings["VPOOL_ID"];

            if (!string.IsNullOrWhiteSpace(vpool_id))
            {
                request.VirtualPoolId = vpool_id;
            }

            client.PutBucket(request);

            for (int i = 0; i < 5; i++)
            {
                PutObjectRequest object_request = new PutObjectRequest()
                {
                    BucketName  = temp_bucket,
                    Key         = string.Format("obj-{0}", i),
                    ContentBody = string.Format("This is sample content for object {0}", i)
                };

                object_request.Metadata.Add("x-amz-meta-decimalvalue", Convert.ToString(i * 2));
                object_request.Metadata.Add("x-amz-meta-stringvalue", string.Format("sample-{0}", Convert.ToString(i)));

                client.PutObject(object_request);
            }
        }
예제 #4
0
        public static void Main(string[] args)
        {
            // create the ECS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            // object key to create, update, and append
            string key        = "atomic-append.txt";
            string bucketName = ECSS3Factory.S3_BUCKET; // bucket to create object in
            string content    = "Hello World!";

            // first create an initial object
            Console.WriteLine(string.Format("creating initial object {0}/{1} with content: {2}", ECSS3Factory.S3_BUCKET, key, content));

            PutObjectRequestECS request = new PutObjectRequestECS()
            {
                BucketName  = bucketName,
                Key         = key,
                ContentBody = content
            };

            s3.PutObject(request);

            // read object and print content
            Console.WriteLine(string.Format("initial object {0}/{1} with content: [{2}]", bucketName, key, readObject(s3, bucketName, key)));

            // append to the end of the object
            string content2 = " ... and Universe!!";

            // the offset at which our appended data was written is returned
            // (this is the previous size of the object)
            long appendOffset = s3.AppendObject(bucketName, key, content2);

            Console.WriteLine(string.Format("append successful at offset {0}", appendOffset));

            // read object and print content
            Console.WriteLine(string.Format("final object {0}/{1} with content: [{2}]", bucketName, key, readObject(s3, bucketName, key)));

            Console.ReadLine();
        }
예제 #5
0
        public static void Main(string[] args)
        {
            // create the ECS S3 Client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            // retrieve the object key and object content from the user
            Console.Write("Enter the object key: ");
            string key = Console.ReadLine();

            Console.Write("Enter the object content: ");
            string content = Console.ReadLine();

            // retrieve the object metadata key and value from user
            Console.Write("Enter the metadata key: ");
            string metaKey = Console.ReadLine();

            Console.Write("Enter the metadata value: ");
            string metaValue = Console.ReadLine();

            // create object request with retrieved input
            PutObjectRequestECS request = new PutObjectRequestECS()
            {
                BucketName  = ECSS3Factory.S3_BUCKET,
                ContentBody = content,
                Key         = key
            };

            // add metadata to request
            request.Metadata.Add(metaKey, metaValue);

            // create the object with metadata in the demo bucket
            s3.PutObject(request);

            // print out object key/value and metadata key/value for validation
            Console.WriteLine(string.Format("Create object {0}/{1} with metadata {2}={3} and content: {4}",
                                            ECSS3Factory.S3_BUCKET, key, metaKey, metaValue, content));
            Console.ReadLine();
        }
        public static void Main(string[] args)
        {
            ECSS3Client         s3 = ECSS3Factory.getS3Client();
            PutObjectRequestECS request;

            string key        = "update-append.txt";               // object key to create, update, and append
            string bucketName = ECSS3Factory.S3_BUCKET;            // bucket to create object in
            string content    = "The tan fox jumped over the dog"; // initial object content
            int    tanIndex   = content.IndexOf("tan");

            Console.WriteLine(string.Format("creating initial object {0}/{1} with content: {2}", ECSS3Factory.S3_BUCKET, key, content));

            // first create an initial object
            request             = new PutObjectRequestECS();
            request.BucketName  = bucketName;
            request.Key         = key;
            request.ContentBody = content;
            s3.PutObject(request);

            // read object and print content
            Console.WriteLine(string.Format("initial object {0}/{1} with content: [{2}]", bucketName, key, readObject(s3, bucketName, key)));

            // update the object in the middle
            string content2 = "red";

            request             = new PutObjectRequestECS();
            request.BucketName  = bucketName;
            request.Key         = key;
            request.ContentBody = content2;
            request.Range       = Range.fromOffsetLength(tanIndex, content2.Length);
            Console.WriteLine(string.Format("updating object at offset {0}", tanIndex));
            s3.PutObject(request);

            // read object and print content
            Console.WriteLine(string.Format("updated object {0}/{1} with content: [{2}]", bucketName, key, readObject(s3, bucketName, key)));

            // append to the object
            string content3 = " and cat";

            Console.WriteLine(string.Format("appending object at offset {0}", content.Length));
            request             = new PutObjectRequestECS();
            request.BucketName  = bucketName;
            request.Key         = key;
            request.ContentBody = content3;
            request.Range       = Range.fromOffset(content.Length);
            s3.PutObject(request);

            // read object and print content
            Console.WriteLine(string.Format("appended object {0}/{1} with content: [{2}]", bucketName, key, readObject(s3, bucketName, key)));

            // create a sparse object by appending past the end of the object
            string content4 = "#last byte#";

            Console.WriteLine(string.Format("sparse append object at offset {0}", 45));
            request             = new PutObjectRequestECS();
            request.BucketName  = bucketName;
            request.Key         = key;
            request.ContentBody = content4;
            request.Range       = Range.fromOffset(45);
            s3.PutObject(request);

            // read object and print content
            Console.WriteLine(string.Format("sparse append object {0}/{1} with content: [{2}]", bucketName, key, readObject(s3, bucketName, key)));

            Console.ReadLine();
        }
예제 #7
0
        public static void Main(string[] args)
        {
            // create the AWS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            foreach (string key in KEY_LIST)
            {
                // create object request with retrieved input
                PutObjectRequest request = new PutObjectRequest()
                {
                    BucketName  = ECSS3Factory.S3_BUCKET,
                    ContentBody = key,
                    Key         = key
                };

                // create the object in demo bucket
                s3.PutObject(request);
            }


            while (true)
            {
                Console.Write("Enter the prefix (empty if none): ");
                string prefix = Console.ReadLine();
                Console.Write("Enter the delimiter (e.g. /, empty for none): ");
                string delimiter = Console.ReadLine();
                Console.Write("Enter the marker (empty if none): ");
                string marker = Console.ReadLine();
                Console.Write("Enter the max keys (empty for defaul): ");
                string maxKeys = Console.ReadLine();

                ListObjectsRequest request = new ListObjectsRequest()
                {
                    BucketName = ECSS3Factory.S3_BUCKET
                };

                if (prefix.Length > 0)
                {
                    request.Prefix = prefix;
                }

                if (delimiter.Length > 0)
                {
                    request.Delimiter = delimiter;
                }

                if (marker.Length > 0)
                {
                    request.Marker = marker;
                }

                if (maxKeys.Length > 0)
                {
                    request.MaxKeys = Int32.Parse(maxKeys);
                }

                ListObjectsResponse response = s3.ListObjects(request);

                Console.WriteLine("-----------------");
                Console.WriteLine("Bucket: " + ECSS3Factory.S3_BUCKET);
                Console.WriteLine("Prefix: " + response.Prefix);
                Console.WriteLine("Delimiter: " + response.Delimiter);
                Console.WriteLine("Marker: " + marker);
                Console.WriteLine("IsTruncated? " + response.IsTruncated);
                Console.WriteLine("NextMarker: " + response.NextMarker);

                Console.WriteLine();

                if (response.CommonPrefixes != null)
                {
                    foreach (string commonPrefix in response.CommonPrefixes)
                    {
                        Console.WriteLine("CommonPrefix: " + commonPrefix);
                    }
                }

                Console.WriteLine("Printing objects");
                Console.WriteLine("-----------------");


                foreach (S3Object s3Object in response.S3Objects)
                {
                    Console.WriteLine(String.Format("{0}    {1}     {2}", s3Object.LastModified.ToString(), s3Object.Size, s3Object.Key));
                }

                Console.Write("Another? (Y/N) ");
                string another = Console.ReadLine();

                if (another.ToUpper() == "N")
                {
                    break;
                }
            }

            foreach (string key in KEY_LIST)
            {
                s3.DeleteObject(ECSS3Factory.S3_BUCKET, key);
            }

            Console.ReadLine();
        }
        public void TestUpdateObjectWithRange()
        {
            string key     = "key-1";
            string content = "The cat crossed the road.";
            int    offset  = content.IndexOf("cat");

            PutObjectRequestECS por = new PutObjectRequestECS()
            {
                BucketName  = temp_bucket,
                Key         = key,
                ContentBody = content
            };

            // create the object
            client.PutObject(por);

            GetObjectResponse respone       = client.GetObject(temp_bucket, key);
            Stream            responeStream = respone.ResponseStream;
            StreamReader      reader1       = new StreamReader(responeStream);
            string            readContent1  = reader1.ReadToEnd();

            Assert.AreEqual(content.Length, readContent1.Length);
            Assert.AreEqual("The cat crossed the road.", readContent1);

            string updatePart = "dog";

            por = new PutObjectRequestECS()
            {
                BucketName  = temp_bucket,
                Key         = key,
                ContentBody = updatePart,
                Range       = Range.fromOffsetLength(offset, updatePart.Length)
            };

            // update the object
            client.PutObject(por);

            // verify update
            GetObjectResponse response       = client.GetObject(temp_bucket, key);
            Stream            responseStream = response.ResponseStream;
            StreamReader      reader         = new StreamReader(responseStream);
            string            readContent    = reader.ReadToEnd();

            Assert.AreEqual("The dog crossed the road.", readContent);

            updatePart = "very lucky animal crossed the road.";

            por = new PutObjectRequestECS()
            {
                BucketName  = temp_bucket,
                Key         = key,
                Range       = Range.fromOffset(offset),
                ContentBody = updatePart
            };

            client.PutObject(por);

            // verify update
            response       = client.GetObject(temp_bucket, key);
            responseStream = response.ResponseStream;
            reader         = new StreamReader(responseStream);
            readContent    = reader.ReadToEnd();
            Assert.AreEqual(content.Substring(0, offset) + updatePart, readContent);
        }
예제 #9
0
        public static void Main(string[] args)
        {
            // create the ECS S3 client
            ECSS3Client s3 = ECSS3Factory.getS3Client();

            // Create the bucket with indexed keys
            List <MetaSearchKey> bucketMetadataSearchKeys = new List <MetaSearchKey>()
            {
                new MetaSearchKey()
                {
                    Name = USER_PREFIX + FIELD_ACCOUNT_ID, Type = MetaSearchDatatype.integer
                },
                new MetaSearchKey()
                {
                    Name = USER_PREFIX + FIELD_BILLING_DATE, Type = MetaSearchDatatype.datetime
                },
                new MetaSearchKey()
                {
                    Name = USER_PREFIX + FIELD_BILL_TYPE, Type = MetaSearchDatatype.@string
                }
            };


            PutBucketRequestECS pbr = new PutBucketRequestECS();

            pbr.BucketName = BUCKET_NAME;
            pbr.SetMetadataSearchKeys(bucketMetadataSearchKeys);
            s3.PutBucket(pbr);

            foreach (string key in KEY_LIST)
            {
                PutObjectRequestECS por = new PutObjectRequestECS();
                por.BucketName = BUCKET_NAME;
                por.Key        = key;
                por.Metadata.Add(FIELD_ACCOUNT_ID, extractAccountId(key));
                por.Metadata.Add(FIELD_BILLING_DATE, extractBillDate(key));
                por.Metadata.Add(FIELD_BILL_TYPE, extractBillType(key));
                s3.PutObject(por);
            }

            while (true)
            {
                Console.Write("Enter the account id (empty for none): ");
                string accountId = Console.ReadLine();
                Console.Write("Enter the billing date (e.g. 2016-09-22, empty for none): ");
                string billingDate = Console.ReadLine();
                Console.Write("Enter the bill type (e.g. xml.  empty for none): ");
                string billType = Console.ReadLine();

                QueryObjectsRequest qor = new QueryObjectsRequest()
                {
                    BucketName = BUCKET_NAME
                };

                StringBuilder query = new StringBuilder();
                if (accountId.Length > 0)
                {
                    query.Append(USER_PREFIX + FIELD_ACCOUNT_ID + "==" + accountId + "");
                }

                if (billingDate.Length > 0)
                {
                    if (query.Length > 0)
                    {
                        query.Append(" and ");
                    }
                    query.Append(USER_PREFIX + FIELD_BILLING_DATE + "==" + billingDate + "T00:00:00Z");
                }

                if (billType.Length > 0)
                {
                    if (query.Length > 0)
                    {
                        query.Append(" and ");
                    }
                    query.Append(USER_PREFIX + FIELD_BILL_TYPE + "=='" + billType + "'");
                }

                qor.Query = query.ToString();

                QueryObjectsResponse res = s3.QueryObjects(qor);
                Console.WriteLine("--------------------------");
                Console.WriteLine("Bucket: " + res.BucketName);
                Console.WriteLine("Query: " + qor.Query);
                Console.WriteLine();

                Console.WriteLine("Key");
                Console.WriteLine("--------------------------");

                foreach (QueryObject obj in res.ObjectMatches)
                {
                    Console.WriteLine(string.Format("{0}", obj.Name));
                }

                Console.Write("Another? (Y/N) ");
                string another = Console.ReadLine();

                if (another.ToUpper() == "N")
                {
                    break;
                }
            }

            //cleanup
            foreach (string key in KEY_LIST)
            {
                s3.DeleteObject(BUCKET_NAME, key);
            }
            s3.DeleteBucket(BUCKET_NAME);
        }