public override Task DeleteAsync(IProgress progress = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (null != progress)
            {
                progress.Total = 1;
            }
            var fullPath = StorageRoot.GetFullPath(this);

            try
            {
                Directory.Delete(fullPath, true);
                if (null != progress)
                {
                    progress.Value = 1;
                }
                Logger.LogDebug("Successfully deleted folder \"{0}\".", fullPath);
                return(Task.CompletedTask);
            }
            catch (Exception exn)
            {
                Logger.LogError("Failed to delete folder \"{0}\".", fullPath);
                return(Task.FromException(exn));
            }
        }
 public Task UpdateSecurityAsync(IStorageSecurity security, IProgress progress = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     try
     {
         if (null != progress)
         {
             progress.Total = 1;
             progress.Value = 0;
         }
         StorageRoot.SetSecurity(LocalPath, security);
         Security = security;
         return(Task.CompletedTask);
     }
     catch (Exception exn)
     {
         return(Task.FromException(exn));
     }
     finally
     {
         if (null != progress)
         {
             progress.Value = 1;
         }
     }
 }
Esempio n. 3
0
        public async Task UpdateContentAsync(Stream contents, string contentType = null, IProgress progress = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            var fullPath = StorageRoot.GetFullPath(LocalPath);

            try
            {
                if (null != progress)
                {
                    progress.Total = contents.Length;
                }
                using (var fileStream = new FileStream(fullPath, FileMode.Create, FileAccess.Write, FileShare.None, StorageRoot.CopyBufferSize))
                {
                    await contents.CopyToAsync(fileStream, StorageRoot.CopyBufferSize, progress, cancellationToken).ConfigureAwait(false);

                    await fileStream.FlushAsync(cancellationToken).ConfigureAwait(false);
                }
                Logger.LogDebug("Successfully updated file \"{0}\".", fullPath);
            }
            catch (Exception exn)
            {
                Logger.LogError(exn, "Failed to update file \"{0}\".", fullPath);
                throw;
            }
            MediaType = contentType ?? await StorageRoot.GetMediaTypeAsync(LocalPath, CancellationToken.None).ConfigureAwait(false);
        }
Esempio n. 4
0
        public override Task DeleteAsync(IProgress progress = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (null != progress)
            {
                progress.Total = 1;
            }
            var fullPath = StorageRoot.GetFullPath(this);

            try
            {
                if (!File.Exists(fullPath))
                {
                    throw new FileNotFoundException("Unable to delete file as it does not exist.", fullPath);
                }
                File.Delete(fullPath);
                if (null != progress)
                {
                    progress.Value = 1;
                }
                Logger.LogDebug("Successfully deleted file \"{0}\".", fullPath);
                return(Task.CompletedTask);
            }
            catch (Exception exn)
            {
                Logger.LogError("Failed to delete file \"{0}\".", fullPath);
                return(Task.FromException(exn));
            }
        }
 protected StorageItem(StorageRoot storageRoot, FsPath localPath)
     : base(storageRoot, localPath)
 {
     Security = storageRoot.GetSecurity(localPath);
 }
Esempio n. 6
0
 public Task <IStorageRecord> RenameAsync(string name, IProgress progress = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     cancellationToken.ThrowIfCancellationRequested();
     return(Task.FromResult <IStorageRecord>(StorageRoot.RenameRecord(this, name, progress)));
 }
Esempio n. 7
0
 public StorageRecord(StorageRoot storageRoot, FsPath localPath, string mediaType)
     : base(storageRoot, localPath)
 {
     _fileInfo = new FileInfo(storageRoot.GetFullPath(localPath));
     MediaType = mediaType;
 }
 public IAsyncEnumerable <IStorageItem> GetContentsAsync() => StorageRoot.GetContentsAsync(LocalPath);
 public Task <IStorageRecord> CreateRecordAsync(string name, Stream contents, string contentType = null, IProgress progress = null, CancellationToken cancellationToken = default(CancellationToken))
 => StorageRoot.CreateRecordAsync(LocalPath + name, contents, contentType, progress, cancellationToken);
 public Task <IStorageFolder> CreateFolderAsync(string name, IProgress progress = null, CancellationToken cancellationToken = default(CancellationToken))
 => StorageRoot.CreateFolderAsync(LocalPath + name, progress, cancellationToken);
 public StorageFolder(StorageRoot storageRoot, FsPath localPath) : base(storageRoot, localPath)
 {
 }
Esempio n. 12
0
 public virtual async Task <IStoragePath> GetParentAsync(CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await StorageRoot.StorageProvider.ResolvePathAsync(System.IO.Path.GetDirectoryName(StorageRoot.GetFullPath(LocalPath)), cancellationToken));
 }
Esempio n. 13
0
 public StoragePath(StorageRoot storageRoot, FsPath localPath)
 {
     StorageRoot = storageRoot ?? throw new ArgumentNullException(nameof(storageRoot));
     LocalPath   = localPath ?? throw new ArgumentNullException(nameof(localPath));
 }