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


C# Request.Progress方法代码示例

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


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

示例1: _UnpackArchive

        private IEnumerable<string> _UnpackArchive(string localFilename, string destinationFolder, Request request) {
            var info = new ZipInfo(localFilename);
            var files = info.GetFiles();
            var percent = 0;
            var index = 0;
            var processed = new List<string>();

                // request.Debug("Unpacking {0} {1}", localFilename, destinationFolder);
                var pid = request.StartProgress(0, "Unpacking Archive '{0}' ", Path.GetFileName(localFilename));
                try {
                    info.Unpack(destinationFolder, (sender, args) => {
                        if (args.ProgressType == ArchiveProgressType.FinishFile) {
                            processed.Add(Path.Combine(destinationFolder, args.CurrentFileName));
                            index++;
                            var complete = (index*100)/files.Count;
                            if (complete != percent) {
                                percent = complete;
                                request.Progress(pid, percent, "Unpacked {0}", args.CurrentFileName);
                            }
                            /*
                         * Does not currently support cancellation .
                         * Todo: add cancellation support to DTF compression classes.
                         * */
                            if (request.IsCanceled) {
                                throw new OperationCanceledException("cancelling");
                            }
                        }
                    });
                } catch (OperationCanceledException) {
                    // no worries.
                }

                // request.Debug("DONE Unpacking {0} {1}", localFilename, destinationFolder);
                request.CompleteProgress(pid, true);

            // return the list of files to the parent.
            return processed.ToArray();
        }
开发者ID:vairam-svs,项目名称:oneget,代码行数:38,代码来源:ZipArchiver.cs

示例2: CreateProgressHandler

        private ExternalUIHandler CreateProgressHandler(Request request) {
            var currentTotalTicks = -1;
            var currentProgress = 0;
            var progressDirection = 1;
            var actualPercent = 0;

            ExternalUIHandler handler = (type, message, buttons, icon, button) => {
                if (request.IsCanceled) {
                    return MessageResult.Cancel;
                }

                switch (type) {
                    case InstallMessage.Progress:
                        if (message.Length >= 2) {
                            var msg = message.Split(": ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(m => m.ToInt32(0)).ToArray();

                            switch (msg[1]) {
                                // http://msdn.microsoft.com/en-us/library/aa370354(v=VS.85).aspx
                                case 0: //Resets progress bar and sets the expected total number of ticks in the bar.
                                    currentTotalTicks = msg[3];
                                    currentProgress = 0;
                                    if (msg.Length >= 6) {
                                        progressDirection = msg[5] == 0 ? 1 : -1;
                                    }
                                    break;
                                case 1:
                                    //Provides information related to progress messages to be sent by the current action.
                                    break;
                                case 2: //Increments the progress bar.
                                    if (currentTotalTicks == -1) {
                                        break;
                                    }
                                    currentProgress += msg[3]*progressDirection;
                                    break;
                                case 3:
                                    //Enables an action (such as CustomAction) to add ticks to the expected total number of progress of the progress bar.
                                    break;
                            }
                        }

                        if (currentTotalTicks > 0) {
                            var newPercent = (currentProgress*100/currentTotalTicks);
                            if (actualPercent < newPercent) {
                                actualPercent = newPercent;
                                // request.Debug("Progress : {0}", newPercent);
                                request.Progress(_progressId, actualPercent, "installing...");
                            }
                        }
                        break;
                }

                return MessageResult.OK;
            };

            return handler;
        }
开发者ID:vairam-svs,项目名称:oneget,代码行数:56,代码来源:MsiProvider.cs


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