protected void CFProviderListContainerObjects(string cfcontainername, string dcregion, bool dcsnet = true)
        {
            var identity = new RackspaceCloudIdentity() { Username = CFUsernameText.Text, APIKey = CFApiKeyText.Text };

            CloudIdentityProvider identityProvider = new net.openstack.Providers.Rackspace.CloudIdentityProvider(identity);
            CloudFilesProvider CloudFilesProvider = new net.openstack.Providers.Rackspace.CloudFilesProvider(identity);

            var Cfobjects = CloudFilesProvider.ListObjects(cfcontainername, null, null, null, dcregion, dcsnet);

            CFContainerContentsDDL.DataSource = Cfobjects;
            CFContainerContentsDDL.DataTextField = "Name";
            CFContainerContentsDDL.DataBind();
        }
        private IEnumerable<ContainerObject> ListContainer(CloudIdentity cloudIdentity, string container, int? limit = null, string prefix = null, string region = null, bool useInternalUrl = false) {
            var provider = new CloudFilesProvider(cloudIdentity);

            ContainerObject lastContainerObject = null;

            do {
                string marker = lastContainerObject != null ? lastContainerObject.Name : null;
                IEnumerable<ContainerObject> containerObjects = provider.ListObjects(container, limit, marker, null, prefix, region, useInternalUrl, cloudIdentity);
                lastContainerObject = null;
                foreach (ContainerObject containerObject in containerObjects) {
                    lastContainerObject = containerObject;
                    yield return containerObject;
                }
            } while (lastContainerObject != null);

        }
        public bool DownloadFromRackSpaceCloudFiles()
        {
            bool syncSucceeded = true;
            try
            {
                var cloudIdentity = new CloudIdentity() { APIKey = this.apiKey, Username = this.username };
                var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
                IEnumerable<ContainerObject> containerObjectList = cloudFilesProvider.ListObjects(container);

                foreach (ContainerObject containerObject in containerObjectList)
                {
                    cloudFilesProvider.GetObjectSaveToFile(container, localSource, containerObject.Name, containerObject.Name);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in downloading from rackspace: " + e);
                syncSucceeded = false;
            }
            return syncSucceeded;
        }
        public void Should_Create_Object_From_File_Without_Headers()
        {
            string filePath = Path.Combine(Directory.GetCurrentDirectory(), objectName);
            string fileName = Path.GetFileName(filePath);
            var headers = new Dictionary<string, string>();
            var provider = new CloudFilesProvider(_testIdentity);
            provider.CreateObjectFromFile(containerName, filePath, fileName, 65536, headers, identity: _testIdentity);

            var containerGetObjectsResponse = provider.ListObjects(containerName, identity: _testIdentity);
            Assert.AreEqual(fileName, containerGetObjectsResponse.Where(x => x.Name.Equals(fileName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Name);
        }
        public void Should_Create_Object_From_File_With_Headers()
        {
            string filePath = Path.Combine(Directory.GetCurrentDirectory(), objectName);
            string fileName = Path.GetFileName(filePath);
            Stream stream = System.IO.File.OpenRead(filePath);
            var etag = GetMD5Hash(filePath);
            stream.Position = 0;
            var headers = new Dictionary<string, string>();
            headers.Add("ETag", etag);
            int cnt = 0;
            var info = new FileInfo(filePath);
            var totalBytest = info.Length;
            var provider = new CloudFilesProvider(_testIdentity);
            provider.CreateObjectFromFile(containerName, filePath, fileName, 65536, headers, null, (bytesWritten) =>
            {
                cnt = cnt + 1;
                if (cnt % 10 != 0)
                    return;

                var x = (float)bytesWritten / (float)totalBytest;
                var percentCompleted = (float)x * 100.00;

                Console.WriteLine(string.Format("{0:0.00} % Completed (Writen: {1} of {2})", percentCompleted, bytesWritten, totalBytest));
            });

            var containerGetObjectsResponse = provider.ListObjects(containerName, identity: _testIdentity);
            Assert.AreEqual(fileName, containerGetObjectsResponse.Where(x => x.Name.Equals(fileName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Name);

            var objectHeadersResponse = provider.GetObjectHeaders(containerName, fileName, identity: _testIdentity);

            Assert.IsNotNull(objectHeadersResponse);
            Assert.AreEqual(etag, objectHeadersResponse.Where(x => x.Key.Equals("ETag", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value);
        }
        public void Should_Create_Object_From_Stream_Without_Headers()
        {
            string fileName = objectName;
            Stream stream = System.IO.File.OpenRead(objectName);
            stream.Position = 0;

            var headers = new Dictionary<string, string>();
            var provider = new CloudFilesProvider(_testIdentity);
            provider.CreateObject(containerName, stream, fileName, 65536, headers);

            var containerGetObjectsResponse = provider.ListObjects(containerName, identity: _testIdentity);
            Assert.AreEqual(fileName, containerGetObjectsResponse.Where(x => x.Name.Equals(fileName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Name);

        }
 public void Should_Throw_An_Exception_When_Calling_Get_Objects_From_Container_And_Objects_Does_Not_Exist()
 {
     var provider = new CloudFilesProvider();
     var containerGetObjectsResponse = provider.ListObjects(containerName, identity: _testIdentity);
     Assert.Fail("Expected exception was not thrown.");
 }
        public void Should_Get_Objects_From_Container()
        {
            var provider = new CloudFilesProvider();
            var containerGetObjectsResponse = provider.ListObjects(containerName, identity: _testIdentity);

            Assert.IsNotNull(containerGetObjectsResponse);
        }
        public void Should_Bulk_Delete_All_Objects()
        {
            var provider = new CloudFilesProvider(_testIdentity);

            provider.BulkDelete(provider.ListObjects(containerName2).Select(o => string.Format("{0}/{1}", containerName2, o.Name)));

            var objects = provider.ListObjects(containerName2).ToArray();

            Assert.AreEqual(0, objects.Count());
        }
        public void Should_Delete_Object_But_Not_The_Segments()
        {
            var provider = new CloudFilesProvider(_testIdentity);

            provider.DeleteObject(containerName2, objectName, deleteSegments: false);

            var objects = provider.ListObjects(containerName2).ToArray();

            Assert.AreEqual(11, objects.Count());
            Assert.IsFalse(objects.Any(o => o.Name.Equals(objectName)));
            for (int i = 0; i < 11; i++)
            {
                Assert.IsTrue(objects.Any(o => o.Name.Equals(string.Format("{0}.seg{1}", objectName, i.ToString("0000")))));
            }
        }
        public void Should_Upload_File_In_Segments()
        {
            var provider = new CloudFilesProvider(_testIdentity);

            string filePath = Path.Combine(Directory.GetCurrentDirectory(), objectName);

            provider.CreateObjectFromFile(containerName2, filePath);

            var objects = provider.ListObjects(containerName2).ToArray();

            Assert.AreEqual(12, objects.Count());
            Assert.IsTrue(objects.Any(o => o.Name.Equals(objectName)));
            for (int i = 0; i < 11; i++)
            {
                Assert.IsTrue(objects.Any(o => o.Name.Equals(string.Format("{0}.seg{1}", objectName, i.ToString("0000")))));
            }
        }
        public void Should_Create_Object_From_File_With_Headers()
        {
            string filePath = Path.Combine(Directory.GetCurrentDirectory(), objectName);
            var etag = GetMD5Hash(filePath);
            var headers = new Dictionary<string, string> {{"ETag", etag}};
            var provider = new CloudFilesProvider(_testIdentity);
            provider.CreateObjectFromFile(containerName, filePath, objectName, headers: headers);

            var containerGetObjectsResponse = provider.ListObjects(containerName, identity: _testIdentity);
            Assert.AreEqual(objectName, containerGetObjectsResponse.Where(x => x.Name.Equals(objectName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Name);

            var objectHeadersResponse = provider.GetObjectHeaders(containerName, objectName, identity: _testIdentity);

            Assert.IsNotNull(objectHeadersResponse);
            Assert.AreEqual(etag, objectHeadersResponse.Where(x => x.Key.Equals("ETag", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value);
        }
        public void Should_Create_Object_From_Stream_With_Headers()
        {
            var etag = GetMD5Hash(objectName);
            var headers = new Dictionary<string, string> {{"ETag", etag}};
            var provider = new CloudFilesProvider(_testIdentity);
            using (var stream = File.OpenRead(objectName))
            {
                provider.CreateObject(containerName, stream, objectName, headers: headers);
            }

            var containerGetObjectsResponse = provider.ListObjects(containerName, identity: _testIdentity);
            Assert.AreEqual(objectName, containerGetObjectsResponse.Where(x => x.Name.Equals(objectName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Name);

            var objectHeadersResponse = provider.GetObjectHeaders(containerName, objectName, identity: _testIdentity);

            Assert.IsNotNull(objectHeadersResponse);
            Assert.AreEqual(etag, objectHeadersResponse.Where(x => x.Key.Equals("ETag", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value);
        }
        public void Should_Bulk_Delete_All_Objects()
        {
            var provider = new CloudFilesProvider(_testIdentity);
            provider.LargeFileBatchThreshold = 81920;

            provider.BulkDelete(provider.ListObjects(containerName2).Select(o => new KeyValuePair<string, string>(containerName2, o.Name)));

            var objects = provider.ListObjects(containerName2).ToArray();

            Assert.AreEqual(0, objects.Count());
        }
        public void Should_Delete_Object_And_All_Segments()
        {
            var provider = new CloudFilesProvider(_testIdentity);
            provider.LargeFileBatchThreshold = 81920;

            provider.DeleteObject(containerName2, objectName, deleteSegments: true);

            var objects = provider.ListObjects(containerName2).ToArray();

            Assert.AreEqual(0, objects.Count());
            Assert.IsFalse(objects.Any(o => o.Name.Equals(objectName)));
            for (int i = 0; i < 11; i++)
            {
                Assert.IsFalse(objects.Any(o => o.Name.Equals(string.Format("{0}.seg{1}", objectName, i.ToString("0000")))));
            }
        }