示例#1
0
 public Encoder(CloudMediaContext context, StorageCredentialsAccountAndKey storageCredentials, MediaEncoding mediaEncoding, TextWriter textWriter)
 {
     this.context = context;
     this.storageCredentials = storageCredentials;
     this.MediaEncoding = mediaEncoding;
     this.textWriter = textWriter;
 }
        // Helper function to allow Storage Client 1.7 (Microsoft.WindowsAzure.StorageClient) to utilize this class.
        // Remove this function if only using Storage Client 2.0 (Microsoft.WindowsAzure.Storage).
        public void DownloadBlobAsync(Microsoft.WindowsAzure.StorageClient.CloudBlob blob, string LocalFile)
        {
            Microsoft.WindowsAzure.StorageCredentialsAccountAndKey account = blob.ServiceClient.Credentials as Microsoft.WindowsAzure.StorageCredentialsAccountAndKey;
            ICloudBlob blob2 = new Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob(blob.Attributes.Uri, new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(blob.ServiceClient.Credentials.AccountName, account.Credentials.ExportBase64EncodedKey()));

            DownloadBlobAsync(blob2, LocalFile);
        }
        public static Uri UploadFile(string storageName, string storageKey, string filePath)
        {
            var baseAddress = string.Format(CultureInfo.InvariantCulture, ConfigurationConstants.BlobEndpointTemplate, storageName);
            var credentials = new StorageCredentialsAccountAndKey(storageName, storageKey);
            var client = new CloudBlobClient(baseAddress, credentials);

            string containerName = "mydeployments";
            string blobName = string.Format(
                CultureInfo.InvariantCulture,
                "{0}_{1}",
                DateTime.UtcNow.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture),
                Path.GetFileName(filePath));

            CloudBlobContainer container = client.GetContainerReference(containerName);
            container.CreateIfNotExist();
            CloudBlob blob = container.GetBlobReference(blobName);

            // blob.UploadFile(filePath);
            UploadBlobStream(blob, filePath);

            return new Uri(
                string.Format(
                    CultureInfo.InvariantCulture,
                    "{0}{1}{2}{3}",
                    client.BaseUri,
                    containerName,
                    client.DefaultDelimiter,
                    blobName));
        }
 public virtual CloudStorageAccount GetAccount()
 {
     var cred = new Microsoft.WindowsAzure.StorageCredentialsAccountAndKey("cloud302blobby",
                                                                           "PDyi8E91Txm+NqS7yUByQkQ933Tfp6/tbgvVG0Z4zvrIrgnG0P5J3bf9hMm7EZ9Ll6R2ol70UjjHU3rI9EO8uA==");
     var account = new Microsoft.WindowsAzure.CloudStorageAccount(cred, true);
     return account;
 }
        /// <summary>
        /// Connect to an Azure subscription and upload a package to blob storage.
        /// </summary>
        protected override void AzureExecute()
        {
            string storageKey = this.StorageKeys.Get(this.ActivityContext).Primary;
            string storageName = this.StorageServiceName.Get(this.ActivityContext);
            string filePath = this.LocalPackagePath.Get(this.ActivityContext);

            var baseAddress = string.Format(CultureInfo.InvariantCulture, ConfigurationConstants.BlobEndpointTemplate, storageName);
            var credentials = new StorageCredentialsAccountAndKey(storageName, storageKey);
            var client = new CloudBlobClient(baseAddress, credentials);

            const string ContainerName = "mydeployments";
            string blobName = string.Format(
                CultureInfo.InvariantCulture,
                "{0}_{1}",
                DateTime.UtcNow.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture),
                Path.GetFileName(filePath));

            CloudBlobContainer container = client.GetContainerReference(ContainerName);
            container.CreateIfNotExist();
            CloudBlob blob = container.GetBlobReference(blobName);

            UploadBlobStream(blob, filePath);

            this.PackageUrl.Set(this.ActivityContext, string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}", client.BaseUri, ContainerName, client.DefaultDelimiter, blobName));
        }
 public AzureBlobClient(Uri endpoint, string accountName, string accountKey, int timeoutInMinutes = 30, int parallelOperationThreadCount = 1)
 {
     var credentials = new StorageCredentialsAccountAndKey(accountName, accountKey);
     blobClient = new CloudBlobClient(endpoint, credentials);
     blobClient.Timeout = new TimeSpan(0, timeoutInMinutes, 0);
     blobClient.ParallelOperationThreadCount = parallelOperationThreadCount;
 }
