麻烦从升级Azure存储1.7〜2.0 [英] Trouble Upgrading from Azure Storage 1.7 to 2.0

查看:203
本文介绍了麻烦从升级Azure存储1.7〜2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在参与升级从Azure的1.7至2.2和我遇到与寄存重大更改。在库中的所有存储呼叫单元测试所覆盖,我已经理顺大部分的变化。

我完全卡在我们的核心方法,它得到一个目录的子目录列表之一。我知道他们不是真正的目录,而是BLOB名称的一部分,但功能2.0之前就已经存在,我们大量使用它跨越近30个不同的服务。

存储BLOB地址
TESTDATA /测试/测试1 / blob.txt

和测试

  ///单元测试
[测试]
公共无效BuildDirectoryAndRetrieveUsingSubDirectory()
{
  CloudBlobDirectory子目录= GetBlobDirectory(TESTDATA /测试/);
  IEnumerable的< CloudBlobDirectory>迪尔斯=
    。subDirectory.ListBlobs()OfType< CloudBlobDirectory>();
  Assert.AreEqual(1,dirs.Count());
}

老1.7 code为GetBlobDirectory返回在TESTDATA /测试/每个目录的blob的列表,所以在这种情况下,将返回测试1

  /// Azure存储1.7
公共静态CloudBlobDirectory GetBlobDirectory(字符串directoryReference)
{
  返回BlobClient.GetBlobDirectoryReference(directoryReference);
}

我白白试图使用2.0得到相同的结果。

  /// Azure存储2.0
公共静态CloudBlobDirectory GetBlobDirectory(字符串directoryReference)
{
  字符串容器名称= GetContainerNameFromDirectoryName(directoryReference);
  CloudBlobContainer容器= BlobClient.GetContainerReference(容器名称);
  返回container.GetBlobDirectoryReference(directoryReference);
}

然而早在测试中显示目录只是返回枚举没有结果。

谁能帮助 - 我很想独自离开测试code,但该方法返回相同的结果。

感谢


解决方案

找到了答案,这是出奇的简单。

在StorageClient 1.7,您在通过preFIX值包含容器名称,并与一个/\".

所以基本上容器名称变为TESTDATA的目录,preFIX变为测试。

在最新版本的preFIX值是什么,不包括容器名称,因此函数已更改为

 公共静态CloudBlobDirectory GetBlobDirectory(字符串directoryReference)
{
    字符串容器名称= GetContainerNameFromDirectoryName(directoryReference);
    串目录preFIX =获取prefixFormDirectoryName(directoryReference);
    CloudBlobContainer容器= BlobClient.GetContainerReference(容器名称);
    VAR斑点= container.ListBlobs(目录preFIX,FALSE);
    返回(CloudBlobDirectory)blobs.Where(B = GT;!b以CloudBlobDirectory = NULL)。首先();
}

I am currently involved in upgrading from Azure 1.7 to 2.2 and am encountering breaking changes with Storage. All the storage calls in the libraries are covered by Unit Tests and I've ironed out most of the changes.

I am completely stuck on one of our core methods which gets a list of subdirectories in a directory. I know they are not actual directories, but parts of blob names, but the functionality existed before 2.0 and we make heavy use of it across nearly 30 different services.

The storage blob address is testdata/test/test1/blob.txt

And the test

/// Unit Test
[Test]
public void BuildDirectoryAndRetrieveUsingSubDirectory()
{
  CloudBlobDirectory subDirectory = GetBlobDirectory("testdata/test/");
  IEnumerable<CloudBlobDirectory> dirs = 
    subDirectory.ListBlobs().OfType<CloudBlobDirectory>();
  Assert.AreEqual(1, dirs.Count());
}

The old 1.7 code for GetBlobDirectory returned a list of every directory blob in testdata/test/, so in this case would return test1

/// Azure Storage 1.7
public static CloudBlobDirectory GetBlobDirectory(string directoryReference)
{
  return BlobClient.GetBlobDirectoryReference(directoryReference);
}

I have tried in vain to get the same results from using 2.0

/// Azure Storage 2.0
public static CloudBlobDirectory GetBlobDirectory(string directoryReference)
{
  string containerName = GetContainerNameFromDirectoryName(directoryReference);
  CloudBlobContainer container = BlobClient.GetContainerReference(containerName);
  return container.GetBlobDirectoryReference(directoryReference);
}

However back in the test the dirs just returns "the enumeration yielded no results".

Can anyone help - I want very much to leave the test code alone, but return the same results from the method.

Thanks

解决方案

Found the answer, which was surprisingly simple.

In StorageClient 1.7, the prefix value that you passed in included the container name and had to end with a "/".

So basically the containerName becomes "testdata" and the directoryPrefix becomes "test".

In the latest version the prefix value is anything not including the container name, so the function has changed to be

public static CloudBlobDirectory GetBlobDirectory(string directoryReference)
{
    string containerName = GetContainerNameFromDirectoryName(directoryReference);
    string directoryPrefix = GetPrefixFormDirectoryName(directoryReference);
    CloudBlobContainer container = BlobClient.GetContainerReference(containerName);
    var blobs = container.ListBlobs(directoryPrefix, false);
    return (CloudBlobDirectory)blobs.Where(b => b as CloudBlobDirectory !=null).First();
}

这篇关于麻烦从升级Azure存储1.7〜2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