当前位置: 首页>>代码示例>>C#>>正文


C# ITransferProgress.Update方法代码示例

本文整理汇总了C#中ITransferProgress.Update方法的典型用法代码示例。如果您正苦于以下问题:C# ITransferProgress.Update方法的具体用法?C# ITransferProgress.Update怎么用?C# ITransferProgress.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITransferProgress的用法示例。


在下文中一共展示了ITransferProgress.Update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetupUploadTransferProgress

        public IDisposable SetupUploadTransferProgress(ITransferProgress transferProgress, TimeSpan timeout) {
            var lastTime = Tools.Generic.GetCurrentUtcDateTime;
            long lastBytes = 0;

            UploadProgressChanged +=
                (sender, args) => {
                    var bytes = args.BytesReceived;
                    var now = Tools.Generic.GetCurrentUtcDateTime;

                    transferProgress.FileSizeTransfered = bytes;
                    long? speed = null;
                    if (lastBytes != 0) {
                        var timeSpan = now - lastTime;
                        var bytesChange = bytes - lastBytes;

                        if (timeSpan.TotalMilliseconds > 0)
                            speed = (long) (bytesChange/(timeSpan.TotalMilliseconds/1000.0));
                    }
                    transferProgress.Update(speed, args.ProgressPercentage);
                    lastTime = now;
                    lastBytes = bytes;
                };

            UploadFileCompleted += (sender, args) => { transferProgress.Completed = true; };

            var timer = new TimerWithElapsedCancellation(500, () => {
                if (!transferProgress.Completed
                    && Tools.Generic.LongerAgoThan(lastTime, timeout)) {
                    CancelAsync();
                    return false;
                }
                return !transferProgress.Completed;
            });
            return timer;
        }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:35,代码来源:WebClient.cs

示例2: ParseOutput

        public override void ParseOutput(Process sender, string data, ITransferProgress progress) {
            //        3.51M  43%  177.98kB/s    0:00:25
            // sent 1.39K bytes  received 1.01K bytes  1.60K bytes/sec
            // total size is 114.55K  speedup is 47.57
            if (data == null)
                return;
            progress.UpdateOutput(data);

            var matches = RSYNC_START.Matches(data);
            if (matches.Count > 0) {
                var match = matches[0];


                var speed = match.Groups[2].Value.TryDouble();
                var speedUnit = match.Groups[3].Value;
                progress.Update(GetByteSize(speed, speedUnit), match.Groups[1].Value.TryDouble());

                TimeSpan ts;
                if (TimeSpan.TryParse(match.Groups[4].Value, out ts))
                    progress.Eta = ts;

                return;
            }

            matches = RSYNC_END.Matches(data);
            if (matches.Count > 0) {
                var match = matches[0];
                var sent = match.Groups[1].Value.TryDouble();
                var sentUnit = match.Groups[2].Value;

                var received = match.Groups[3].Value.TryDouble();
                var receivedUnit = match.Groups[4].Value;

                // Rsync final message omits B(yte) indication
                progress.FileSizeTransfered = GetByteSize(sent, sentUnit + "b") +
                                              GetByteSize(received, receivedUnit + "b");
                progress.Completed = true;
                return;
            }

            progress.Eta = null;
            progress.Update(null, 0);
        }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:43,代码来源:RsyncOutputParser.cs

示例3: ParseOutput

        public override void ParseOutput(Process sender, string data, ITransferProgress progress) {
            // ###################- 97.3% 141.5 kBps 0:00 ETA  
            // used 0 local, fetched 894
            if (data == null)
                return;
            progress.UpdateOutput(data);

            if (!VerifyZsyncCompatible(data))
                progress.ZsyncIncompatible = true;

            if (CheckZsyncLoop(sender, data, progress))
                return;

            var matches = ZSYNC_START.Matches(data);
            if (matches.Count > 0) {
                var match = matches[0];

                var speed = match.Groups[2].Value.TryDouble();
                var speedUnit = match.Groups[3].Value;
                progress.Update(GetByteSize(speed, speedUnit), match.Groups[1].Value.TryDouble());

                var eta = match.Groups[4].Value;
                if (tspan.IsMatch(eta))
                    eta = "0:" + eta;
                TimeSpan ts;
                if (TimeSpan.TryParse(eta, out ts))
                    progress.Eta = ts;

                return;
            }

            matches = ZSYNC_END.Matches(data);
            if (matches.Count > 0) {
                var match = matches[0];
                progress.FileSizeTransfered = match.Groups[2].Value.TryInt();
                progress.Completed = true;
                return;
            }

            progress.Eta = null;
            progress.Update(null, 0);
        }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:42,代码来源:ZsyncOutputParser.cs


注:本文中的ITransferProgress.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。