示例#7
0
 public static CloudStorageAccount GetStorageAccount()
 {
     StorageCredentials crendentials = new StorageCredentialsAccountAndKey(AzureBlobServiceSettings.Instance.AccountName
         , AzureBlobServiceSettings.Instance.AccountKey);
     Uri blobEndpoint = new Uri(AzureBlobServiceSettings.Instance.Endpoint);
     CloudStorageAccount storageAccount = new CloudStorageAccount(crendentials, blobEndpoint, null, null);
     return storageAccount;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CloudStorageAccount"/> class using the specified
 /// account credentials and the default service endpoints.
 /// </summary>
 /// <param name="storageCredentialsAccountAndKey">An object of type <see cref="StorageCredentialsAccountAndKey"/> that
 /// specifies the account name and account key for the storage account.</param>
 /// <param name="useHttps"><c>True</c> to use HTTPS to connect to storage service endpoints; otherwise, <c>false</c>.</param>
 public CloudStorageAccount(StorageCredentialsAccountAndKey storageCredentialsAccountAndKey, bool useHttps)
     : this(
         storageCredentialsAccountAndKey,
         new Uri(GetDefaultBlobEndpoint(useHttps ? "https" : "http", storageCredentialsAccountAndKey.AccountName)),
         new Uri(GetDefaultQueueEndpoint(useHttps ? "https" : "http", storageCredentialsAccountAndKey.AccountName)),
         new Uri(GetDefaultTableEndpoint(useHttps ? "https" : "http", storageCredentialsAccountAndKey.AccountName)))
 {
 }
示例#9
0
 public static CloudStorageAccount GetStorageAccount()
 {
     StorageCredentials crendentials = new StorageCredentialsAccountAndKey(SiteOnAzureTableSettings.Instance.AccountName
         , SiteOnAzureTableSettings.Instance.AccountKey);
     Uri tableEndpoint = new Uri(SiteOnAzureTableSettings.Instance.Endpoint);
     CloudStorageAccount storageAccount = new CloudStorageAccount(crendentials, null, null, tableEndpoint);
     return storageAccount;
 }
        public virtual CloudStorageAccount GetAccount()
        {
            var cred = new Microsoft.WindowsAzure.StorageCredentialsAccountAndKey("cloud302blobby",
                                                                                  "PDyi8E91Txm+NqS7yUByQkQ933Tfp6/tbgvVG0Z4zvrIrgnG0P5J3bf9hMm7EZ9Ll6R2ol70UjjHU3rI9EO8uA==");
            var account = new Microsoft.WindowsAzure.CloudStorageAccount(cred, true);

            return(account);
        }
示例#11
0
 private static void LoadConfiguration()
 {
     string accountName = ConfigManager.AppSettings["AccountName"];
     string accountSharedKey = ConfigManager.AppSettings["AccountSharedKey"];
     tableBaseUri = ConfigManager.AppSettings["TableStorageEndpoint"];
     queueBaseUri = ConfigManager.AppSettings["QueueStorageEndpoint"];
     blobBaseUri = ConfigManager.AppSettings["BlobStorageEndpoint"];
     credentials = new StorageCredentialsAccountAndKey(accountName, accountSharedKey);
 }
        public TableFactory(string accountName, string key)
        {
            //Specify storage credentials.
            StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey(accountName, key);

            //Create a reference to your storage account, passing in your credentials.
            CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true);
            _tableClient = GetTableClient(storageAccount);
        }
示例#13
0
        private static void DeleteBlob(string packageUrl, string storageAccountName, string storageAccountKey)
        {
            OurTrace.TraceInfo(string.Format("Deleting blob {0}", packageUrl));

            var packageUri = new Uri(packageUrl);
            var baseAddress = packageUri.GetComponents(UriComponents.SchemeAndServer, UriFormat.UriEscaped);
            var credentials = new StorageCredentialsAccountAndKey(storageAccountName, storageAccountKey);

            var cloudBlobClient = new CloudBlobClient(baseAddress, credentials);
            var blobRef = cloudBlobClient.GetBlockBlobReference(packageUrl);
            blobRef.DeleteIfExists();
        }
