public static IStorageFolder CreateFolder(
     this IStorageProvider storageProvider,
     IStoragePath path,
     bool recursive     = false,
     IProgress progress = null)
 {
     return(storageProvider.CreateFolderAsync(path, recursive, progress).GetAwaiter().GetResult());
 }
 public static IStorageRecord CreateRecord(
     this IStorageProvider storageProvider,
     IStoragePath path,
     byte[] contents,
     string contentType = null,
     IProgress progress = null)
 {
     return(storageProvider.CreateRecordAsync(path, contents, contentType, progress).GetAwaiter().GetResult());
 }
 public static async Task <IStorageRecord> CreateRecordAsync(
     this IStorageProvider storageProvider,
     IStoragePath path,
     byte[] contents,
     string contentType = null,
     IProgress progress = null,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var buffer = new MemoryStream(contents, 0, contents.Length, false, true))
     {
         return(await storageProvider.CreateRecordAsync(path, buffer, contentType, progress, cancellationToken));
     }
 }
        public static async Task <IStorageFolder> CreateFolderAsync(
            this IStorageProvider storageProvider,
            IStoragePath path,
            bool recursive     = false,
            IProgress progress = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (storageProvider == null)
            {
                throw new ArgumentNullException(nameof(storageProvider));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (storageProvider.Features.TryGetFeature(out ICreateByPathFeature implmentation))
            {
                return(await implmentation.CreateFolderAsync(storageProvider, path, recursive, progress, cancellationToken));
            }
            // Default implementation.
            var p = await path.GetParentAsync(cancellationToken);

            switch (p)
            {
            case null:
                throw new InvalidOperationException($"Unable to resolve parent of {path.Uri}.");

            case IStorageFolder folder:
                return(await folder.CreateFolderAsync(path.Name, progress, cancellationToken));

            case IStorageRecord _:
                throw new InvalidOperationException($"Parent of {path.Uri} is a storage record.");

            case IStoragePath parentPath:
                if (recursive)
                {
                    var folder = await storageProvider.CreateFolderAsync(parentPath, true, progress, cancellationToken);

                    return(await folder.CreateFolderAsync(path.Name, progress, cancellationToken));
                }
                throw new InvalidOperationException($"Parent of {path.Uri} does not exist.");

            default:
                throw new NotImplementedException($"No implementation provided that handles {p.GetType()}");
            }
        }
 public static IStoragePath GetParent(this IStoragePath path)
 {
     return(path.GetParentAsync().GetAwaiter().GetResult());
 }
 public static IStorageProvider GetStorageProvider(this IStoragePath storagePath) => storagePath.StorageRoot.StorageProvider;
 public static bool IsRecord(this IStoragePath storagePath) => storagePath is IStorageRecord;
 public async Task <IStorageRecord> CreateRecordAsync(IStorageProvider storageProvider, IStoragePath path, Stream contents, string contentType = null, IProgress progress = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (path is StoragePath googleStoragePath)
     {
         return(await googleStoragePath.StorageRoot.CreateRecordAsync(googleStoragePath.LocalPath, contents, contentType, progress, cancellationToken).ConfigureAwait(false));
     }
     throw new InvalidOperationException($"Invalid storage path of type {path.GetType()}");
 }
 public Task <IStorageFolder> CreateFolderAsync(IStorageProvider storageProvider, IStoragePath path, bool recursive = false, IProgress progress = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     try
     {
         if (path is StoragePath googleStoragePath)
         {
             return(Task.FromResult <IStorageFolder>(CreateFolder(googleStoragePath, progress)));
         }
         throw new InvalidOperationException($"Invalid storage path of type {path.GetType()}");
     }
     catch (Exception exn)
     {
         return(Task.FromException <IStorageFolder>(exn));
     }
 }