本文整理匯總了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();
}
}