示例#14
0
		public static void DeletePackageFromBlob(IServiceManagement channel, string storageName, string subscriptionId, Uri packageUri)
		{
			StorageService storageKeys = channel.GetStorageKeys(subscriptionId, storageName);
			string primary = storageKeys.StorageServiceKeys.Primary;
			storageKeys = channel.GetStorageService(subscriptionId, storageName);
			EndpointList endpoints = storageKeys.StorageServiceProperties.Endpoints;
			string str = ((List<string>)endpoints).Find((string p) => p.Contains(".blob."));
			StorageCredentialsAccountAndKey storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey(storageName, primary);
			CloudBlobClient cloudBlobClient = new CloudBlobClient(str, storageCredentialsAccountAndKey);
			CloudBlob blobReference = cloudBlobClient.GetBlobReference(packageUri.AbsoluteUri);
			blobReference.DeleteIfExists();
		}
示例#15
0
        private static AssetHelper GetAssetHelper(TextWriter textWriter)
        {
            textWriter.WriteLine("Instantiating the classes required to ingest, encode and locate a video file.");
            textWriter.WriteLine();

            var cloudMediaContext = new CloudMediaContext(Config.MEDIA_ACCOUNT_NAME, Config.MEDIA_ACCESS_KEY);
            var restServices = new RestServices(Config.MEDIA_ACCOUNT_NAME, Config.MEDIA_ACCESS_KEY);
            var storageCredentials = new StorageCredentialsAccountAndKey(Config.STORAGE_ACCOUNT_NAME, Config.STORAGE_ACCESS_KEY);
            var encoder = new Encoder(cloudMediaContext, storageCredentials, MediaEncodings.H264_HD_720p_Vbr, textWriter);

            return new AssetHelper(cloudMediaContext, encoder, restServices, textWriter);
        }
示例#16
0
        public static void Initialize(string account, string key)
        {
            Uri blobUri = new Uri(string.Format("http://{0}.blob.core.windows.net", account));
            Uri queueUri = new Uri(string.Format("http://{0}.queue.core.windows.net", account));
            Uri tableUri = new Uri(string.Format("http://{0}.table.core.windows.net", account));

            s_credentials = new StorageCredentialsAccountAndKey(account, key);
            s_storageAccount = new CloudStorageAccount(s_credentials, blobUri, queueUri, tableUri);

            s_blobClient = s_storageAccount.CreateCloudBlobClient();
            s_tableClient = s_storageAccount.CreateCloudTableClient();
            s_queueClient = s_storageAccount.CreateCloudQueueClient();
        }
