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(); } }
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(); } }