Esempio n. 1
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. 2
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));
            }
        }
        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));
            }
        }
Esempio n. 4
0
 public StorageRecord(StorageRoot storageRoot, FsPath localPath, string mediaType)
     : base(storageRoot, localPath)
 {
     _fileInfo = new FileInfo(storageRoot.GetFullPath(localPath));
     MediaType = mediaType;
 }
Esempio n. 5
0
 public virtual async Task <IStoragePath> GetParentAsync(CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await StorageRoot.StorageProvider.ResolvePathAsync(System.IO.Path.GetDirectoryName(StorageRoot.GetFullPath(LocalPath)), cancellationToken));
 }