示例#17
0
        public BlobFactory(string azureAccountName, string azureKey)
        {
            // initialize Azure Account
            StorageCredentialsAccountAndKey storageKey = new StorageCredentialsAccountAndKey(azureAccountName, azureKey);
            CloudStorageAccount azureAccount = new CloudStorageAccount(storageKey, true);

            // Create blob containers
            CloudBlobClient blobClient = azureAccount.CreateCloudBlobClient();

            userContainer = blobClient.GetContainerReference("user");
            accountContainer = blobClient.GetContainerReference("account");
            listContainer = blobClient.GetContainerReference("list");
            msgContainer = blobClient.GetContainerReference("msg");
        }
        public void DeletePackageBlob(string csPkgFileLocation,
                                      string blobUrl,
                                      string storageAccountName,
                                      string storageAccountKey)
        {
            StorageCredentials storageCredentails;
            CloudBlobClient blobClient;
            CloudBlobContainer packageContainer;

            storageCredentails = new StorageCredentialsAccountAndKey(storageAccountName, storageAccountKey);
            blobClient = new CloudBlobClient(blobUrl, storageCredentails);

            packageContainer = blobClient.GetContainerReference(_cspkgBlobContainerName);
            packageContainer.Delete();
        }
        private static void DownloadVHDFromCloud(Config config)
        {
            StorageCredentialsAccountAndKey creds =
                   new StorageCredentialsAccountAndKey(config.Account, config.Key);

            CloudBlobClient blobStorage = new CloudBlobClient(config.AccountUrl, creds);
            blobStorage.ReadAheadInBytes = 0;

            CloudBlobContainer container = blobStorage.GetContainerReference(config.Container);
            CloudPageBlob pageBlob = container.GetPageBlobReference(config.Blob);

            // Get the length of the blob
            pageBlob.FetchAttributes();
            long vhdLength = pageBlob.Properties.Length;
            long totalDownloaded = 0;
            Console.WriteLine("Vhd size:  " + Megabytes(vhdLength));

            // Create a new local file to write into
            FileStream fileStream = new FileStream(config.Vhd.FullName, FileMode.Create, FileAccess.Write);
            fileStream.SetLength(vhdLength);

            // Download the valid ranges of the blob, and write them to the file
            IEnumerable<PageRange> pageRanges = pageBlob.GetPageRanges();
            BlobStream blobStream = pageBlob.OpenRead();

            foreach (PageRange range in pageRanges)
            {
                // EndOffset is inclusive... so need to add 1
                int rangeSize = (int)(range.EndOffset + 1 - range.StartOffset);

                // Chop range into 4MB chucks, if needed
                for (int subOffset = 0; subOffset < rangeSize; subOffset += FourMegabyteAsBytes)
                {
                    int subRangeSize = Math.Min(rangeSize - subOffset, FourMegabyteAsBytes);
                    blobStream.Seek(range.StartOffset + subOffset, SeekOrigin.Begin);
                    fileStream.Seek(range.StartOffset + subOffset, SeekOrigin.Begin);

                    Console.WriteLine("Range: ~" + Megabytes(range.StartOffset + subOffset)
                                      + " + " + PrintSize(subRangeSize));
                    byte[] buffer = new byte[subRangeSize];

                    blobStream.Read(buffer, 0, subRangeSize);
                    fileStream.Write(buffer, 0, subRangeSize);
                    totalDownloaded += subRangeSize;
                }
            }
            Console.WriteLine("Downloaded " + Megabytes(totalDownloaded) + " of " + Megabytes(vhdLength));
        }
示例#20
0
文件: Disks.cs 项目: nickchal/pash
		public static void RemoveVHD(IServiceManagement channel, string subscriptionId, Uri mediaLink)
		{
			StorageService storageKeys;
			char[] chrArray = new char[1];
			chrArray[0] = '.';
			string str = mediaLink.Host.Split(chrArray)[0];
			string components = mediaLink.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
			using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)channel))
			{
				storageKeys = channel.GetStorageKeys(subscriptionId, str);
			}
			StorageCredentialsAccountAndKey storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey(str, storageKeys.StorageServiceKeys.Primary);
			CloudBlobClient cloudBlobClient = new CloudBlobClient(components, storageCredentialsAccountAndKey);
			CloudBlob blobReference = cloudBlobClient.GetBlobReference(mediaLink.AbsoluteUri);
			blobReference.DeleteIfExists();
		}
        static void Main(string[] args)
        {
            var accountAndKey = new StorageCredentialsAccountAndKey("account", "key");
            string location = @"D:\";

            var cloudStorageAccount = new Microsoft.WindowsAzure.CloudStorageAccount(accountAndKey, true);

            var client = CloudStorageAccountStorageClientExtensions.CreateCloudBlobClient(cloudStorageAccount);
            client.RetryPolicy = RetryPolicies.Retry(20, TimeSpan.Zero);

            var containerReference = client.GetContainerReference("container");

            var blobDirectory = client.GetBlobDirectoryReference(containerReference.Uri.AbsoluteUri);

            var blobs = blobDirectory.ListBlobs();

            foreach (var b in blobs)
            {
                string filePath = Path.Combine(location, System.Web.HttpUtility.UrlDecode(b.Uri.Segments[2]));

                var blobReference = client.GetBlobReference(b.Uri.AbsoluteUri);

                if (!File.Exists(filePath))
                {
                    using (FileStream fs = new FileStream(filePath, FileMode.Create))
                    {
                        blobReference.DownloadToStream(fs);
                    }
                }
                else
                {
                    blobReference.FetchAttributes();

                    var file = new FileInfo(filePath);

                    if (blobReference.Properties.Length != file.Length)
                    {
                        File.Delete(filePath);
                        using (FileStream fs = new FileStream(filePath, FileMode.Create))
                        {
                            blobReference.DownloadToStream(fs);
                        }
                    }
                }
            }
        }
