示例#1
0
        private static async Task Upload(string source, string filename, UploadOptions options, DropboxClient client,
                                         CancellationToken cancellationToken)
        {
            Output($"Uploading {filename} to {options.DropboxPath}", options);
            Console.Title = $"Uploading {filename} to {(!string.IsNullOrEmpty(options.DropboxPath) ? options.DropboxPath : "Dropbox")}";

            if (ShowCancelHelp)
            {
                Output("Ctrl-C to cancel", options);
                ShowCancelHelp = false;
            }

            using (var fs = new FileStream(source, FileMode.Open, FileAccess.Read))
            {
                Metadata uploaded;

                if (!options.Chunked && fs.Length >= DropboxClientExtensions.ChunkedThreshold)
                {
                    Output("File is larger than 150MB, using chunked uploading.", options);
                    options.Chunked = true;
                }

                if (options.Chunked && fs.Length <= DropboxClientExtensions.ChunkSize)
                {
                    Output("File is less than 128kB, disabling chunked uploading.", options);
                    options.Chunked = false;
                }

                if (options.Chunked)
                {
                    var progress = ConfigureProgressHandler(options, fs.Length);
                    uploaded = await client.UploadChunked(options.DropboxPath, filename, fs, cancellationToken, progress, File.GetLastWriteTime(source));
                }
                else
                {
                    uploaded = await client.Upload(options.DropboxPath, filename, fs, File.GetLastWriteTime(source));
                }

                Output("Whoosh...", options);
                Output($"Uploaded {uploaded.Name} to {uploaded.PathDisplay}; Revision {uploaded.AsFile.Rev}", options);
            }
        }
示例#2
0
        private static async Task Upload(string source, string filename, UploadOptions options, DropboxClient client,
                                         CancellationToken cancellationToken)
        {
            Output($"Uploading {filename} to {options.DropboxPath}", options);
            Console.Title = $"Uploading {filename} to {options.DropboxPath}";

            if (ShowCancelHelp)
            {
                Output("Ctrl-C to cancel", options);
                ShowCancelHelp = false;
            }

            using (var fs = new FileStream(source, FileMode.Open, FileAccess.Read))
            {
                Metadata uploaded;

                if (!options.Chunked && fs.Length >= 150 * 1024 * 1024)
                {
                    Output("File is larger than 150MB, using chunked uploading.", options);
                    options.Chunked = true;
                }

                if (options.Chunked)
                {
                    var progress = ConfigureProgressHandler(options, fs.Length);
                    uploaded = await client.UploadChunked(options.DropboxPath, filename, fs, cancellationToken, progress);
                }
                else
                {
                    uploaded = await client.Upload(options.DropboxPath, filename, fs);
                }

                Output("Whoosh...", options);
                Output($"Uploaded {uploaded.Name} to {uploaded.PathDisplay}; Revision {uploaded.AsFile.Rev}", options);
            }
        }