当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlobClient.GetBlobReferenceFromServer方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetBlobReferenceFromServer方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobClient.GetBlobReferenceFromServer方法的具体用法?C# CloudBlobClient.GetBlobReferenceFromServer怎么用?C# CloudBlobClient.GetBlobReferenceFromServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient的用法示例。


在下文中一共展示了CloudBlobClient.GetBlobReferenceFromServer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeletePackageFromBlob

 public static 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 = new Uri(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();
 }
开发者ID:bielawb,项目名称:azure-sdk-tools,代码行数:11,代码来源:AzureBlob.cs

示例2: DeletePackageFromBlob

 public void DeletePackageFromBlob(string storageName, Uri packageUri)
 {
     StorageAccountGetKeysResponse keys = StorageManagementClient.StorageAccounts.GetKeys(storageName);
     string storageKey = keys.PrimaryKey;
     var storageService = StorageManagementClient.StorageAccounts.Get(storageName);
     var blobStorageEndpoint = storageService.StorageAccount.Properties.Endpoints[0];
     var credentials = new StorageCredentials(storageName, storageKey);
     var client = new CloudBlobClient(blobStorageEndpoint, credentials);
     ICloudBlob blob = client.GetBlobReferenceFromServer(packageUri);
     blob.DeleteIfExists();
 }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:11,代码来源:StorageClientWrapper.cs

示例3: RemoveVHD

        public static void RemoveVHD(IServiceManagement channel, string subscriptionId, Uri mediaLink)
        {
            var accountName = mediaLink.Host.Split('.')[0];
            var blobEndpoint = new Uri(mediaLink.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped));

            StorageService storageService;
            using (new OperationContextScope(channel.ToContextChannel()))
            {
                storageService = channel.GetStorageKeys(subscriptionId, accountName);
            }

            var storageAccountCredentials = new StorageCredentials(accountName, storageService.StorageServiceKeys.Primary);
            var client = new CloudBlobClient(blobEndpoint, storageAccountCredentials);
            var blob = client.GetBlobReferenceFromServer(mediaLink);
            blob.DeleteIfExists();
        }
开发者ID:huangpf,项目名称:azure-sdk-tools,代码行数:16,代码来源:Disks.cs

示例4: DownloadTestCredentials

 public static void DownloadTestCredentials(string testEnvironment, string downloadDirectoryPath, string blobUri, string storageAccount, string storageKey)
 {
     string containerPath = string.Format(EnvironmentPathFormat, testEnvironment);
     StorageCredentials credentials = new StorageCredentials(storageAccount, storageKey);
     CloudBlobClient blobClient = new CloudBlobClient(new Uri(blobUri), credentials);
     CloudBlobContainer container = blobClient.GetContainerReference(containerPath);
     foreach (IListBlobItem blobItem in container.ListBlobs())
     {
         ICloudBlob blob = blobClient.GetBlobReferenceFromServer(blobItem.Uri);
         Console.WriteLine("Downloading file {0} from blob Uri {1}", blob.Name, blob.Uri);
         FileStream blobStream = new FileStream(Path.Combine(downloadDirectoryPath, blob.Name), FileMode.Create);
         blob.DownloadToStream(blobStream);
         blobStream.Flush();
         blobStream.Close();
     }
 }
开发者ID:huangpf,项目名称:azure-sdk-tools,代码行数:16,代码来源:TestCredentialHelper.cs