示例#22
0
        protected static Uri UploadFile(String path, TimeSpan timeout)
        {
            Console.WriteLine("Uploading " + path + " to " + StorageContainer + " Blob Storage Container");
            StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey(StorageAccount, StorageKey);
            string accountUri = string.Format(AzureBlobUriFormat , StorageAccount);
            CloudBlobClient blobStorage = new CloudBlobClient(accountUri, credentials);
            blobStorage.SingleBlobUploadThresholdInBytes = SingleBlobUploadThresholdInBytes;
            CloudBlobContainer container = blobStorage.GetContainerReference(StorageContainer);
            //TODO: Support container properties
            container.CreateIfNotExist();
            CloudBlob blob = container.GetBlobReference(Path.GetFileName(path));
            BlobRequestOptions options = new BlobRequestOptions();
            options.Timeout = timeout;

            blob.UploadFile(path, options);
            return blob.Uri;
        }
示例#23
0
        public void WriteData(string container, string blobName, string data)
        {
            StorageCredentialsAccountAndKey creds = new StorageCredentialsAccountAndKey(account, key);
            CloudBlobClient blobStorage = new CloudBlobClient(url, creds);

            // get blob container
            CloudBlobContainer blobContainer = blobStorage.GetContainerReference(container);
            if (blobContainer.CreateIfNotExist())
            {
                // configure container for public access
                var permissions = blobContainer.GetPermissions();
                permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                blobContainer.SetPermissions(permissions);
            }

            CloudBlockBlob blob = blobStorage.GetBlockBlobReference(container + "/" + blobName);
            blob.UploadText(data);
        }
示例#24
0
        public static void WriteDebugBlob(string blobName, string message)
        {
            string destinationAccountName = "";
            string destinationAccessKey = "";
            string destinationContainer = "";

            StorageCredentialsAccountAndKey accountAndKey = new StorageCredentialsAccountAndKey(destinationAccountName, destinationAccessKey);
            CloudStorageAccount account = new CloudStorageAccount(accountAndKey, false);
            CloudBlobClient client = account.CreateCloudBlobClient();
            CloudBlobContainer container = client.GetContainerReference(destinationContainer);

            CloudBlob blob = container.GetBlobReference(blobName);
            Stream stream = blob.OpenWrite();
            using (TextWriter writer = new StreamWriter(stream))
            {
                writer.Write("{0} {1}", DateTime.UtcNow, message);
            }
        }
示例#25
0
        public static CloudQueue InitializeQueue(string queueName)
        {
            CloudQueueClient queueStorage = null;

            if (AzureStorageKey == null)
            {
                var clientStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
                queueStorage = new CloudQueueClient(clientStorageAccount.QueueEndpoint.AbsoluteUri, clientStorageAccount.Credentials);
            }
            else
            {
                byte[] key = Convert.FromBase64String(AzureStorageKey);
                var creds = new StorageCredentialsAccountAndKey(AccountName, key);
                queueStorage = new CloudQueueClient(String.Format("http://{0}.queue.core.windows.net", AccountName), creds);
            }

            CloudQueue queue = queueStorage.GetQueueReference(queueName);
            queue.CreateIfNotExist();
            return queue;
        }
