コード例 #1
0
        private void UploadCallback(ulong progress, ulong total_size)
        {
            //WindowsFormsExtensions.SetTaskbarProgress(this, (((float)transferredBytes) / totalBytes) * 100);
            var evt = new UploadProgressEvtArgs {
                total_bytes = total_size, uploaded_bytes = progress
            };

            UploadEvtProgress?.Invoke(this, evt);
        }
コード例 #2
0
        protected override async Task UploadFile(Stream file, string remote_name)
        {
            try {
                remote_name = remote_path + remote_name;
                using (Stream stream = new MemoryStream()) {
                    var use_compression = compress;
                    if (file.Length > 1024 * 1024 * 5)                     //if more than 5 megs don't comress
                    {
                        use_compression = false;
                    }
                    var writer = WriterFactory.Open(stream, ArchiveType.Tar, new WriterOptions(use_compression ? CompressionType.BZip2 : CompressionType.None)
                    {
                        LeaveStreamOpen = true
                    });
                    var arr  = remote_name.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    var path = String.Join("/", arr.Take(arr.Length - 1));

                    writer.Write(arr[arr.Length - 1], file);
                    writer.Dispose();
                    var len = stream.Length;
                    stream.Seek(0, SeekOrigin.Begin);
                    UploadEvtProgress?.Invoke(this, new UploadProgressEvtArgs {
                        total_bytes = 100, uploaded_bytes = 1
                    });
                    try {
                        await client.Containers.ExtractArchiveToContainerAsync(container, new ContainerPathStatParameters()
                        {
                            Path = path
                        }, stream, cancel.Token);
                    } catch (Exception ex) {
                        if (ex is TaskCanceledException || ex.InnerException is TaskCanceledException)
                        {
                            return;
                        }
                        throw ex;
                    }
                    UploadEvtProgress?.Invoke(this, new UploadProgressEvtArgs {
                        total_bytes = 1, uploaded_bytes = 1
                    });
                }
            } catch (Exception e) {
                HandleException(e);
            }
        }