コード例 #1
0
        /// <inheritdoc/>
        public async Task <IBackgroundTransfer> CreateAsync(
            IUnixDirectoryEntry targetDirectory,
            string fileName,
            Stream data,
            CancellationToken cancellationToken)
        {
            var targetEntry = (GoogleDriveDirectoryEntry)targetDirectory;

            var body = new File
            {
                Name    = fileName,
                Parents = new List <string>()
                {
                    targetEntry.File.Id,
                },
            };

            var request = Service.Files.Create(body);

            request.Fields = FileExtensions.DefaultFileFields;
            var newFileEntry = await request.ExecuteAsync(cancellationToken).ConfigureAwait(false);

            if (!_useBackgroundUpload)
            {
                var upload = Service.Files.Update(new File(), newFileEntry.Id, data, "application/octet-stream");
                var result = await upload.UploadAsync(cancellationToken).ConfigureAwait(false);

                if (result.Status == UploadStatus.Failed)
                {
                    throw new Exception(result.Exception.Message, result.Exception);
                }

                return(null);
            }

            var expectedSize = data.CanSeek ? data.Length : (long?)null;
            var tempData     = await _temporaryDataFactory.CreateAsync(data, expectedSize, cancellationToken).ConfigureAwait(false);

            var fullPath          = FileSystemExtensions.CombinePath(targetEntry.FullName, fileName);
            var backgroundUploads = new BackgroundUpload(fullPath, newFileEntry, tempData, this);
            await _uploadsLock.WaitAsync(cancellationToken).ConfigureAwait(false);

            try
            {
                _uploads.Add(backgroundUploads.File.Id, backgroundUploads);
            }
            finally
            {
                _uploadsLock.Release();
            }

            return(backgroundUploads);
        }
コード例 #2
0
        /// <inheritdoc/>
        public async Task <IBackgroundTransfer> ReplaceAsync(IUnixFileEntry fileEntry, Stream data, CancellationToken cancellationToken)
        {
            var fe       = (GoogleDriveFileEntry)fileEntry;
            var tempData = await _requestFactory.CreateTemporaryData(data, cancellationToken);

            var backgroundUploads = new BackgroundUpload(fe.FullName, fe.File, tempData, this);
            await _uploadsLock.WaitAsync(cancellationToken);

            try
            {
                _uploads.Add(backgroundUploads.File.Id, backgroundUploads);
            }
            finally
            {
                _uploadsLock.Release();
            }
            return(backgroundUploads);
        }
コード例 #3
0
        /// <inheritdoc/>
        public async Task <IBackgroundTransfer> CreateAsync(IUnixDirectoryEntry targetDirectory, string fileName, Stream data, CancellationToken cancellationToken)
        {
            var targetEntry  = (GoogleDriveDirectoryEntry)targetDirectory;
            var newFileEntry = await Service.CreateItemAsync(targetEntry.File, fileName, cancellationToken);

            var tempData = await _requestFactory.CreateTemporaryData(data, cancellationToken);

            var fullPath          = FileSystemExtensions.CombinePath(targetEntry.FullName, fileName);
            var backgroundUploads = new BackgroundUpload(fullPath, newFileEntry, tempData, this);
            await _uploadsLock.WaitAsync(cancellationToken);

            try
            {
                _uploads.Add(backgroundUploads.File.Id, backgroundUploads);
            }
            finally
            {
                _uploadsLock.Release();
            }
            return(backgroundUploads);
        }
コード例 #4
0
        /// <inheritdoc/>
        public async Task <IBackgroundTransfer> CreateAsync(
            IUnixDirectoryEntry targetDirectory,
            string fileName,
            Stream data,
            CancellationToken cancellationToken)
        {
            var targetEntry = (GoogleDriveDirectoryEntry)targetDirectory;

            var body = new File
            {
                Name    = fileName,
                Parents = new List <string>()
                {
                    targetEntry.File.Id,
                },
            };

            var request = Service.Files.Create(body);

            request.Fields = FileExtensions.DefaultFileFields;
            var newFileEntry = await request.ExecuteAsync(cancellationToken);

            var expectedSize = data.CanSeek ? data.Length : (long?)null;
            var tempData     = await _temporaryDataFactory.CreateAsync(data, expectedSize, cancellationToken);

            var fullPath          = FileSystemExtensions.CombinePath(targetEntry.FullName, fileName);
            var backgroundUploads = new BackgroundUpload(fullPath, newFileEntry, tempData, this);
            await _uploadsLock.WaitAsync(cancellationToken);

            try
            {
                _uploads.Add(backgroundUploads.File.Id, backgroundUploads);
            }
            finally
            {
                _uploadsLock.Release();
            }

            return(backgroundUploads);
        }