示例#26
0
		private static Uri UploadFile(string storageName, string storageKey, string blobStorageEndpoint, string filePath)
		{
			StorageCredentialsAccountAndKey storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey(storageName, storageKey);
			CloudBlobClient cloudBlobClient = new CloudBlobClient(blobStorageEndpoint, storageCredentialsAccountAndKey);
			object[] str = new object[2];
			DateTime utcNow = DateTime.UtcNow;
			str[0] = utcNow.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture);
			str[1] = Path.GetFileName(filePath);
			string str1 = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", str);
			CloudBlobContainer containerReference = cloudBlobClient.GetContainerReference("mydeployments");
			containerReference.CreateIfNotExist();
			CloudBlob blobReference = containerReference.GetBlobReference(str1);
			AzureBlob.UploadBlobStream(blobReference, filePath);
			object[] baseUri = new object[4];
			baseUri[0] = cloudBlobClient.BaseUri;
			baseUri[1] = "mydeployments";
			baseUri[2] = cloudBlobClient.DefaultDelimiter;
			baseUri[3] = str1;
			return new Uri(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}", baseUri));
		}
示例#27
0
        /// <summary>
        /// Uploads a file to azure store.
        /// </summary>
        /// <param name="storageName">Store which file will be uploaded to</param>
        /// <param name="storageKey">Store access key</param>
        /// <param name="filePath">Path to file which will be uploaded</param>
        /// <returns>Uri which holds locates the uploaded file</returns>
        /// <remarks>The uploaded file name will be guid</remarks>
        public static Uri UploadFile(string storageName, string storageKey, string filePath)
        {
            var baseAddress = string.Format(CultureInfo.InvariantCulture, AzureBlob.BlobEndpointTemplate, storageName);
            var credentials = new StorageCredentialsAccountAndKey(storageName, storageKey);
            var client = new CloudBlobClient(baseAddress, credentials);
            string blobName = Guid.NewGuid().ToString();

            CloudBlobContainer container = client.GetContainerReference(containerName);
            container.CreateIfNotExist();
            CloudBlob blob = container.GetBlobReference(blobName);
            UploadBlobStream(blob, filePath);

            return new Uri(
                string.Format(
                    CultureInfo.InvariantCulture,
                    "{0}{1}{2}{3}",
                    client.BaseUri,
                    containerName,
                    client.DefaultDelimiter,
                    blobName));
        }
示例#28
0
		static void Main()
		{
			var accountName = ConfigurationManager.AppSettings["Cloud Diagnostics Storage Account Name"];
			Console.WriteLine(string.Format("Cloud Diagnostics Storage Account Name: {0}", accountName));
			var accountKey = ConfigurationManager.AppSettings["Cloud Diagnostics Storage Account Key"];
			Console.WriteLine(string.Format("Cloud Diagnostics Storage Account Key: {0}", new string('*', accountKey.Length)));

			var storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey(accountName, accountKey);
			var storageAccount = new CloudStorageAccount(storageCredentialsAccountAndKey, true);

			Console.WriteLine(string.Format("Deployment ID: "));
			var deploymentID = Console.ReadLine();

			var deploymentDiagnosticManager = new DeploymentDiagnosticManager(storageAccount, deploymentID);

			string roleInstanceName;
			Guid guid;

			var roleNames = deploymentDiagnosticManager.GetRoleNames();
			foreach (var roleName in roleNames)
			{
				Console.WriteLine(string.Format("Role Name: {0}", roleName));

				foreach (var roleInstanceDiagnosticManager in deploymentDiagnosticManager.GetRoleInstanceDiagnosticManagersForRole(roleName))
				{
					roleInstanceName = roleInstanceDiagnosticManager.RoleInstanceId;
					Console.WriteLine(string.Format("Role Instance Name: {0}", roleInstanceName));

					Console.WriteLine("Calling to transfer logs.");
					guid = Transfer(roleInstanceDiagnosticManager, DataBufferName.Logs);
					Console.WriteLine(string.Format("Logs transfer '{0}'", guid));
					Console.WriteLine("Calling to transfer directories.");
					guid = Transfer(roleInstanceDiagnosticManager, DataBufferName.Directories);
					Console.WriteLine(string.Format("Directories transfer '{0}'", guid));
				}
			}

			Console.WriteLine("Hit any key to end...");
			Console.ReadKey();
		}
        public string StoreDeploymentPackageInBlob(string csPkgFileLocation,
                                                   string blobUrl,
                                                   string storageAccountName,
                                                   string storageAccountKey)
        {
            string fileName;
            bool containerCreated = false;
            StorageCredentials storageCredentails;
            CloudBlobClient blobClient;
            CloudBlobContainer packageContainer;
            CloudBlob deploymentBlob;

            storageCredentails = new StorageCredentialsAccountAndKey(storageAccountName, storageAccountKey);
            blobClient = new CloudBlobClient(blobUrl, storageCredentails);

            packageContainer = blobClient.GetContainerReference(_cspkgBlobContainerName);

            try { containerCreated = packageContainer.CreateIfNotExist(); }
            catch { };

            if (containerCreated == true)
            {
                BlobContainerPermissions permissions = new BlobContainerPermissions();
                permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                packageContainer.SetPermissions(permissions);
            }

            //Upload a file.
            Console.WriteLine("Uploading Deployment package - start");
            fileName = Path.GetFileName(csPkgFileLocation);
            deploymentBlob = packageContainer.GetBlobReference(fileName);

            using (FileStream fs = new FileStream(csPkgFileLocation, FileMode.Open))
            {
                deploymentBlob.UploadFromStream(fs);
            }
            Console.WriteLine("Uploading Deployment package - end");
            return String.Format(deploymentBlob.Uri.ToString());
        }