示例5: DownloadTestVhdsAndPackages

        private static void DownloadTestVhdsAndPackages(string testEnvironment, string downloadDirectoryPath, string blobUri, string storageAccount, string storageKey)
        {
            StorageCredentials credentials = new StorageCredentials(storageAccount, storageKey);
            CloudBlobClient blobClient = new CloudBlobClient(new Uri(blobUri), credentials);
            blobContainer = blobClient.GetContainerReference(VhdFilesContainerName);
            foreach (IListBlobItem blobItem in blobContainer.ListBlobs())
            {
                ICloudBlob blob = blobClient.GetBlobReferenceFromServer(blobItem.Uri);
                Console.WriteLine("Downloading file {0} from blob Uri {1}", blob.Name, blob.Uri);
                FileStream blobStream = new FileStream(Path.Combine(downloadDirectoryPath, blob.Name), FileMode.Create);
                blob.DownloadToStream(blobStream);
                blobStream.Flush();
                blobStream.Close();
            }

            blobContainer = blobClient.GetContainerReference(toolsContainerName);
            foreach (IListBlobItem blobItem in blobContainer.ListBlobs())
            {
                ICloudBlob blob = blobClient.GetBlobReferenceFromServer(blobItem.Uri);
                Console.WriteLine("Downloading file {0} from blob Uri {1}", blob.Name, blob.Uri);
                FileStream blobStream = new FileStream(Path.Combine(downloadDirectoryPath, @"..\..\", blob.Name), FileMode.Create);
                blob.DownloadToStream(blobStream);
                blobStream.Flush();
                blobStream.Close();
            }
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:26,代码来源:CredentialHelper.cs

示例6: CloudBlobContainerGetBlobReferenceFromServer

        public void CloudBlobContainerGetBlobReferenceFromServer()
        {
            CloudBlobContainer container = GetRandomContainerReference();
            try
            {
                container.Create();

                SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
                {
                    Permissions = SharedAccessBlobPermissions.Read,
                    SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
                };

                CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb");
                blockBlob.PutBlockList(new string[] { });

                CloudPageBlob pageBlob = container.GetPageBlobReference("pb");
                pageBlob.Create(0);

                CloudAppendBlob appendBlob = container.GetAppendBlobReference("ab");
                appendBlob.CreateOrReplace();

                CloudBlobClient client;
                ICloudBlob blob;

                blob = container.GetBlobReferenceFromServer("bb");
                Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob));
                Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri));

                CloudBlockBlob blockBlobSnapshot = ((CloudBlockBlob)blob).CreateSnapshot();
                blob.SetProperties();
                Uri blockBlobSnapshotUri = new Uri(blockBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + blockBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
                blob = container.ServiceClient.GetBlobReferenceFromServer(blockBlobSnapshotUri);
                AssertAreEqual(blockBlobSnapshot.Properties, blob.Properties);
                Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlobSnapshot.Uri));
                Assert.IsNull(blob.StorageUri.SecondaryUri);

                blob = container.GetBlobReferenceFromServer("pb");
                Assert.IsInstanceOfType(blob, typeof(CloudPageBlob));
                Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri));

                CloudPageBlob pageBlobSnapshot = ((CloudPageBlob)blob).CreateSnapshot();
                blob.SetProperties();
                Uri pageBlobSnapshotUri = new Uri(pageBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + pageBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
                blob = container.ServiceClient.GetBlobReferenceFromServer(pageBlobSnapshotUri);
                AssertAreEqual(pageBlobSnapshot.Properties, blob.Properties);
                Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlobSnapshot.Uri));
                Assert.IsNull(blob.StorageUri.SecondaryUri);

                blob = container.GetBlobReferenceFromServer("ab");
                Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob));
                Assert.IsTrue(blob.StorageUri.Equals(appendBlob.StorageUri));

                CloudAppendBlob appendBlobSnapshot = ((CloudAppendBlob)blob).CreateSnapshot();
                blob.SetProperties();
                Uri appendBlobSnapshotUri = new Uri(appendBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + appendBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
                blob = container.ServiceClient.GetBlobReferenceFromServer(appendBlobSnapshotUri);
                AssertAreEqual(appendBlobSnapshot.Properties, blob.Properties);
                Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(appendBlobSnapshot.Uri));
                Assert.IsNull(blob.StorageUri.SecondaryUri);

                blob = container.ServiceClient.GetBlobReferenceFromServer(blockBlob.Uri);
                Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob));
                Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlob.Uri));
                Assert.IsNull(blob.StorageUri.SecondaryUri);

                blob = container.ServiceClient.GetBlobReferenceFromServer(pageBlob.Uri);
                Assert.IsInstanceOfType(blob, typeof(CloudPageBlob));
                Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlob.Uri));
                Assert.IsNull(blob.StorageUri.SecondaryUri);

                blob = container.ServiceClient.GetBlobReferenceFromServer(appendBlob.Uri);
                Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob));
                Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(appendBlob.Uri));
                Assert.IsNull(blob.StorageUri.SecondaryUri);

                blob = container.ServiceClient.GetBlobReferenceFromServer(blockBlob.StorageUri);
                Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob));
                Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri));

                blob = container.ServiceClient.GetBlobReferenceFromServer(pageBlob.StorageUri);
                Assert.IsInstanceOfType(blob, typeof(CloudPageBlob));
                Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri));

                blob = container.ServiceClient.GetBlobReferenceFromServer(appendBlob.StorageUri);
                Assert.IsInstanceOfType(blob, typeof(CloudAppendBlob));
                Assert.IsTrue(blob.StorageUri.Equals(appendBlob.StorageUri));

                string blockBlobToken = blockBlob.GetSharedAccessSignature(policy);
                StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken);
                Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri);
                StorageUri blockBlobSASStorageUri = blockBlobSAS.TransformUri(blockBlob.StorageUri);

                string pageBlobToken = pageBlob.GetSharedAccessSignature(policy);
                StorageCredentials pageBlobSAS = new StorageCredentials(pageBlobToken);
                Uri pageBlobSASUri = pageBlobSAS.TransformUri(pageBlob.Uri);
                StorageUri pageBlobSASStorageUri = pageBlobSAS.TransformUri(pageBlob.StorageUri);

                string appendBlobToken = appendBlob.GetSharedAccessSignature(policy);
