当前位置: 首页>>代码示例>>C#>>正文


C# CloudFilesProvider.GetObject方法代码示例

本文整理汇总了C#中net.openstack.Providers.Rackspace.CloudFilesProvider.GetObject方法的典型用法代码示例。如果您正苦于以下问题:C# CloudFilesProvider.GetObject方法的具体用法?C# CloudFilesProvider.GetObject怎么用?C# CloudFilesProvider.GetObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.openstack.Providers.Rackspace.CloudFilesProvider的用法示例。


在下文中一共展示了CloudFilesProvider.GetObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestDeleteObject

        public void TestDeleteObject()
        {
            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);
            }

            string actualData = ReadAllObjectText(provider, containerName, objectName, Encoding.UTF8);
            Assert.AreEqual(fileData, actualData);

            provider.DeleteObject(containerName, objectName);

            try
            {
                using (MemoryStream downloadStream = new MemoryStream())
                {
                    provider.GetObject(containerName, objectName, downloadStream);
                }

                Assert.Fail("Expected an exception (object should not exist)");
            }
            catch (ResponseException)
            {
            }

            /* Cleanup
             */
            provider.DeleteContainer(containerName, deleteObjects: true);
        }
开发者ID:nick-o,项目名称:openstack.net,代码行数:38,代码来源:UserObjectStorageTests.cs

示例2: TestCreateLargeObject

        public void TestCreateLargeObject()
        {
            IObjectStorageProvider provider =
                new CloudFilesProvider(Bootstrapper.Settings.TestIdentity)
                {
                    LargeFileBatchThreshold = 81920
                };

            string containerName = TestContainerPrefix + Path.GetRandomFileName();
            string sourceFileName = "DarkKnightRises.jpg";
            byte[] content = File.ReadAllBytes("DarkKnightRises.jpg");

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

            ProgressMonitor progressMonitor = new ProgressMonitor(content.Length);
            provider.CreateObjectFromFile(containerName, sourceFileName, progressUpdated: progressMonitor.Updated);
            Assert.IsTrue(progressMonitor.IsComplete, "Failed to notify progress monitor callback of status update.");

            using (MemoryStream downloadStream = new MemoryStream())
            {
                provider.GetObject(containerName, sourceFileName, downloadStream);
                Assert.AreEqual(content.Length, GetContainerObjectSize(provider, containerName, sourceFileName));

                downloadStream.Position = 0;
                byte[] actualData = new byte[downloadStream.Length];
                downloadStream.Read(actualData, 0, actualData.Length);
                Assert.AreEqual(content.Length, actualData.Length);
                using (MD5 md5 = MD5.Create())
                {
                    byte[] contentMd5 = md5.ComputeHash(content);
                    byte[] actualMd5 = md5.ComputeHash(actualData);
                    Assert.AreEqual(BitConverter.ToString(contentMd5), BitConverter.ToString(actualMd5));
                }
            }

            /* Cleanup
             */
            provider.DeleteContainer(containerName, deleteObjects: true);
        }
开发者ID:nick-o,项目名称:openstack.net,代码行数:40,代码来源:UserObjectStorageTests.cs


注:本文中的net.openstack.Providers.Rackspace.CloudFilesProvider.GetObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。