Exemplo n.º 1
0
        public static async Task <IStorageItemWithPath> ToStorageItemWithPath(this string path, StorageFolderWithPath parentFolder = null)
        {
            StorageFolderWithPath rootFolder = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(path));

            FilesystemResult <StorageFileWithPath> fsFileWithPathResult = await FilesystemTasks.Wrap(() =>
            {
                return(StorageFileExtensions.DangerousGetFileWithPathFromPathAsync(path, rootFolder, parentFolder));
            });

            if (fsFileWithPathResult)
            {
                return(fsFileWithPathResult.Result);
            }

            FilesystemResult <StorageFolderWithPath> fsFolderWithPathResult = await FilesystemTasks.Wrap(() =>
            {
                return(StorageFileExtensions.DangerousGetFolderWithPathFromPathAsync(path, rootFolder));
            });

            if (fsFolderWithPathResult)
            {
                return(fsFolderWithPathResult.Result);
            }

            return(null);
        }
Exemplo n.º 2
0
        // TODO: If the TODO of IStorageItemWithPath is implemented, change return type to IStorageItem
        public static async Task <IStorageItem> ToStorageItem(this string path, StorageFolderWithPath parentFolder = null)
        {
            FilesystemResult <StorageFolderWithPath> fsRootFolderResult = await FilesystemTasks.Wrap(async() =>
            {
                return((StorageFolderWithPath)await Path.GetPathRoot(path).ToStorageItemWithPath());
            });

            FilesystemResult <StorageFile> fsFileResult = await FilesystemTasks.Wrap(() =>
            {
                return(StorageFileExtensions.DangerousGetFileFromPathAsync(path, fsRootFolderResult.Result, parentFolder));
            });

            if (fsFileResult)
            {
                if (!string.IsNullOrWhiteSpace(fsFileResult.Result.Path))
                {
                    return(fsFileResult.Result);
                }
                else
                {
                    FilesystemResult <StorageFileWithPath> fsFileWithPathResult = await FilesystemTasks.Wrap(() =>
                    {
                        return(StorageFileExtensions.DangerousGetFileWithPathFromPathAsync(path, fsRootFolderResult));
                    });

                    if (fsFileWithPathResult)
                    {
                        return(null); /* fsFileWithPathResult.Result */ // Could be done if IStorageItemWithPath implemented IStorageItem
                    }
                }
            }

            FilesystemResult <StorageFolder> fsFolderResult = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path));

            if (fsFolderResult)
            {
                if (!string.IsNullOrWhiteSpace(fsFolderResult.Result.Path))
                {
                    return(fsFolderResult.Result);
                }
                else
                {
                    FilesystemResult <StorageFolderWithPath> fsFolderWithPathResult = await FilesystemTasks.Wrap(() =>
                    {
                        return(StorageFileExtensions.DangerousGetFolderWithPathFromPathAsync(path, fsRootFolderResult));
                    });

                    if (fsFolderWithPathResult)
                    {
                        return(null); /* fsFolderWithPathResult.Result; */ // Could be done if IStorageItemWithPath implemented IStorageItem
                    }
                }
            }

            return(null);
        }