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_Get_Object_And_Save_To_File_Without_Headers_And_Verify_Etag()
 {
     string filePath = Path.Combine(Directory.GetCurrentDirectory(), objectName);
     string fileName = Path.GetFileName(filePath);
     var headers = new Dictionary<string, string>();
     var provider = new CloudFilesProvider();
     provider.GetObjectSaveToFile(containerName, saveDirectory, fileName, null, 65536, null, null, true, identity: _testIdentity);
 }
Exemplo n.º 3
0
 public void Should_Get_Object_And_Save_To_File_Without_Headers_And_Verify_Etag()
 {
     var provider = new CloudFilesProvider(_testIdentity);
     provider.GetObjectSaveToFile(containerName, Directory.GetCurrentDirectory(), objectName, saveFileNane2, verifyEtag: true);
 }
        public void TestGetObjectSaveToFile()
        {
            IObjectStorageProvider provider = new CloudFilesProvider(Bootstrapper.Settings.TestIdentity);
            string containerName = TestContainerPrefix + Path.GetRandomFileName();
            string objectName = Path.GetRandomFileName();
            // another random name counts as random content
            string fileData = Path.GetRandomFileName();

            ObjectStore containerResult = provider.CreateContainer(containerName);
            Assert.AreEqual(ObjectStore.ContainerCreated, containerResult);

            using (MemoryStream uploadStream = new MemoryStream(Encoding.UTF8.GetBytes(fileData)))
            {
                provider.CreateObject(containerName, uploadStream, objectName);
            }

            try
            {
                provider.GetObjectSaveToFile(containerName, Path.GetTempPath(), objectName);
                Assert.AreEqual(fileData, File.ReadAllText(Path.Combine(Path.GetTempPath(), objectName), Encoding.UTF8));

                // it's ok to download the same file twice
                ProgressMonitor progressMonitor = new ProgressMonitor(GetContainerObjectSize(provider, containerName, objectName));
                provider.GetObjectSaveToFile(containerName, Path.GetTempPath(), objectName, progressUpdated: progressMonitor.Updated);
                Assert.IsTrue(progressMonitor.IsComplete, "Failed to notify progress monitor callback of status update.");
            }
            finally
            {
                File.Delete(Path.Combine(Path.GetTempPath(), objectName));
            }

            string tempFileName = Path.GetRandomFileName();
            try
            {
                provider.GetObjectSaveToFile(containerName, Path.GetTempPath(), objectName, tempFileName);
                Assert.AreEqual(fileData, File.ReadAllText(Path.Combine(Path.GetTempPath(), tempFileName), Encoding.UTF8));

                // it's ok to download the same file twice
                ProgressMonitor progressMonitor = new ProgressMonitor(GetContainerObjectSize(provider, containerName, objectName));
                provider.GetObjectSaveToFile(containerName, Path.GetTempPath(), objectName, progressUpdated: progressMonitor.Updated);
                Assert.IsTrue(progressMonitor.IsComplete, "Failed to notify progress monitor callback of status update.");
            }
            finally
            {
                File.Delete(Path.Combine(Path.GetTempPath(), tempFileName));
            }

            /* Cleanup
             */
            provider.DeleteContainer(containerName, deleteObjects: true);
        }