//.........这里部分代码省略.........
开发者ID:Gajendra-Bahakar,项目名称:azure-storage-net,代码行数:101,代码来源:CloudBlobContainerTest.cs

示例7: CloudBlobContainerGetBlobReferenceFromServer

        public void CloudBlobContainerGetBlobReferenceFromServer()
        {
            CloudBlobContainer container = GetRandomContainerReference();
            try
            {
                container.Create();

                SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
                {
                    Permissions = SharedAccessBlobPermissions.Read,
                    SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
                };

                CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb");
                blockBlob.PutBlockList(new string[] { });

                CloudPageBlob pageBlob = container.GetPageBlobReference("pb");
                pageBlob.Create(0);
                
                ICloudBlob blob1 = container.GetBlobReferenceFromServer("bb");
                Assert.IsInstanceOfType(blob1, typeof(CloudBlockBlob));

                CloudBlockBlob blob1Snapshot = ((CloudBlockBlob)blob1).CreateSnapshot();
                blob1.SetProperties();
                Uri blob1SnapshotUri = new Uri(blob1Snapshot.Uri.AbsoluteUri + "?snapshot=" + blob1Snapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
                ICloudBlob blob1SnapshotReference = container.ServiceClient.GetBlobReferenceFromServer(blob1SnapshotUri);
                AssertAreEqual(blob1Snapshot.Properties, blob1SnapshotReference.Properties);

                ICloudBlob blob2 = container.GetBlobReferenceFromServer("pb");
                Assert.IsInstanceOfType(blob2, typeof(CloudPageBlob));

                CloudPageBlob blob2Snapshot = ((CloudPageBlob)blob2).CreateSnapshot();
                blob2.SetProperties();
                Uri blob2SnapshotUri = new Uri(blob2Snapshot.Uri.AbsoluteUri + "?snapshot=" + blob2Snapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
                ICloudBlob blob2SnapshotReference = container.ServiceClient.GetBlobReferenceFromServer(blob2SnapshotUri);
                AssertAreEqual(blob2Snapshot.Properties, blob2SnapshotReference.Properties);

                ICloudBlob blob3 = container.ServiceClient.GetBlobReferenceFromServer(blockBlob.Uri);
                Assert.IsInstanceOfType(blob3, typeof(CloudBlockBlob));

                ICloudBlob blob4 = container.ServiceClient.GetBlobReferenceFromServer(pageBlob.Uri);
                Assert.IsInstanceOfType(blob4, typeof(CloudPageBlob));

                string blockBlobToken = blockBlob.GetSharedAccessSignature(policy);
                StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken);
                Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri);

                string pageBlobToken = pageBlob.GetSharedAccessSignature(policy);
                StorageCredentials pageBlobSAS = new StorageCredentials(pageBlobToken);
                Uri pageBlobSASUri = pageBlobSAS.TransformUri(pageBlob.Uri);

                ICloudBlob blob5 = container.ServiceClient.GetBlobReferenceFromServer(blockBlobSASUri);
                Assert.IsInstanceOfType(blob5, typeof(CloudBlockBlob));

                ICloudBlob blob6 = container.ServiceClient.GetBlobReferenceFromServer(pageBlobSASUri);
                Assert.IsInstanceOfType(blob6, typeof(CloudPageBlob));

                CloudBlobClient client7 = new CloudBlobClient(container.ServiceClient.BaseUri, blockBlobSAS);
                ICloudBlob blob7 = client7.GetBlobReferenceFromServer(blockBlobSASUri);
                Assert.IsInstanceOfType(blob7, typeof(CloudBlockBlob));

                CloudBlobClient client8 = new CloudBlobClient(container.ServiceClient.BaseUri, pageBlobSAS);
                ICloudBlob blob8 = client8.GetBlobReferenceFromServer(pageBlobSASUri);
                Assert.IsInstanceOfType(blob8, typeof(CloudPageBlob));
            }
            finally
            {
                container.DeleteIfExists();
            }
        }
