コード例 #1
0
        private static void SetCurrentCloudStorageAccount(IServiceManagement channel, SubscriptionData subscriptionData)
        {
            CloudStorageAccount currentStorage = null;

            using (new OperationContextScope((IContextChannel)channel))
            {
                var storageService = channel.GetStorageService(
                    subscriptionData.SubscriptionId,
                    subscriptionData.CurrentStorageAccount);
                var storageServiceKeys = channel.GetStorageKeys(
                    subscriptionData.SubscriptionId,
                    subscriptionData.CurrentStorageAccount);

                if (storageService != null && storageServiceKeys != null)
                {
                    currentStorage = new CloudStorageAccount(new StorageCredentials(
                                                                 storageService.ServiceName,
                                                                 storageServiceKeys.StorageServiceKeys.Primary),
                                                             General.CreateHttpsEndpoint(storageService.StorageServiceProperties.Endpoints[0]),
                                                             General.CreateHttpsEndpoint(storageService.StorageServiceProperties.Endpoints[1]),
                                                             General.CreateHttpsEndpoint(storageService.StorageServiceProperties.Endpoints[2]));
                }
            }

            subscriptionData.CurrentCloudStorageAccount = currentStorage;
        }
コード例 #2
0
        public virtual string ReadConfigurationFromBlob(
            IServiceManagement channel,
            string storageName,
            string subscriptionId,
            Uri configurationFileUri)
        {
            var storageService = channel.GetStorageKeys(subscriptionId, storageName);
            var storageKey     = storageService.StorageServiceKeys.Primary;

            storageService = channel.GetStorageService(subscriptionId, storageName);
            var blobStorageEndpoint = General.CreateHttpsEndpoint(
                storageService.StorageServiceProperties.Endpoints.Find(p => p.Contains(BlobEndpointIdentifier)));
            var           credentials   = new StorageCredentials(storageName, storageKey);
            var           client        = new CloudBlobClient(blobStorageEndpoint, credentials);
            ICloudBlob    blob          = client.GetBlobReferenceFromServer(configurationFileUri);
            StringBuilder configuration = new StringBuilder(string.Empty);

            using (var stream = blob.OpenRead())
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    while (!reader.EndOfStream)
                    {
                        configuration.Append(reader.ReadLine());
                    }
                }
            }
            return(configuration.ToString());
        }
コード例 #3
0
        public virtual Uri UploadPackageToBlob(
            IServiceManagement channel,
            string storageName,
            string subscriptionId,
            string packagePath,
            BlobRequestOptions blobRequestOptions)
        {
            StorageService storageService = channel.GetStorageKeys(subscriptionId, storageName);
            string         storageKey     = storageService.StorageServiceKeys.Primary;

            storageService = channel.GetStorageService(subscriptionId, storageName);
            string blobEndpointUri = storageService.StorageServiceProperties.Endpoints[0];

            return(UploadFile(
                       storageName,
                       General.CreateHttpsEndpoint(blobEndpointUri), storageKey, packagePath, blobRequestOptions));
        }
コード例 #4
0
        public virtual void DeletePackageFromBlob(
            IServiceManagement channel,
            string storageName,
            string subscriptionId,
            Uri packageUri)
        {
            var storageService = channel.GetStorageKeys(subscriptionId, storageName);
            var storageKey     = storageService.StorageServiceKeys.Primary;

            storageService = channel.GetStorageService(subscriptionId, storageName);
            var blobStorageEndpoint = General.CreateHttpsEndpoint(
                storageService.StorageServiceProperties.Endpoints.Find(p => p.Contains(BlobEndpointIdentifier)));
            var        credentials = new StorageCredentials(storageName, storageKey);
            var        client      = new CloudBlobClient(blobStorageEndpoint, credentials);
            ICloudBlob blob        = client.GetBlobReferenceFromServer(packageUri);

            blob.DeleteIfExists();
        }