Exemplo n.º 1
0
        public override IEnumerable <ILocation> GetFiles(bool recurse)
        {
            if (recurse)
            {
                return(GetFiles(false).Union(GetDirectories(false).SelectMany(each => each.GetFiles(true))));
            }

            if (IsContainer)
            {
                return(CloudContainer.ListBlobs().Where(each => each is ICloudBlob && !(each as ICloudBlob).Name.EndsWith("/")).Select(each => new AzureLocation(_driveInfo, new Path {
                    HostAndPort = Path.HostAndPort,
                    Container = Path.Container,
                    SubPath = Path.ParseUrl(each.Uri).Name,
                }, each)));
            }

            if (IsDirectory)
            {
                var cbd = (_cloudItem.Value as CloudBlobDirectory);
                return(cbd == null?Enumerable.Empty <ILocation>() : cbd.ListBlobs().Where(each => each is ICloudBlob && !(each as ICloudBlob).Name.EndsWith("/")).Select(each => new AzureLocation(_driveInfo, new Path {
                    HostAndPort = Path.HostAndPort,
                    Container = Path.Container,
                    SubPath = Path.SubPath + '\\' + Path.ParseUrl(each.Uri).Name,
                }, each)));
            }
            return(Enumerable.Empty <AzureLocation>());
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
 public override ILocation GetChildLocation(string relativePath)
 {
     return(new AzureLocation(_driveInfo, Path.ParseWithContainer(AbsolutePath + "\\" + relativePath), null));
 }
Exemplo n.º 4
0
        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();
            }
        }
Exemplo n.º 5
0
        public override IEnumerable <ILocation> GetDirectories(bool recurse)
        {
            if (_invalidLocation)
            {
                return(Enumerable.Empty <AzureLocation>());
            }

            if (recurse)
            {
                var dirs = GetDirectories(false);
                return(dirs.Union(dirs.SelectMany(each => each.GetDirectories(true))));
            }

            if (IsRootNamespace)
            {
                // list accounts we know

                return(AzureProviderInfo.NamespaceProvider.Drives
                       .Select(each => each as AzureDriveInfo)
                       .Where(each => !string.IsNullOrEmpty(each.HostAndPort))
                       .Distinct(new ClrPlus.Core.Extensions.EqualityComparer <AzureDriveInfo>((a, b) => a.HostAndPort == b.HostAndPort, a => a.HostAndPort.GetHashCode()))
                       .Select(each => new AzureLocation(each, new Path {
                    HostAndPort = each.HostAndPort,
                    Container = string.Empty,
                    SubPath = string.Empty,
                }, null)));
            }

            if (IsAccount)
            {
                return(_driveInfo.CloudFileSystem.ListContainers().Select(each => new AzureLocation(_driveInfo, new Path {
                    HostAndPort = Path.HostAndPort,
                    Container = each.Name,
                }, null)));
            }

            if (IsContainer)
            {
                return(ListSubdirectories(CloudContainer).Select(each => new AzureLocation(_driveInfo, new Path {
                    HostAndPort = Path.HostAndPort,
                    Container = Path.Container,
                    SubPath = Path.ParseUrl(each.Uri).Name,
                }, each)));
            }

            if (IsDirectory)
            {
                var cbd = (_cloudItem.Value as CloudBlobDirectory);

                return(cbd == null
                    ? Enumerable.Empty <ILocation>()
                    : ListSubdirectories(cbd).Select(each => {
                    return new AzureLocation(_driveInfo, new Path {
                        HostAndPort = Path.HostAndPort,
                        Container = Path.Container,
                        SubPath = Path.SubPath + '\\' + Path.ParseUrl(each.Uri).Name,
                    }, each);
                }));
            }

            return(Enumerable.Empty <AzureLocation>());
        }