Exemplo n.º 1
0
        /// <summary>
        /// Uploads the given file to the specified Azure blob.
        /// </summary>
        /// <param name="azureAccount">Azure account to use.</param>
        /// <param name="blobName">Name of the blob to upload to.</param>
        /// <returns>A reference to the CloudBlockBlob.</returns>
        private static CloudBlockBlob GetPackageBlob(AzureAccount azureAccount, string blobName)
        {
            // Get connection string for our storage account.
            // TODO: Remove hard-coded storage account name.
            const string StorageAccountName = "ironcladstoretest";
            string connectionString = azureAccount.GetConnectionStringForStorageAccount(StorageAccountName);

            ////Console.WriteLine("Using connection string " + connectionString);

            // Use our storage account connection string to get our CloudStorageAccount.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            ////Console.WriteLine("Storage account URI = {0}", storageAccount.BlobEndpoint.AbsoluteUri);

            // Use our CloudStorageAccount to create a CloudBlobClient.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            ////Console.WriteLine("Blob base URI = {0}", blobClient.BaseUri);

            // Find or create our "packages" blob storage container.
            CloudBlobContainer container = blobClient.GetContainerReference("packages");
            container.CreateIfNotExists(BlobContainerPublicAccessType.Container);

            // Get the package blob we want to deploy.
            // This is a 'cspkg' file stored as a blob.
            CloudBlockBlob packageBlob = container.GetBlockBlobReference(blobName);
            return packageBlob;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets our Azure account.
        /// </summary>
        /// <returns>An Azure account.</returns>
        private static AzureAccount GetOurAzureAccount()
        {
            string subscriptionId = null;
            string certBase64Encoded = null;

            NameValueCollection appSettings = ConfigurationManager.AppSettings;
            if (appSettings != null)
            {
                subscriptionId = appSettings["Subscription Id"];
                certBase64Encoded = appSettings["Certificate (Base 64 Encoded)"];
            }

            if (string.IsNullOrEmpty(subscriptionId))
            {
                throw new ConfigurationException("Subscription Id setting missing from your AzureManager.exe.config file!");
            }

            if (string.IsNullOrEmpty(certBase64Encoded))
            {
                throw new ConfigurationException("Certificate setting missing from your AzureManager.exe.config file!");
            }

            byte[] cert = Convert.FromBase64String(certBase64Encoded);
            X509Certificate2 x509Cert = new X509Certificate2(cert);
            AzureAccount azureAccount = new AzureAccount(subscriptionId, x509Cert);

            return azureAccount;
        }