开发者ID:huoxudong125,项目名称:azure-sdk-for-net,代码行数:71,代码来源:CloudBlobContainerTest.cs

示例8: Start

        /// <summary>
        /// Begins orchestration of bootstrapper tasks.
        /// </summary>
        /// <param name="args">The validated args parsed from the commmand line.</param>
        public void Start(BootStrapperArgs args)
        {
            if (RoleEnvironment.IsAvailable && RoleEnvironment.IsEmulated && !args.RunInEmulator)
            {
                // Skip running if under emulator
                return;
            }

            try
            {
                Client = String.IsNullOrEmpty(args.StorageConnection) ? null : CloudStorageAccount.Parse(args.StorageConnection).CreateCloudBlobClient();
            }
            catch (Exception ex)
            {
                throw new ArgumentException("The Azure storage connection string is not valid:  " + ex.Message, args.StorageConnection);
            }

            //download package (if not previously downloaded).  RunAlways forces download always.
            Uri targetUri = null;
            String package = null;
            if ( !String.IsNullOrEmpty(args.Get) )
            {
                Uri urlToDownload = null;

                //if a storage account is present generate a SAS for the get
                if (Client != null)
                {
                    //x| var account = CloudStorageAccount.Parse(args.StorageConnection);
                    //x| var client = account.CreateCloudBlobClient();

                    //TODO BASEURI THING
                    // MAKE

                    var uri = new Uri(Client.BaseUri, args.Get);
                    var reference = Client.GetBlobReferenceFromServer(uri);

                    var sas = reference.GetSharedAccessSignature(
                        new SharedAccessBlobPolicy()
                        {
                            Permissions = SharedAccessBlobPermissions.Read,
                            SharedAccessExpiryTime = DateTime.Now.AddMinutes(10)
                        });

                    urlToDownload = new Uri(reference.Uri, sas);
                }
                else //otherwise, this is a standard get
                {
                    if (!Uri.TryCreate(args.Get, UriKind.Absolute, out urlToDownload))
                        throw new ArgumentException("Invalid Uri", "args.Get");
                }

                //always download as a get
                package = this.downloader.DownloadPackageToDisk(
                    urlToDownload,
                    args.RunAlways,
                    args.LocalResource
                    );

                //Unzip without replace.  RunAlways forces unzip with replace
                if (args.Unzip)
                {
                    this.unzipper.Unzip(package, args.UnzipTarget, args.RunAlways);
                }
            }

            if ( !String.IsNullOrEmpty(args.Put) )
            {
                if ( Client != null )
                {
                    try {
                        var uri = new Uri(Client.BaseUri, args.Put);
                        var blob = Client.GetBlobReferenceFromServer(uri);
                        blob.Container.CreateIfNotExists();
                        String target = blob.GetSharedAccessSignature(
                            new SharedAccessBlobPolicy() {
                                Permissions = SharedAccessBlobPermissions.Write,
                                SharedAccessExpiryTime = DateTime.Now.AddMinutes(30)
                            });
                        if (args.Overwrite)
                            blob.DeleteIfExists();
                        targetUri = new Uri(blob.Uri, target);
                    }
                    catch ( StorageException ex ) {
                        if (Uri.IsWellFormedUriString(args.Put, UriKind.Relative))
                            throw new ArgumentException(
                                "A valid connection string to Azure blob storage must be supplied when uploading to a relative URL.\n" + ex.Message,
                                args.StorageConnection);
                    }
                }
                if ( targetUri == null ) //i| fall back on standard put.
                {
                    if ( !Uri.TryCreate(args.Put, UriKind.Absolute, out targetUri) )
                        throw new ArgumentException("Invalid URL was supplied for the PUT argument.", args.Put);
                }

                //i| Only package when we don't have a filename (didn't get), and the local resource is an existing folder.
//.........这里部分代码省略.........
开发者ID:directr,项目名称:bootstrapper,代码行数:101,代码来源:BootStrapperManager.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetBlobReferenceFromServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。