本文整理汇总了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;
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
}