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


C# IProgressMonitor.ThrowIfCanceled方法代码示例

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


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

示例1: LoadReport

        /// <inheritdoc />
        public Report LoadReport(bool loadAttachmentContents, IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
                throw new ArgumentNullException(@"progressMonitor");

            using (progressMonitor.BeginTask(String.Format("Loading report '{0}'.", reportContainer.ReportName), 10))
            {
                string reportPath = reportContainer.ReportName + @".xml";

                progressMonitor.ThrowIfCanceled();
                progressMonitor.SetStatus(reportPath);

                var serializer = new XmlSerializer(typeof(Report));

                Report report;
                using (Stream stream = reportContainer.OpenRead(reportPath))
                {
                    progressMonitor.ThrowIfCanceled();
                    report = (Report)serializer.Deserialize(stream);
                }

                FixImplicitIds(report);

                progressMonitor.Worked(1);
                progressMonitor.SetStatus(@"");

                if (loadAttachmentContents)
                {
                    progressMonitor.ThrowIfCanceled();
                    using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(9))
                        LoadReportAttachments(report, subProgressMonitor);
                }

                return report;
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:37,代码来源:DefaultReportReader.cs

示例2: SaveReportAttachments

        /// <inheritdoc />
        public void SaveReportAttachments(IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
                throw new ArgumentNullException(@"progressMonitor");

            if (reportAttachmentsSaved)
                return;

            int attachmentCount = CountAttachments(report);
            if (attachmentCount == 0)
                return;

            using (progressMonitor.BeginTask("Saving report attachments.", attachmentCount))
            {
                foreach (TestStepRun testStepRun in report.TestPackageRun.AllTestStepRuns)
                {
                    foreach (AttachmentData attachment in testStepRun.TestLog.Attachments)
                    {
                        string attachmentPath = attachmentPathResolver.GetAttachmentPath(testStepRun.Step.Id, attachment.Name, attachment.ContentType);

                        progressMonitor.ThrowIfCanceled();
                        progressMonitor.SetStatus(attachmentPath);

                        SaveAttachmentContents(attachment, attachmentPath);

                        progressMonitor.Worked(1);
                    }
                }

                reportAttachmentsSaved = true;
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:33,代码来源:DefaultReportWriter.cs

示例3: SaveReport

        /// <inheritdoc />
        public void SaveReport(AttachmentContentDisposition attachmentContentDisposition,
            IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
                throw new ArgumentNullException(@"progressMonitor");

            if (reportSaved)
                return;

            int attachmentCount = CountAttachments(report);
            using (progressMonitor.BeginTask("Saving report.", attachmentCount + 1))
            {
                var encoding = new UTF8Encoding(false);
                var settings = new XmlWriterSettings();
                settings.CheckCharacters = false;
                settings.Indent = true;
                settings.Encoding = encoding;
                settings.CloseOutput = true;

                string reportPath = reportContainer.ReportName + @".xml";

                progressMonitor.ThrowIfCanceled();
                progressMonitor.SetStatus(reportPath);

                using (XmlWriter writer = XmlWriter.Create(reportContainer.OpenWrite(reportPath, MimeTypes.Xml, settings.Encoding), settings))
                {
                    progressMonitor.ThrowIfCanceled();
                    SerializeReport(writer, attachmentContentDisposition);
                }

                progressMonitor.Worked(1);
                progressMonitor.SetStatus(@"");

                if (attachmentContentDisposition == AttachmentContentDisposition.Link && attachmentCount != 0)
                {
                    progressMonitor.ThrowIfCanceled();
                    using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(attachmentCount))
                        SaveReportAttachments(subProgressMonitor);
                }

                AddReportDocumentPath(reportPath);
                reportSaved = true;
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:45,代码来源:DefaultReportWriter.cs

示例4: LoadReportAttachments

        /// <inheritdoc />
        public void LoadReportAttachments(Report report, IProgressMonitor progressMonitor)
        {
            if (progressMonitor == null)
                throw new ArgumentNullException(@"progressMonitor");

            if (report.TestPackageRun == null)
                return;

            var attachmentsToLoad = new List<AttachmentData>();
            foreach (TestStepRun testStepRun in report.TestPackageRun.AllTestStepRuns)
            {
                foreach (AttachmentData attachment in testStepRun.TestLog.Attachments)
                {
                    if (attachment.ContentPath != null)
                        attachmentsToLoad.Add(attachment);
                }
            }

            if (attachmentsToLoad.Count == 0)
                return;

            using (progressMonitor.BeginTask("Loading report attachments.", attachmentsToLoad.Count))
            {
                foreach (AttachmentData attachment in attachmentsToLoad)
                {
                    progressMonitor.ThrowIfCanceled();

                    if (attachment.ContentDisposition != AttachmentContentDisposition.Link
                        || attachment.ContentPath == null)
                        continue;

                    string attachmentPath = attachment.ContentPath;

                    progressMonitor.SetStatus(attachmentPath);
                    LoadAttachmentContents(attachment, attachmentPath);
                }
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:39,代码来源:DefaultReportReader.cs


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