コード例 #5
0
        /// <inheritdoc/>
        public async Task <IBackgroundTransfer> ReplaceAsync(
            IUnixFileEntry fileEntry,
            Stream data,
            CancellationToken cancellationToken)
        {
            var fe           = (GoogleDriveFileEntry)fileEntry;
            var expectedSize = data.CanSeek ? data.Length : (long?)null;
            var tempData     = await _temporaryDataFactory.CreateAsync(data, expectedSize, cancellationToken);

            var backgroundUploads = new BackgroundUpload(fe.FullName, fe.File, tempData, this);
            await _uploadsLock.WaitAsync(cancellationToken);

            try
            {
                _uploads.Add(backgroundUploads.File.Id, backgroundUploads);
            }
            finally
            {
                _uploadsLock.Release();
            }

            return(backgroundUploads);
        }
コード例 #6
0
        /// <inheritdoc/>
        public async Task <IBackgroundTransfer> ReplaceAsync(
            IUnixFileEntry fileEntry,
            Stream data,
            CancellationToken cancellationToken)
        {
            var fe = (GoogleDriveFileEntry)fileEntry;

            if (!_useBackgroundUpload)
            {
                var upload = Service.Files.Update(new File(), fe.File.Id, data, "application/octet-stream");
                var result = await upload.UploadAsync(cancellationToken).ConfigureAwait(false);

                if (result.Status == UploadStatus.Failed)
                {
                    throw new IOException(result.Exception.Message, result.Exception);
                }

                return(null);
            }

            var expectedSize = data.CanSeek ? data.Length : (long?)null;
            var tempData     = await _temporaryDataFactory.CreateAsync(data, expectedSize, cancellationToken).ConfigureAwait(false);

            var backgroundUploads = new BackgroundUpload(fe.FullName, fe.File, tempData, this);
            await _uploadsLock.WaitAsync(cancellationToken).ConfigureAwait(false);

            try
            {
                _uploads.Add(backgroundUploads.File.Id, backgroundUploads);
            }
            finally
            {
                _uploadsLock.Release();
            }

            return(backgroundUploads);
        }
コード例 #7
0
 /// <inheritdoc/>
 public async Task<IBackgroundTransfer> ReplaceAsync(IUnixFileEntry fileEntry, Stream data, CancellationToken cancellationToken)
 {
     var fe = (GoogleDriveFileEntry)fileEntry;
     var tempData = await _requestFactory.CreateTemporaryData(data, cancellationToken);
     var backgroundUploads = new BackgroundUpload(fe.FullName, fe.File, tempData, this);
     await _uploadsLock.WaitAsync(cancellationToken);
     try
     {
         _uploads.Add(backgroundUploads.File.Id, backgroundUploads);
     }
     finally
     {
         _uploadsLock.Release();
     }
     return backgroundUploads;
 }
コード例 #8
0
 /// <inheritdoc/>
 public async Task<IBackgroundTransfer> CreateAsync(IUnixDirectoryEntry targetDirectory, string fileName, Stream data, CancellationToken cancellationToken)
 {
     var targetEntry = (GoogleDriveDirectoryEntry)targetDirectory;
     var newFileEntry = await Service.CreateItemAsync(targetEntry.File, fileName, cancellationToken);
     var tempData = await _requestFactory.CreateTemporaryData(data, cancellationToken);
     var fullPath = FileSystemExtensions.CombinePath(targetEntry.FullName, fileName);
     var backgroundUploads = new BackgroundUpload(fullPath, newFileEntry, tempData, this);
     await _uploadsLock.WaitAsync(cancellationToken);
     try
     {
         _uploads.Add(backgroundUploads.File.Id, backgroundUploads);
     }
     finally
     {
         _uploadsLock.Release();
     }
     return backgroundUploads;
 }