简体   繁体   English

从 WindowsAzure.Storage 迁移到 Azure.Storage 包时从 CloudStorageAccount 引用服务

[英]Referencing services from CloudStorageAccount when migrating from WindowsAzure.Storage to Azure.Storage packages

I have a code-base that makes extensive use of the WindowsAzure.Storage nuget package for access to Queues, Tables and Blobs .我有一个代码库,它广泛使用WindowsAzure.Storage nuget package 来访问Queues, Tables 和 Blobs The package is now flagged as deprecated with the indication that the functionality has been broken up into individual components under the Azure.Storage package-set. package 现在被标记为已弃用,表明该功能已分解为Azure.Storage包集下的各个组件。

This StackOverflow question and answer provides some description of the replacement packages but it's unclear how much of the restructuring is complete and what combination of legacy and new packages are required to migrate at this time. 这个 StackOverflow 问题和答案提供了对替换包的一些描述,但目前尚不清楚有多少重组已完成,以及此时需要哪些旧包和新包的组合才能迁移。

I've been unable to find any up-to-date migration guide and example code/documentation for the new packages tends to focus on basic operations.我一直找不到任何最新的迁移指南,新包的示例代码/文档往往侧重于基本操作。

Specifically, I'm having difficulty accessing the new services from a top-level storage account.具体来说,我很难从顶级存储帐户访问新服务。

The current code uses a pattern like this...当前代码使用这样的模式......

    var accountName = "...";
    var accountKey ="..............";
    var credentials = new StorageCredentials(accountName, accountKey);
    var account = new CloudStorageAccount(credentials,true);

    //for table access...
    var client = account.CreateCloudTableClient();
    var table = client.GetTableReference(tableName);
    
    //for queue access
    var client = account.CreateCloudQueueClient();
    var queue = client.GetQueueReference(queueName);
    
    //for blob access 
    var client = account.CreateCloudBlobClient();
    var container = client.GetContainerReference(containerName);
    var blob =   container.GetBlockBlobReference(path);
        

What would be the equivalent using the new packages and what combination of packages would I need?使用新包的等价物是什么?我需要什么样的包组合?

You will need 3 separate Nuget packages:您将需要 3 个单独的 Nuget 包:

  1. Azure.Storage.Blobs : For managing blobs Azure.Storage.Blobs :用于管理 blob
  2. Azure.Storage.Queues : For managing queues and Azure.Storage.Queues :用于管理队列和
  3. Microsoft.Azure.Cosmos.Table : For managing tables. Microsoft.Azure.Cosmos.Table :用于管理表。

As far as creating an instance of CloudStorageAccount is concerned, it is not available in Azure.Storage.Blobs and Azure.Storage.Queues.就创建CloudStorageAccount的实例而言,它在 Azure.Storage.Blobs 和 Azure.Storage.Queues 中不可用。 You will have to deal with it in a different manner.您将不得不以不同的方式处理它。 For Tables, CloudStorageAccount is available in Microsoft.Azure.Cosmos.Table namespace.对于表,CloudStorageAccount 在 Microsoft.Azure.Cosmos.Table 命名空间中可用。

For example, the following code in old SDK例如旧的 SDK 中的以下代码

var container = client.GetContainerReference(containerName);
var blob =   container.GetBlockBlobReference(path);

Need to be changed to something like:需要更改为:

var blobContainerClient = new BlobContainerClient(connectionString, containerName);//Use this client to perform operations on blob container.
var blockBlobClient = blobContainerClient.GetBlockBlobClient(blobName);//Use this client to perform operations on block blob.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从“WindowsAzure.Storage”迁移时,我应该为 Azure 表使用什么 package - What package should I use for Azure Tables when migrating away from "WindowsAzure.Storage" 共享访问从 windowsazure.storage 移动到 Azure.Storage.Files - Shared Access moving from windowsazure.storage to Azure.Storage.Files WindowsAzure.Storage没有使用.Net Core 1.0 - WindowsAzure.Storage on not working on .Net Core 1.0 WindowsAzure.Storage使用C#mono - WindowsAzure.Storage using C# mono ExecuteQuery WindowsAzure.Storage 5.0.3没有扩展方法 - ExecuteQuery WindowsAzure.Storage 5.0.3 no extension method 无法发布到Azure-Microsoft.WindowsAzure.Storage.CloudStorageAccount ctor不匹配 - Cannot publish to Azure - Microsoft.WindowsAzure.Storage.CloudStorageAccount ctor doesn't match 在 C# .NET Core 中使用 Azure TableStorage - Nuget Package WindowsAzure.Storage Alternative - Using Azure TableStorage in C# .NET Core - Nuget Package WindowsAzure.Storage Alternative 如何使用 Azure.Storage v12 SDK 从 Azure Blob 中删除元数据? - How can I remove metadata from an Azure Blob using Azure.Storage v12 SDK? WindowsAzure.Storage,版本= 9.3.0.0-异常无法加载文件或程序集 - WindowsAzure.Storage, Version=9.3.0.0 - exception could not load file or assembly 如何在Visual Studio 2013中安装WindowsAzure.Storage? - How do I install WindowsAzure.Storage in Visual Studio 2013?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM