示例#1
0
        public void CloudStorageAccountWithStorageUri()
        {
            StorageUri blobEndpoint = new StorageUri(
                new Uri("http://" + AccountName + BlobService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + BlobService + EndpointSuffix));

            StorageUri queueEndpoint = new StorageUri(
                new Uri("http://" + AccountName + QueueService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + QueueService + EndpointSuffix));

            StorageUri tableEndpoint = new StorageUri(
                new Uri("http://" + AccountName + TableService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + TableService + EndpointSuffix));

            StorageUri fileEndpoint = new StorageUri(
                new Uri("http://" + AccountName + FileService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + FileService + EndpointSuffix));

#if WINDOWS_RT || ASPNET_K
            CloudStorageAccount account = CloudStorageAccount.Create(new StorageCredentials(), blobEndpoint, queueEndpoint, tableEndpoint, fileEndpoint);
#else
            CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials(), blobEndpoint, queueEndpoint, tableEndpoint, fileEndpoint);
#endif
            Assert.IsTrue(blobEndpoint.Equals(account.BlobStorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.QueueStorageUri));
            Assert.IsTrue(tableEndpoint.Equals(account.TableStorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.FileStorageUri));

            account = new CloudStorageAccount(new StorageCredentials(AccountName, TestBase.StorageCredentials.ExportBase64EncodedKey()), false);
            Assert.IsTrue(blobEndpoint.Equals(account.BlobStorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.QueueStorageUri));
            Assert.IsTrue(tableEndpoint.Equals(account.TableStorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.FileStorageUri));

            account = CloudStorageAccount.Parse(string.Format("DefaultEndpointsProtocol=http;AccountName={0};AccountKey=", AccountName));
            Assert.IsTrue(blobEndpoint.Equals(account.BlobStorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.QueueStorageUri));
            Assert.IsTrue(tableEndpoint.Equals(account.TableStorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.FileStorageUri));

            Assert.IsTrue(blobEndpoint.Equals(account.CreateCloudBlobClient().StorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.CreateCloudQueueClient().StorageUri));
            Assert.IsTrue(tableEndpoint.Equals(account.CreateCloudTableClient().StorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.CreateCloudFileClient().StorageUri));

            Assert.IsTrue(blobEndpoint.PrimaryUri.Equals(account.BlobEndpoint));
            Assert.IsTrue(queueEndpoint.PrimaryUri.Equals(account.QueueEndpoint));
            Assert.IsTrue(tableEndpoint.PrimaryUri.Equals(account.TableEndpoint));
            Assert.IsTrue(fileEndpoint.PrimaryUri.Equals(account.FileEndpoint));
        }
示例#2
0
        private CloudStorageAccount CreateStorageAccount()
        {
            CloudStorageAccount storageAccount;

            try
            {
                var creds = new StorageCredentials(sas);
                storageAccount = CloudStorageAccount.Create(creds, null, null, tableStorageUri, null);
            }
            catch (FormatException)
            {
                Debug.WriteLine("Invalid storage account information provided. Please confirm the AccountName and AccountKey are valid in the app.config file - then restart the sample.");
                throw;
            }
            catch (ArgumentException)
            {
                Debug.WriteLine("Invalid storage account information provided. Please confirm the AccountName and AccountKey are valid in the app.config file - then restart the sample.");
                throw;
            }
            return(storageAccount);
        }