|
| 1 | +#include "Stdafx.h" |
| 2 | + |
| 3 | +using namespace net::openstack::Core; |
| 4 | +using namespace net::openstack::Core::Domain; |
| 5 | +using namespace net::openstack::Core::Providers; |
| 6 | +using namespace System; |
| 7 | +using namespace System::Collections::Generic; |
| 8 | + |
| 9 | +ref class ObjectStorageProviderExamples |
| 10 | +{ |
| 11 | +public: |
| 12 | +#pragma region ListObjectsInContainer |
| 13 | + void ListObjects(IObjectStorageProvider^ provider, String^ containerName) |
| 14 | + { |
| 15 | + Console::WriteLine("Objects in container {0}", containerName); |
| 16 | + for each (ContainerObject^ containerObject in ListAllObjects(provider, containerName)) |
| 17 | + Console::WriteLine(" {0}", containerObject->Name); |
| 18 | + } |
| 19 | + |
| 20 | + static IEnumerable<ContainerObject^>^ ListAllObjects(IObjectStorageProvider^ provider, String^ containerName) |
| 21 | + { |
| 22 | + return ListAllObjects(provider, containerName, Nullable<int>(), nullptr, nullptr, false, nullptr); |
| 23 | + } |
| 24 | + |
| 25 | + static IEnumerable<ContainerObject^>^ ListAllObjects( |
| 26 | + IObjectStorageProvider^ provider, |
| 27 | + String^ containerName, |
| 28 | + Nullable<int> blockSize, |
| 29 | + String^ prefix, |
| 30 | + String^ region, |
| 31 | + bool useInternalUrl, |
| 32 | + CloudIdentity^ identity) |
| 33 | + { |
| 34 | + if (blockSize.HasValue && blockSize.Value <= 0) |
| 35 | + throw gcnew ArgumentOutOfRangeException("blockSize"); |
| 36 | + |
| 37 | + List<ContainerObject^>^ result = gcnew List<ContainerObject^>(); |
| 38 | + ContainerObject^ lastContainerObject = nullptr; |
| 39 | + do |
| 40 | + { |
| 41 | + String^ marker = lastContainerObject ? lastContainerObject->Name : nullptr; |
| 42 | + IEnumerable<ContainerObject^>^ containerObjects = |
| 43 | + provider->ListObjects(containerName, blockSize, marker, nullptr, prefix, region, useInternalUrl, identity); |
| 44 | + int previousCount = result->Count; |
| 45 | + result->AddRange(containerObjects); |
| 46 | + if (result->Count > previousCount) |
| 47 | + lastContainerObject = result[result->Count - 1]; |
| 48 | + else |
| 49 | + lastContainerObject = nullptr; |
| 50 | + } while (lastContainerObject); |
| 51 | + |
| 52 | + return result; |
| 53 | + } |
| 54 | +#pragma endregion |
| 55 | +}; |
0 commit comments