简体   繁体   English

从Azure存储1.7升级到2.0的问题

[英]Trouble Upgrading from Azure Storage 1.7 to 2.0

I am currently involved in upgrading from Azure 1.7 to 2.2 and am encountering breaking changes with Storage. 我目前正在参与从Azure 1.7到2.2的升级,并且遇到存储方面的重大更改。 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. 我知道它们不是实际目录,而是blob名称的一部分,但是该功能在2.0之前就已存在,我们在近30种不同的服务中大量使用了它。

The storage blob address is testdata/test/test1/blob.txt 存储Blob地址为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 GetBlobDirectory的旧1.7代码返回了testdata / test /中每个目录blob的列表,因此在这种情况下将返回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 我白费了尝试从使用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". 但是,在测试中,dirs仅返回“枚举没有结果”。

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 "/". 在StorageClient 1.7中,您传入的前缀值包括容器名称,并且必须以“ /”结尾。

So basically the containerName becomes "testdata" and the directoryPrefix becomes "test". 因此,基本上,containerName变为“ testdata”,而directoryPrefix变为“ 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();
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM