示例#1
0
        static void Main(string[] args)
        {
            // Configure and build the core client.
            IDs3Client client = new Ds3Builder(
                ConfigurationManager.AppSettings["Ds3Endpoint"],
                new Credentials(
                    ConfigurationManager.AppSettings["Ds3AccessKey"],
                    ConfigurationManager.AppSettings["Ds3SecretKey"]
                )
            ).Build();

            // Tracing example
            if (clientSwitch.TraceInfo) { Trace.WriteLine("List all buckets"); }

            // Loop through all of the objects in the bucket.
            foreach (var bucket in client.GetService(new GetServiceRequest()).ResponsePayload.Buckets)
            {
                if (clientSwitch.TraceVerbose) { Trace.WriteLine(string.Format("Bucket '{0}'.", bucket.Name)); }
                Console.WriteLine("Bucket '{0}'.", bucket.Name);
            }

            // Wait for user input.
            Console.WriteLine("Press enter to continue.");
            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            // Configure and build the core client.
            IDs3Client client = new Ds3Builder(
                ConfigurationManager.AppSettings["Ds3Endpoint"],
                new Credentials(
                    ConfigurationManager.AppSettings["Ds3AccessKey"],
                    ConfigurationManager.AppSettings["Ds3SecretKey"]
                )
            ).Build();

            // Set up the high-level abstractions.
            IDs3ClientHelpers helpers = new Ds3ClientHelpers(client);

            string bucket = "bucket-name";
            string directory = "DataFromBucket";

            // Creates a bulk job with all of the objects in the bucket.
            IJob job = helpers.StartReadAllJob(bucket);
            // Same as: IJob job = helpers.StartReadJob(bucket, helpers.ListObjects(bucket));

            // Keep the job id around. This is useful for job recovery in the case of a failure.
            Console.WriteLine("Job id {0} started.", job.JobId);

            // Tracing example 
            if (clientSwitch.TraceInfo) { Trace.WriteLine(string.Format("StartReadAllJob({0})", bucket)); }
            if (clientSwitch.TraceVerbose) { Trace.WriteLine(string.Format("dd files from: {0}", directory)); }

            // Transfer all of the files.
            job.Transfer(FileHelpers.BuildFileGetter(directory));

            // Wait for user input.
            Console.WriteLine("Press enter to continue.");
            Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            // Configure and build the core client.
            IDs3Client client = new Ds3Builder(
                ConfigurationManager.AppSettings["Ds3Endpoint"],
                new Credentials(
                    ConfigurationManager.AppSettings["Ds3AccessKey"],
                    ConfigurationManager.AppSettings["Ds3SecretKey"]
                )
            ).Build();

            string bucket = "bucket-name";

            // Set up the high-level abstractions.
            IDs3ClientHelpers helpers = new Ds3ClientHelpers(client);

            // Tracing example
            if (clientSwitch.TraceInfo) { Trace.WriteLine(string.Format("ListObjects from bucket = {0}", bucket)); }

            // Loop through all of the objects in the bucket.
            foreach (var obj in helpers.ListObjects("bucket-name"))
            {
                if (clientSwitch.TraceVerbose) { Trace.WriteLine(string.Format("Object '{0}' of size {1}.", obj.Name, obj.Size)); }
                Console.WriteLine("Object '{0}' of size {1}.", obj.Name, obj.Size);
            }

            // Wait for user input.
            Console.WriteLine("Press enter to continue.");
            Console.ReadLine();
        }
示例#4
0
        public Ds3ExampleClient(string endpoint, Credentials credentials, string proxy)
        {
            Ds3Builder builder = new Ds3Builder(endpoint, credentials);
            if (!string.IsNullOrEmpty(proxy))
            {
                builder.WithProxy(new Uri(proxy));
            }
            _client = builder.Build();

            // Set up the high-level abstractions.
            _helpers = new Ds3ClientHelpers(_client);
        }
示例#5
0
        /// <summary>
        /// Creates a Ds3Builder with the endpoint, credentials, and proxy all populated from
        /// environment variables.
        /// </summary>
        public static Ds3Builder FromEnv()
        {
            string _endpoint = Environment.GetEnvironmentVariable("DS3_ENDPOINT");
            string accesskey = Environment.GetEnvironmentVariable("DS3_ACCESS_KEY");
            string secretkey = Environment.GetEnvironmentVariable("DS3_SECRET_KEY");
            string _proxy = Environment.GetEnvironmentVariable("http_proxy");

            var _credentials = new Credentials(accesskey, secretkey);
            Ds3Builder builder = new Ds3Builder(_endpoint, _credentials);
            if (!string.IsNullOrEmpty(_proxy))
            {
                builder.WithProxy(new Uri(_proxy));
            }

            return builder;
        }
示例#6
0
        static void Main(string[] args)
        {
            // Configure and build the core client.
            IDs3Client client = new Ds3Builder(
                ConfigurationManager.AppSettings["Ds3Endpoint"],
                new Credentials(
                    ConfigurationManager.AppSettings["Ds3AccessKey"],
                    ConfigurationManager.AppSettings["Ds3SecretKey"]
                )
            ).Build();

            // Set up the high-level abstractions.
            IDs3ClientHelpers helpers = new Ds3ClientHelpers(client);

            string bucket = "bucket-name";
            string directory = "TestData";

            // Creates a bucket if it does not already exist.
            helpers.EnsureBucketExists(bucket);
            if (clientSwitch.TraceVerbose) { Trace.WriteLine(string.Format("Bucket exists: {0}", bucket)); }

            // Creates a bulk job with the server based on the files in a directory (recursively).
            IJob job = helpers.StartWriteJob(bucket, FileHelpers.ListObjectsForDirectory(directory));

            // Tracing example
            if (clientSwitch.TraceInfo) { Trace.WriteLine(string.Format("StartWriteJob({0})", bucket)); }
            if (clientSwitch.TraceVerbose) { Trace.WriteLine(string.Format("Add files from: {0}", directory)); }

            // Keep the job id around. This is useful for job recovery in the case of a failure.
            Console.WriteLine("Job id {0} started.", job.JobId);

            // Transfer all of the files.
            job.Transfer(FileHelpers.BuildFilePutter(directory));

            // Wait for user input.
            Console.WriteLine("Press enter to continue.");
            Console.ReadLine();
        }
        public void startup()
        {
            _endpoint = Environment.GetEnvironmentVariable("DS3_ENDPOINT");
            string accesskey = Environment.GetEnvironmentVariable("DS3_ACCESS_KEY");
            string secretkey = Environment.GetEnvironmentVariable("DS3_SECRET_KEY");
            _proxy = Environment.GetEnvironmentVariable("http_proxy");
            _credentials = new Credentials(accesskey, secretkey);
            Ds3Builder builder = new Ds3Builder(_endpoint, _credentials);
            if (!string.IsNullOrEmpty(_proxy))
            {
                builder.WithProxy(new Uri(_proxy));
            }
            _client = builder.Build();
            _helpers = new Ds3ClientHelpers(_client);

            setupTestData();
        }
        public void TestHttpsClient()
        {
            if (RuntimeUtils.IsRunningOnMono()) Assert.Ignore();

            var endpoint = Environment.GetEnvironmentVariable("DS3_ENDPOINT");
            endpoint = endpoint.ToLower().Replace("http://", "https://");
            var accesskey = Environment.GetEnvironmentVariable("DS3_ACCESS_KEY");
            var secretkey = Environment.GetEnvironmentVariable("DS3_SECRET_KEY");
            var proxy = Environment.GetEnvironmentVariable("http_proxy");

            var credentials = new Credentials(accesskey, secretkey);
            var builder = new Ds3Builder(endpoint, credentials);
            if (!string.IsNullOrEmpty(proxy))
            {
                builder.WithProxy(new Uri(proxy));
            }

            var client = builder.Build();

            client.GetService(new GetServiceRequest());
        }
        public static void Main()
        {
            // Configure and build the core client.
            var client = new Ds3Builder(
                ConfigurationManager.AppSettings["Ds3Endpoint"],
                new Credentials(
                    ConfigurationManager.AppSettings["Ds3AccessKey"],
                    ConfigurationManager.AppSettings["Ds3SecretKey"]
                )
            ).Build();

            // Set up the high-level abstractions.
            IDs3ClientHelpers helpers = new Ds3ClientHelpers(client);

            const string bucketName = "BulkPutWithStreamStrategy";
            const string directory = "TestData";

            // Creates a bucket if it does not already exist.
            helpers.EnsureBucketExists(bucketName);
            if (ClientSwitch.TraceVerbose) { Trace.WriteLine(string.Format("Bucket exists: {0}", bucketName)); }

            // Creates a bulk job with the server based on the files in a directory (recursively).
            var directoryObjects = FileHelpers.ListObjectsForDirectory(directory).ToList();
            var job = helpers.StartWriteJob(bucketName, directoryObjects, helperStrategy: new WriteStreamHelperStrategy());

            // Tracing example
            if (ClientSwitch.TraceInfo) { Trace.WriteLine(string.Format("StartWriteJob({0})", bucketName)); }
            if (ClientSwitch.TraceVerbose) { Trace.WriteLine(string.Format("Add files from: {0}", directory)); }

            // Keep the job id around. This is useful for job recovery in the case of a failure.
            Console.WriteLine("Job id {0} started.", job.JobId);

            var cryptoStreams = new Dictionary<string, CryptoStream>();
            var md5s = new Dictionary<string, MD5>();

            directoryObjects.ForEach(obj =>
            {
                var md5 = MD5.Create();
                var fileStream = File.OpenRead(Path.Combine(directory, obj.Name));
                var md5Stream = new CryptoStream(fileStream, md5, CryptoStreamMode.Read);

                cryptoStreams.Add(obj.Name, md5Stream);
                md5s.Add(obj.Name, md5);
            });

            // Transfer all of the files.
            job.Transfer(fileName => cryptoStreams[fileName]);

            foreach (var stream in cryptoStreams.Select(pair => pair.Value).Where(stream => !stream.HasFlushedFinalBlock))
            {
                stream.FlushFinalBlock();
            }

            foreach (var md5 in md5s)
            {
                Console.WriteLine("Done transferring file {0} with MD5 value {1}", md5.Key, Convert.ToBase64String(md5.Value.Hash));
            }

            // Wait for user input.
            Console.WriteLine("Press enter to continue.");
            Console.ReadLine();
        }