public override void GetProperty(string path, System.Collections.ObjectModel.Collection <string> providerSpecificPickList)
        {
            var r = AzureFilePathResolver.ResolvePath(this.Client, path, skipCheckExistence: false);

            switch (r.PathType)
            {
            case PathType.AzureFile:
                r.File.FetchAttributes();
                this.RootProvider.WriteItemObject(r.File.Properties, path, false);
                this.RootProvider.WriteItemObject(r.File.Metadata, path, false);
                break;

            case PathType.AzureFileDirectory:
                if (r.Parts.Count() == 1)
                {
                    r.Share.FetchAttributes();
                    this.RootProvider.WriteItemObject(r.Share.Properties, path, true);
                    this.RootProvider.WriteItemObject(r.Share.Metadata, path, true);
                }
                else
                {
                    r.Directory.FetchAttributes();
                    this.RootProvider.WriteItemObject(r.Directory.Properties, path, true);
                }
                break;

            default:
                break;
            }
        }
        public override void SetProperty(string path, PSObject propertyValue)
        {
            var r = AzureFilePathResolver.ResolvePath(this.Client, path, skipCheckExistence: false);

            switch (r.PathType)
            {
            case PathType.AzureFile:
                r.File.FetchAttributes();
                MergeProperties(r.File.Metadata, propertyValue.Properties);
                r.File.SetMetadata();
                break;

            case PathType.AzureFileDirectory:
                if (r.Parts.Count() == 1)
                {
                    r.Share.FetchAttributes();
                    MergeProperties(r.Share.Metadata, propertyValue.Properties);
                    r.Share.SetMetadata();
                }
                else
                {
                    throw new Exception("Setting metadata/properties for directory is not supported");
                }
                break;

            default:
                break;
            }
        }
        public override void GetChildNames(string path, ReturnContainers returnContainers)
        {
            var r = AzureFilePathResolver.ResolvePath(this.Client, path);

            switch (r.PathType)
            {
            case PathType.AzureFileRoot:
                var shares = this.ListItems(path);
                foreach (CloudFileShare s in shares)
                {
                    this.RootProvider.WriteItemObject(s.Name, path, true);
                }
                break;

            case PathType.AzureFileDirectory:
                var items      = r.Directory.ListFilesAndDirectories();
                var parentPath = PathResolver.Combine(r.Parts);
                this.HandleItems(items,
                                 (f) => this.RootProvider.WriteItemObject(f.Name, PathResolver.Root, false),
                                 (d) => this.RootProvider.WriteItemObject(d.Name, PathResolver.Root, true),
                                 (s) => { }
                                 );
                break;

            case PathType.AzureFile:
            default:
                break;
            }
        }
        public CloudFile GetFile(string path)
        {
            var r = AzureFilePathResolver.ResolvePath(this.Client, path, hint: PathType.AzureFile);

            if (r.PathType == PathType.AzureFile)
            {
                return(r.File);
            }

            return(null);
        }
        public override IContentReader GetContentReader(string path)
        {
            var r = AzureFilePathResolver.ResolvePath(this.Client, path, hint: PathType.AzureFile, skipCheckExistence: false);

            if (r.PathType == PathType.AzureFile)
            {
                var reader = new AzureFileReader(GetFile(path));
                return(reader);
            }

            return(null);
        }
        internal void Upload(string localPath, string targePath)
        {
            var r = AzureFilePathResolver.ResolvePath(this.Client, targePath, skipCheckExistence: false);
            var localIsDirectory = Directory.Exists(localPath);
            var local            = PathResolver.SplitPath(localPath);

            switch (r.PathType)
            {
            case PathType.AzureFileRoot:
                if (localIsDirectory)
                {
                    var share = CreateShare(local.Last());
                    var dir   = share.GetRootDirectoryReference();
                    foreach (var f in Directory.GetFiles(localPath))
                    {
                        UploadFile(f, dir);
                    }

                    foreach (var d in Directory.GetDirectories(localPath))
                    {
                        UploadDirectory(d, dir);
                    }
                }
                else
                {
                    throw new Exception("Cannot upload file as file share.");
                }
                break;

            case PathType.AzureFileDirectory:
                if (localIsDirectory)
                {
                    UploadDirectory(localPath, r.Directory);
                }
                else
                {
                    UploadFile(localPath, r.Directory);
                }
                break;

            case PathType.AzureFile:
            default:
                break;
            }
        }
        public override void RemoveItem(string path, bool recurse)
        {
            var r = AzureFilePathResolver.ResolvePath(this.Client, path, skipCheckExistence: false);

            switch (r.PathType)
            {
            case PathType.AzureFileDirectory:
                this.DeleteDirectory(r.Directory, recurse);
                break;

            case PathType.AzureFile:
                r.File.Delete();
                break;

            default:
                break;
            }
        }
        public override bool ItemExists(string path)
        {
            if (PathResolver.IsLocalPath(path))
            {
                path = PathResolver.ConvertToRealLocalPath(path);
                return(File.Exists(path) || Directory.Exists(path));
            }

            try
            {
                var r      = AzureFilePathResolver.ResolvePath(this.Client, path, skipCheckExistence: false);
                var exists = r.Exists();
                return(exists);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        internal IEnumerable <object> ListItems(string path)
        {
            var result = AzureFilePathResolver.ResolvePath(this.Client, path, skipCheckExistence: false);

            switch (result.PathType)
            {
            case PathType.AzureFileRoot:
                return(ListShares(this.Client));

            case PathType.AzureFileDirectory:
                return(ListDirectory(result.Directory));

            case PathType.AzureFile:
                return(ListFile(result.File));

            default:
                return(null);
            }
        }
        internal void CreateDirectory(string path)
        {
            var r = AzureFilePathResolver.ResolvePath(this.Client, path);

            switch (r.PathType)
            {
            case PathType.AzureFileRoot:
                return;

            case PathType.AzureFileDirectory:
                CreateDirectoryAndShare(r.Directory);
                return;

            case PathType.AzureFile:
                throw new Exception("File " + path + " already exists.");

            default:
                return;
            }
        }
        internal void Download(string path, string destination)
        {
            var r           = AzureFilePathResolver.ResolvePath(this.Client, path, skipCheckExistence: false);
            var targetIsDir = Directory.Exists(destination);

            switch (r.PathType)
            {
            case PathType.AzureFile:
                if (targetIsDir)
                {
                    destination = PathResolver.Combine(destination, r.Parts.Last());
                }

                r.File.DownloadToFile(destination, FileMode.CreateNew);
                break;

            case PathType.AzureFileDirectory:
                if (string.IsNullOrEmpty(r.Directory.Name))
                {
                    //at share level
                    this.DownloadShare(r.Share, destination);
                }
                else
                {
                    DownloadDirectory(r.Directory, destination);
                }
                break;

            case PathType.AzureFileRoot:
                var shares = this.Client.ListShares();
                foreach (var share in shares)
                {
                    this.DownloadShare(share, destination);
                }
                break;

            default:
                break;
            }
        }
        public override bool IsItemContainer(string path)
        {
            if (PathResolver.IsLocalPath(path))
            {
                return(true);
            }

            var parts = PathResolver.SplitPath(path);

            if (parts.Count == 0)
            {
                return(true);
            }

            try
            {
                var r = AzureFilePathResolver.ResolvePath(this.Client, path, hint: PathType.AzureFileDirectory, skipCheckExistence: false);
                return(r.Exists());
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public override bool HasChildItems(string path)
        {
            var r = AzureFilePathResolver.ResolvePath(this.Client, path, hint: PathType.AzureFileDirectory, skipCheckExistence: false);

            return(r.Exists());
        }