Exemplo n.º 1
0
        public Task <string> GetHashAsync(DriveItem driveItem)
        {
            var _hashAlgorithm = new QuickXorHash();

            using (var stream = File.OpenRead(driveItem.GetAbsolutePath(this.BasePath)))
            {
                return(Task.FromResult(Convert.ToBase64String(_hashAlgorithm.ComputeHash(stream))));
            }
        }
Exemplo n.º 2
0
 public Task <DriveItem> ToFullDriveItem(DriveItem driveItem)
 {
     if (driveItem.Type() == DriveItemType.File)
     {
         var fileInfo = new FileInfo(driveItem.GetAbsolutePath(this.BasePath));
         return(Task.FromResult(fileInfo.ToDriveItem(this.BasePath)));
     }
     else
     {
         throw new ArgumentException();
     }
 }
Exemplo n.º 3
0
        public Task <DriveItem> DeleteAsync(DriveItem driveItem)
        {
            string fullPath = driveItem.GetAbsolutePath(this.BasePath);

            switch (driveItem.Type())
            {
            case DriveItemType.Folder:
                Directory.Delete(fullPath, recursive: true);
                break;

            case DriveItemType.File:
                File.Delete(fullPath);
                break;

            case DriveItemType.RemoteItem:
            default:
                throw new NotSupportedException();
            }

            return(Task.FromResult(driveItem));
        }
Exemplo n.º 4
0
        public Task SetLastWriteTimeUtcAsync(DriveItem driveItem)
        {
            var driveItemPath = driveItem.GetAbsolutePath(this.BasePath);

            switch (driveItem.Type())
            {
            case DriveItemType.Folder:
                Directory.SetLastWriteTimeUtc(driveItemPath, driveItem.LastModified());
                break;

            case DriveItemType.File:
                File.SetLastWriteTimeUtc(driveItemPath, driveItem.LastModified());
                break;

            case DriveItemType.RemoteItem:
            default:
                throw new NotSupportedException();
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 5
0
        public Task <bool> ExistsAsync(DriveItem driveItem)
        {
            bool   result;
            string fullPath = driveItem.GetAbsolutePath(this.BasePath);

            switch (driveItem.Type())
            {
            case DriveItemType.Folder:
                result = Directory.Exists(fullPath);
                break;

            case DriveItemType.File:
                result = File.Exists(fullPath);
                break;

            case DriveItemType.RemoteItem:
            default:
                throw new NotSupportedException();
            }

            return(Task.FromResult(result));
        }
Exemplo n.º 6
0
        public async Task <DriveItem> CreateOrUpdateAsync(DriveItem driveItem)
        {
            var fullPath = driveItem.GetAbsolutePath(this.BasePath);

            switch (driveItem.Type())
            {
            case DriveItemType.Folder:
                Directory.CreateDirectory(fullPath);
                break;

            case DriveItemType.File:

                Directory.CreateDirectory(Path.GetDirectoryName(fullPath));

                if (driveItem.Content != null)
                {
                    using (var stream = File.OpenWrite(fullPath))
                    {
                        driveItem.Content.Seek(0, SeekOrigin.Begin);
                        driveItem.Content.CopyTo(stream);
                    }
                }
                else
                {
                    await new WebClient().DownloadFileTaskAsync(driveItem.Uri(), fullPath);
                }

                File.SetLastWriteTimeUtc(fullPath, driveItem.FileSystemInfo.LastModifiedDateTime.Value.DateTime);

                break;

            case DriveItemType.RemoteItem:
            default:
                throw new NotSupportedException();
            }

            return(driveItem);
        }
Exemplo n.º 7
0
        public Task <DriveItem> MoveAsync(DriveItem oldDriveItem, DriveItem newDriveItem)
        {
            var fullOldPath = oldDriveItem.GetAbsolutePath(this.BasePath);
            var fullNewPath = newDriveItem.GetAbsolutePath(this.BasePath);

            switch (newDriveItem.Type())
            {
            case DriveItemType.Folder:
                Directory.Move(fullOldPath, fullNewPath);
                break;

            case DriveItemType.File:
                Directory.CreateDirectory(Path.GetDirectoryName(fullNewPath));
                File.Move(fullOldPath, fullNewPath);
                break;

            case DriveItemType.RemoteItem:
            default:
                throw new NotSupportedException();
            }

            return(Task.FromResult(newDriveItem));
        }
Exemplo n.º 8
0
 public Task <DateTime> GetLastWriteTimeUtcAsync(DriveItem driveItem)
 {
     return(Task.FromResult(File.GetLastWriteTimeUtc(driveItem.GetAbsolutePath(this.BasePath))));
 }
Exemplo n.º 9
0
 public Task <Uri> GetDownloadUriAsync(DriveItem driveItem)
 {
     return(Task.FromResult(new Uri(driveItem.GetAbsolutePath(this.BasePath))));
 }