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();
            }
        }
Exemple #2
0
        // NewDrive

        /// <summary>
        ///     Allows the provider to map drives after initialization.
        /// </summary>
        /// <returns>
        ///     A drive collection with the drives that the provider wants to be added to the session upon initialization. The default implementation returns an empty
        ///     <see
        ///         cref="System.Management.Automation.PSDriveInfo" />
        ///     collection.
        /// </returns>
        /// <remarks>
        ///     After the Start method is called on a provider, the
        ///     InitializeDefaultDrives method is called. This is an opportunity
        ///     for the provider to mount drives that are important to it. For
        ///     instance, the Active Directory provider might mount a drive for
        ///     the defaultNamingContext if the machine is joined to a domain.
        ///     All providers should mount a root drive to help the user with
        ///     discoverability. This root drive might contain a listing of a set
        ///     of locations that would be interesting as roots for other mounted
        ///     drives. For instance, the Active Directory provider may create a
        ///     drive that lists the naming contexts found in the namingContext
        ///     attributes on the RootDSE. This will help users discover
        ///     interesting mount points for other drives.
        /// </remarks>
        protected override Collection <PSDriveInfo> InitializeDefaultDrives()
        {
            var rootDrive = new AzureDriveInfo(AzureDriveInfo.ProviderScheme, ProviderInfo, string.Empty, "Azure namespace", null);

            UniversalProviderInfo.AddingDrives.Add(rootDrive);

            foreach (var alias in UniversalProviderInfo.Aliases)
            {
                UniversalProviderInfo.AddingDrives.Add(new AzureDriveInfo(alias, ProviderInfo));
            }

            return(UniversalProviderInfo.AddingDrives);
        }
        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();
            }
        }