本文整理汇总了C#中AsyncLazy.InitializeAsync方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncLazy.InitializeAsync方法的具体用法?C# AsyncLazy.InitializeAsync怎么用?C# AsyncLazy.InitializeAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncLazy
的用法示例。
在下文中一共展示了AsyncLazy.InitializeAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AzureLocation
public AzureLocation(AzureDriveInfo driveInfo, Path path, IListBlobItem cloudItem) {
_driveInfo = driveInfo;
Path = path;
Path.Validate();
if (cloudItem != null) {
_cloudItem = new AsyncLazy<IListBlobItem>(() => {
if (cloudItem is CloudBlockBlob) {
(cloudItem as CloudBlockBlob).FetchAttributes();
}
return cloudItem;
});
} else {
if (IsRootNamespace || IsAccount || IsContainer) {
// azure namespace mount.
_cloudItem = new AsyncLazy<IListBlobItem>(() => null);
return;
}
_cloudItem = new AsyncLazy<IListBlobItem>(() => {
if (CloudContainer == null) {
return null;
}
// not sure if it's a file or a directory.
if (path.EndsWithSlash) {
// can't be a file!
CloudContainer.GetDirectoryReference(Path.SubPath);
}
// check to see if it's a file.
ICloudBlob blobRef = null;
try {
blobRef = CloudContainer.GetBlobReferenceFromServer(Path.SubPath);
if (blobRef != null && blobRef.BlobType == BlobType.BlockBlob) {
blobRef.FetchAttributes();
return blobRef;
}
} catch {
}
// well, we know it's not a file, container, or account.
// it could be a directory (but the only way to really know that is to see if there is any files that have this as a parent path)
var dirRef = CloudContainer.GetDirectoryReference(Path.SubPath);
if (dirRef.ListBlobs().Any()) {
return dirRef;
}
blobRef = CloudContainer.GetBlockBlobReference(Path.SubPath);
if (blobRef != null && blobRef.BlobType == BlobType.BlockBlob) {
return blobRef;
}
// it really didn't match anything, we'll return the reference to the blob in case we want to write to it.
return blobRef;
});
_cloudItem.InitializeAsync();
}
}