示例#30
0
 internal static void CheckAllowInsecureEndpoints(bool allowInsecureRemoteEndpoints, StorageCredentialsAccountAndKey info, Uri baseUri)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     if (allowInsecureRemoteEndpoints)
     {
         return;
     }
     if (baseUri == null || string.IsNullOrEmpty(baseUri.Scheme))
     {
         throw new SecurityException("allowInsecureRemoteEndpoints is set to false (default setting) but the endpoint URL seems to be empty or there is no URL scheme." +
                                     "Please configure the provider to use an https enpoint for the storage endpoint or " +
                                     "explicitly set the configuration option allowInsecureRemoteEndpoints to true.");
     }
     if (baseUri.Scheme.ToUpper(CultureInfo.InvariantCulture) == Uri.UriSchemeHttps.ToUpper(CultureInfo.InvariantCulture))
     {
         return;
     }
     if (baseUri.IsLoopback)
     {
         return;
     }
     throw new SecurityException("The provider is configured with allowInsecureRemoteEndpoints set to false (default setting) but the endpoint for " +
                                 "the storage system does not seem to be an https or local endpoint. " +
                                 "Please configure the provider to use an https enpoint for the storage endpoint or " +
                                 "explicitly set the configuration option allowInsecureRemoteEndpoints to true.");
 }
示例#31
0
 internal BlobProvider(StorageCredentialsAccountAndKey info, Uri baseUri, string containerName)
 {
     _containerName = containerName;
     _client = new CloudBlobClient(baseUri.ToString(), info);
 }
 /// <summary>Initializes a new instance of the <see cref="CloudStorageAccount"/> class using the specified account credentials and the default service endpoints.</summary>
 /// <param name="storageCredentialsAccountAndKey">An object of type <see cref="StorageCredentialsAccountAndKey"/> that specifies the account name and account key for the storage account. </param>
 /// <param name="useHttps"><c>True</c> to use HTTPS to connect to storage service endpoints; otherwise, <c>false</c> . </param>
 public CloudStorageAccount(StorageCredentialsAccountAndKey storageCredentialsAccountAndKey, bool useHttps)
     : this(storageCredentialsAccountAndKey,
         new Uri(
             GetDefaultBlobEndpoint(useHttps ? "https" : "http", storageCredentialsAccountAndKey.AccountName)),
         new Uri(
             GetDefaultQueueEndpoint(useHttps ? "https" : "http", storageCredentialsAccountAndKey.AccountName)),
         new Uri(
             GetDefaultTableEndpoint(useHttps ? "https" : "http", storageCredentialsAccountAndKey.AccountName)))
 {
 }
示例#33
0
        static int Main(string[] args)
        {
            // Parse Options
            var options = new Options();
            if (!CommandLineParser.Default.ParseArguments(args, options))
                return 1;

            // Configure Logging
            ConfigureLogging(options.Brief);

            // Fetch References
            var credentials = new StorageCredentialsAccountAndKey(options.Account, options.Key);
            var account = new CloudStorageAccount(credentials, true);
            var client = account.CreateCloudBlobClient();
            var container = client.GetContainerReference(options.Container);

            // Fetch API Version?
            if (options.GetApiVersion) {
                var properties = client.GetServiceProperties();
                Log.Info("Service Properties:");
                Log.Info(string.Format("Default Service (API) Version: {0}", properties.DefaultServiceVersion));
                return 0;
            }

            // Set API Version?
            if (!string.IsNullOrEmpty(options.SetApiVersion)) {
                var properties = client.GetServiceProperties();
                var version = options.SetApiVersion == "reset" ? null : options.SetApiVersion;
                Log.Info(string.Format("Updating API Version from {0} to {1}", properties.DefaultServiceVersion, version));
                properties.DefaultServiceVersion = version;
                client.SetServiceProperties(properties);
                Log.Info("Updated Ok");
                return 0;
            }

            // Source is Required
            if (options.Sources == null) {
                Console.WriteLine(options.GetUsage());
                return 0;
            }

            // Download?
            if (options.Download) {
                var downloads = options.Sources.ToList();
                Log.Info(string.Format("Downloading {0} file(s)", downloads.Count));

                foreach (var download in downloads) {
                    var blob = container.GetBlobReference(download);
                    blob.FetchAttributes();

                    Log.Info(string.Format("Found Blob: {0}", blob.Uri));

                    // Does this file exist locally?
                    var localFilename = Path.GetFileName(blob.Name);
                    if (localFilename == null)
                        throw new ArgumentException(string.Format("Could not resolve Blob name: {0}", blob.Uri));

                    // Prepend Directory if provided
                    var saveDirectory = options.Directory;
                    if (!string.IsNullOrEmpty(saveDirectory))
                        localFilename = Path.Combine(saveDirectory, localFilename);

                    // Ignore existing files if required
                    if (!options.Force && File.Exists(localFilename)) {
                        Log.Warn(string.Format("Local file {0} already exists; skipping download", localFilename));
                        continue;
                    }

                    // Create directory if required
                    if (!string.IsNullOrEmpty(saveDirectory) && !Directory.Exists(saveDirectory))
                        Directory.CreateDirectory(saveDirectory);

                    // Download Blob
                    blob.DownloadToFile(localFilename);
                    Log.Info(string.Format("Saved Blob: {0} ({1} bytes)", localFilename, blob.Attributes.Properties.Length));
                }

                return 0;
            }

            // Resolve Sources
            var files = new List<FileInfo>();
            foreach (var file in options.Sources) {
                if (Path.IsPathRooted(file))
                    files.Add(new FileInfo(file));
                else
                    files.AddRange(Directory.GetFiles(Environment.CurrentDirectory, file).Select(x => new FileInfo(x)));
            }

            // Perform Upload
            Log.Info(string.Format("Uploading {0} file(s)", files.Count));
            foreach(var fileInfo in files) {
                // Calculate Paths
                var directory = fileInfo.Directory;
                if (directory == null)
                    throw new ArgumentException(string.Format("Invalid directory for file: {0}", fileInfo.FullName));

                var uploadPath = Path.Combine(options.Directory, fileInfo.Name).Replace("\\", "/");

                // If our upload Directory has an extension, then we mean to write out this file with that exact path
                if (Path.HasExtension(options.Directory)) {
                    if (files.Count > 1)
                        throw new ArgumentException("Cannot specify an exact filename to upload to (-d) with multiple files");

                    uploadPath = options.Directory;
                }

                var blob = container.GetBlobReference(uploadPath);

                // Blob existance check?
                if (!options.Force) {
                    try {
                        // Fetch Attributes (and checks to see if Blob exists)
                        blob.FetchAttributes();

                        // If this succeeded, our Blob already exists
                        throw new ArgumentException(string.Format("Blob already exists: {0}", uploadPath));
                    } catch (StorageClientException) {
                        // Ignored - Blob does not exist
                    }
                }

                Log.Info(string.Format("Uploading {0} to {1}", fileInfo, uploadPath));
                blob.UploadFile(fileInfo.FullName);
            }

            Log.Info("Finished uploading");
            return 0;
        }