public string SaveReportAs(Report report, string fileName, string format, IProgressMonitor progressMonitor)
        {
            var file = string.Empty;
            using (progressMonitor.BeginTask("Generating report", 100))
            {
                var folderName = Path.GetDirectoryName(fileName);
                var reportContainer = new FileSystemReportContainer(folderName, 
                    Path.GetFileNameWithoutExtension(fileName));
                var reportWriter = reportManager.CreateReportWriter(report, reportContainer);

                if (progressMonitor.IsCanceled)
                    throw new OperationCanceledException();

                // Delete the report if it already exists
                reportContainer.DeleteReport();

                if (progressMonitor.IsCanceled)
                    throw new OperationCanceledException();

                progressMonitor.Worked(10);

                // Format the report
                var reportFormatterOptions = new ReportFormatterOptions();
                using (var subProgressMonitor = progressMonitor.CreateSubProgressMonitor(90))
                    reportManager.Format(reportWriter, format, reportFormatterOptions, subProgressMonitor);

                if (progressMonitor.IsCanceled)
                    throw new OperationCanceledException();

                if (reportWriter.ReportDocumentPaths.Count > 0)
                    file = Path.Combine(folderName, reportWriter.ReportDocumentPaths[0]);
            }
            return file;
        }
        /// <summary>
        /// Creates a copy of the options.
        /// </summary>
        /// <returns>The copy.</returns>
        public ReportFormatterOptions Copy()
        {
            var copy = new ReportFormatterOptions();

            copy.properties.AddAll(properties);
            return(copy);
        }
Exemple #3
0
        /// <inheritdoc />
        public void Format(IReportWriter reportWriter, string formatterName, ReportFormatterOptions formatterOptions,
                           IProgressMonitor progressMonitor)
        {
            if (reportWriter == null)
            {
                throw new ArgumentNullException(@"reportWriter");
            }
            if (formatterName == null)
            {
                throw new ArgumentNullException(@"formatterName");
            }
            if (formatterOptions == null)
            {
                throw new ArgumentNullException(@"formatterOptions");
            }
            if (progressMonitor == null)
            {
                throw new ArgumentNullException(@"progressMonitor");
            }

            IReportFormatter formatter = GetReportFormatter(formatterName);

            if (formatter == null)
            {
                throw new InvalidOperationException(String.Format("There is no report formatter named '{0}'.", formatterName));
            }

            formatter.Format(reportWriter, formatterOptions, progressMonitor);
        }
        /// <summary>
        /// Gets the attachment content disposition.
        /// </summary>
        /// <param name="options">The formatter options.</param>
        /// <returns>The attachment content disposition.</returns>
        protected AttachmentContentDisposition GetAttachmentContentDisposition(ReportFormatterOptions options)
        {
            string contentDisposition = options.Properties.GetValue(AttachmentContentDispositionOption);
            
            if (contentDisposition != null)
            {
                try
                {
                    return (AttachmentContentDisposition)Enum.Parse(typeof(AttachmentContentDisposition), contentDisposition, true);
                }
                catch (ArgumentException)
                {
                    // Ignore parse error.
                }
            }

            return DefaultAttachmentContentDisposition;
        }
        public void FormatWritesTheReportWithTheDefaultAttachmentContentDispositionIfNoneSpecified()
        {
            IProgressMonitor progressMonitor = Mocks.Stub<IProgressMonitor>();
            IReportWriter writer = Mocks.StrictMock<IReportWriter>();

            using (Mocks.Record())
            {
                writer.SaveReport(AttachmentContentDisposition.Absent, progressMonitor);
            }

            using (Mocks.Playback())
            {
                XmlReportFormatter formatter = new XmlReportFormatter();
                var reportFormatterOptions = new ReportFormatterOptions();

                formatter.Format(writer, reportFormatterOptions, progressMonitor);
            }
        }
        public void FormatWritesTheReportWithTheSpecifiedAttachmentContentDisposition()
        {
            IProgressMonitor progressMonitor = Mocks.Stub<IProgressMonitor>();
            IReportWriter writer = Mocks.StrictMock<IReportWriter>();

            using (Mocks.Record())
            {
                writer.SaveReport(AttachmentContentDisposition.Link, progressMonitor);
            }

            using (Mocks.Playback())
            {
                XmlReportFormatter formatter = new XmlReportFormatter();
                ReportFormatterOptions options = new ReportFormatterOptions();
                options.AddProperty(XmlReportFormatter.AttachmentContentDispositionOption, AttachmentContentDisposition.Link.ToString());

                formatter.Format(writer, options, progressMonitor);
            }
        }
        /// <inheritdoc />
        public override void Format(IReportWriter reportWriter, ReportFormatterOptions formatterOptions, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask("Formatting report.", 10))
            {
                using (MultipartMimeReportContainer archiveContainer = new MultipartMimeReportContainer(reportWriter.ReportContainer))
                {
                    string archivePath = archiveContainer.ReportName + ".mht";
                    reportWriter.AddReportDocumentPath(archivePath);

                    archiveContainer.OpenArchive(archivePath);
                    progressMonitor.Worked(0.5);

                    DefaultReportWriter archiveWriter = new DefaultReportWriter(reportWriter.Report, archiveContainer);
                    using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(9))
                        htmlReportFormatter.Format(archiveWriter, formatterOptions, subProgressMonitor);

                    archiveContainer.CloseArchive();
                    progressMonitor.Worked(0.5);
                }
            }
        }
        public static FileInfo GetHtmlFormattedReport(string sessionId, bool condensed)
        {
            IDiskCacheGroup group = GetReportCacheGroup(sessionId);
            string directory = condensed ? "Condensed" : "Full";

            FileInfo htmlReportFile = group.GetFileInfo(Path.Combine(directory, HtmlReportFileName));
            if (!htmlReportFile.Exists)
            {
                Report report = LoadSerializedReport(sessionId);
                if (report == null)
                    return null;

                group.CreateSubdirectory(directory);
                IReportManager reportManager = RuntimeAccessor.ServiceLocator.Resolve<IReportManager>();
                FileSystemReportContainer reportContainer = new FileSystemReportContainer(htmlReportFile.DirectoryName, ReportBaseName);
                IReportWriter reportWriter = reportManager.CreateReportWriter(report, reportContainer);
                var reportFormatterOptions = new ReportFormatterOptions();
                reportManager.Format(reportWriter, condensed ? "Html-Condensed" : "Html", reportFormatterOptions, NullProgressMonitor.CreateInstance());
            }

            return htmlReportFile;
        }
        /// <inheritdoc />
        public override void Format(IReportWriter reportWriter, ReportFormatterOptions options, IProgressMonitor progressMonitor)
        {
            AttachmentContentDisposition attachmentContentDisposition = GetAttachmentContentDisposition(options);

            using (progressMonitor.BeginTask("Formatting report.", 10))
            {
                progressMonitor.SetStatus("Applying template.");
                ApplyTemplate(reportWriter, attachmentContentDisposition, options);
                progressMonitor.Worked(3);

                progressMonitor.SetStatus("Copying resources.");
                CopyResources(reportWriter);
                progressMonitor.Worked(2);

                progressMonitor.SetStatus(@"");

                if (attachmentContentDisposition == AttachmentContentDisposition.Link)
                {
                    using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(5))
                        reportWriter.SaveReportAttachments(subProgressMonitor);
                }
            }
        }
        public void FormatWritesTheArchivedReport()
        {
            IReportWriter reportWriter = Mocks.StrictMock<IReportWriter>();
            IReportContainer reportContainer = Mocks.StrictMock<IReportContainer>();
            IReportFormatter htmlReportFormatter = Mocks.StrictMock<IReportFormatter>();
            IProgressMonitor progressMonitor = NullProgressMonitor.CreateInstance();
            var reportFormatterOptions = new ReportFormatterOptions();

            string reportPath = SpecialPathPolicy.For<MHtmlReportFormatterTest>().CreateTempFileWithUniqueName().FullName;
            using (Stream tempFileStream = File.OpenWrite(reportPath))
            {
                using (Mocks.Record())
                {
                    SetupResult.For(reportWriter.ReportContainer).Return(reportContainer);
                    SetupResult.For(reportWriter.Report).Return(new Report());

                    Expect.Call(reportContainer.EncodeFileName(null))
                        .Repeat.Any()
                        .IgnoreArguments()
                        .Do((Func<string, string>)delegate(string value) { return value; });

                    SetupResult.For(reportContainer.ReportName).Return("Foo");
                    Expect.Call(reportContainer.OpenWrite("Foo.mht", MimeTypes.MHtml, new UTF8Encoding(false)))
                        .Return(tempFileStream);
                    reportWriter.AddReportDocumentPath("Foo.mht");

                    Expect.Call(delegate { htmlReportFormatter.Format(null, null, null); })
                        .Constraints(Is.NotNull(), Is.Same(reportFormatterOptions), Is.NotNull())
                        .Do((FormatDelegate)delegate(IReportWriter innerReportWriter, ReportFormatterOptions innerFormatterOptions, IProgressMonitor innerProgressMonitor)
                        {
                            using (StreamWriter contentWriter = new StreamWriter(innerReportWriter.ReportContainer.OpenWrite("Foo.html", MimeTypes.Html, Encoding.UTF8)))
                                contentWriter.Write("<html><body>Some HTML</body></html>");

                            using (StreamWriter contentWriter = new StreamWriter(innerReportWriter.ReportContainer.OpenWrite(
                                innerReportWriter.ReportContainer.EncodeFileName("Foo\\Attachment 1%.txt"), MimeTypes.PlainText, Encoding.UTF8)))
                                contentWriter.Write("An attachment.");

                            using (StreamWriter contentWriter = new StreamWriter(innerReportWriter.ReportContainer.OpenWrite("Foo.css", null, null)))
                                contentWriter.Write("#Some CSS.");
                        });
                }

                using (Mocks.Playback())
                {
                    MHtmlReportFormatter formatter = new MHtmlReportFormatter(htmlReportFormatter);

                    formatter.Format(reportWriter, reportFormatterOptions, progressMonitor);

                    string reportContents = File.ReadAllText(reportPath);
                    TestLog.AttachPlainText("MHTML Report", reportContents);

                    Assert.Contains(reportContents, "MIME-Version: 1.0");
                    Assert.Contains(reportContents, "Content-Type: multipart/related; type=\"text/html\"; boundary=");
                    Assert.Contains(reportContents, "This is a multi-part message in MIME format.");

                    Assert.Contains(reportContents, "text/html");
                    Assert.Contains(reportContents, "Content-Location: file:///Foo.html");
                    Assert.Contains(reportContents, Convert.ToBase64String(Encoding.UTF8.GetBytes("<html><body>Some HTML</body></html>"), Base64FormattingOptions.InsertLineBreaks));

                    Assert.Contains(reportContents, "text/plain");
                    Assert.Contains(reportContents, "Content-Location: file:///Foo/Attachment_1%25.txt");
                    Assert.Contains(reportContents, Convert.ToBase64String(Encoding.UTF8.GetBytes("An attachment."), Base64FormattingOptions.InsertLineBreaks));

                    Assert.Contains(reportContents, "text/css");
                    Assert.Contains(reportContents, "Content-Location: file:///Foo.css");
                    Assert.Contains(reportContents, Convert.ToBase64String(Encoding.UTF8.GetBytes("#Some CSS."), Base64FormattingOptions.InsertLineBreaks));

                    File.Delete(reportPath);
                }
            }
        }
 /// <summary>
 /// Populates the arguments for the XSL template processing.
 /// </summary>
 protected virtual void PopulateArguments(XsltArgumentList arguments, ReportFormatterOptions options, string reportName)
 {
     arguments.AddParam(@"resourceRoot", @"", reportName);
 }
        /// <summary>
        /// Applies the transform to produce a report.
        /// </summary>
        protected virtual void ApplyTransform(IReportWriter reportWriter, AttachmentContentDisposition attachmentContentDisposition, ReportFormatterOptions options)
        {
            XsltArgumentList arguments = new XsltArgumentList();
            PopulateArguments(arguments, options, reportWriter.ReportContainer.ReportName);

            XPathDocument document = SerializeReportToXPathDocument(reportWriter, attachmentContentDisposition);

            string reportPath = reportWriter.ReportContainer.ReportName + @"." + extension;

            Encoding encoding = new UTF8Encoding(false);
            XslCompiledTransform transform = Transform;
            XmlWriterSettings settings = transform.OutputSettings.Clone();
            settings.CheckCharacters = false;
            settings.Encoding = encoding;
            settings.CloseOutput = true;
            using (XmlWriter writer = XmlWriter.Create(reportWriter.ReportContainer.OpenWrite(reportPath, contentType, encoding), settings))
                transform.Transform(document, arguments, writer);

            reportWriter.AddReportDocumentPath(reportPath);
        }
 /// <summary>
 /// Gets the report page size.
 /// </summary>
 /// <param name="options">The formatter options.</param>
 /// <returns>The report page size.</returns>
 protected int GetReportPageSize(ReportFormatterOptions options)
 {
     int value;
     string field = options.Properties.GetValue(ReportPageSizeOption);
     return (field != null) && Int32.TryParse(field, out value) ? value : -1;
 }
        private VtlReportWriter GetReportWriter(VelocityEngine velocityEngine, VelocityContext velocityContext, IReportWriter reportWriter, FormatHelper helper, ReportFormatterOptions options)
        {
            int pageSize = GetReportPageSize(options);
            int testCount = (reportWriter.Report.TestPackageRun == null) ? 0 : reportWriter.Report.TestPackageRun.Statistics.TestCount;

            if (pageSize < 0)
            {
                HtmlReportSplitSettings settings = preferenceManager.HtmlReportSplitSettings;
                pageSize = settings.Enabled ? settings.PageSize : 0;
            }

            if (supportSplit && pageSize > 0 && testCount > pageSize)
                return new MultipleFilesVtlReportWriter(velocityEngine, velocityContext, reportWriter, templatePath, contentType, extension, helper, pageSize);

            return new SingleFileVtlReportWriter(velocityEngine, velocityContext, reportWriter, templatePath, contentType, extension, helper);
        }
 /// <summary>
 /// Applies the template to produce a report.
 /// </summary>
 protected virtual void ApplyTemplate(IReportWriter reportWriter, AttachmentContentDisposition attachmentContentDisposition, ReportFormatterOptions options)
 {
     VelocityEngine velocityEngine = VelocityEngineFactory.CreateVelocityEngine();
     var helper = new FormatHelper();
     VelocityContext velocityContext = VelocityEngineFactory.CreateVelocityContext(reportWriter, helper);
     var writer = GetReportWriter(velocityEngine, velocityContext, reportWriter, helper, options);
     reportWriter.WithUpdatedContentPathsAndDisposition(attachmentContentDisposition, writer.Run);
 }
 /// <inheritdoc />
 public abstract void Format(IReportWriter reportWriter, ReportFormatterOptions formatterOptions, IProgressMonitor progressMonitor);
        /// <inheritdoc />
        public void Format(IReportWriter reportWriter, string formatterName, ReportFormatterOptions formatterOptions,
            IProgressMonitor progressMonitor)
        {
            if (reportWriter == null)
                throw new ArgumentNullException(@"reportWriter");
            if (formatterName == null)
                throw new ArgumentNullException(@"formatterName");
            if (formatterOptions == null)
                throw new ArgumentNullException(@"formatterOptions");
            if (progressMonitor == null)
                throw new ArgumentNullException(@"progressMonitor");

            IReportFormatter formatter = GetReportFormatter(formatterName);
            if (formatter == null)
                throw new InvalidOperationException(String.Format("There is no report formatter named '{0}'.", formatterName));

            formatter.Format(reportWriter, formatterOptions, progressMonitor);
        }
        /// <inheritdoc />
        public override void Format(IReportWriter reportWriter, ReportFormatterOptions options, IProgressMonitor progressMonitor)
        {
            AttachmentContentDisposition attachmentContentDisposition = GetAttachmentContentDisposition(options);

            reportWriter.SaveReport(attachmentContentDisposition, progressMonitor);
        }
        private FacadeTestRunState Run(IFacadeTestListener testListener, string assemblyPath, Filter<ITestDescriptor> filter, FacadeOptions facadeOptions)
        {
            if (testListener == null)
                throw new ArgumentNullException(@"testListener");
            if (assemblyPath == null)
                throw new ArgumentNullException("assemblyPath");
            if (facadeOptions == null)
                throw new ArgumentNullException("facadeOptions");

            ILogger logger = new FilteredLogger(new TDNetLogger(testListener), LogSeverity.Info);

            try
            {
                RuntimeAccessor.Instance.AddLogListener(logger);
                var filterRules = new List<FilterRule<ITestDescriptor>>();

                switch (facadeOptions.FilterCategoryMode)
                {
                    case FacadeFilterCategoryMode.Disabled:
                        filterRules.Add(new FilterRule<ITestDescriptor>(FilterRuleType.Inclusion, filter));
                        break;

                    case FacadeFilterCategoryMode.Include:
                        filterRules.Add(new FilterRule<ITestDescriptor>(FilterRuleType.Inclusion,
                            new AndFilter<ITestDescriptor>(new[] { filter, ToCategoryFilter(facadeOptions.FilterCategoryNames) })));
                        break;

                    case FacadeFilterCategoryMode.Exclude:
                        filterRules.Add(new FilterRule<ITestDescriptor>(FilterRuleType.Exclusion, ToCategoryFilter(facadeOptions.FilterCategoryNames)));
                        filterRules.Add(new FilterRule<ITestDescriptor>(FilterRuleType.Inclusion, filter));
                        break;
                }

                var filterSet = new FilterSet<ITestDescriptor>(filterRules);
                launcher.Logger = logger;
                launcher.ProgressMonitorProvider = new LogProgressMonitorProvider(logger);
                launcher.TestExecutionOptions.FilterSet = filterSet;
                launcher.TestProject.TestRunnerFactoryName = StandardTestRunnerFactoryNames.IsolatedAppDomain;
                launcher.TestProject.AddTestRunnerExtension(new TDNetExtension(testListener)); // This monitor will inform the user in real-time what's going on
                launcher.TestProject.TestPackage.AddFile(new FileInfo(assemblyPath));
                string assemblyDirectory = Path.GetDirectoryName(assemblyPath);
                launcher.TestProject.TestPackage.ApplicationBaseDirectory = new DirectoryInfo(assemblyDirectory);
                launcher.TestProject.TestPackage.WorkingDirectory = new DirectoryInfo(assemblyDirectory);
                TestLauncherResult result = RunLauncher(launcher);
                string reportDirectory = GetReportDirectory(logger);

                if (reportDirectory != null)
                {
                    var reportFormatterOptions = new ReportFormatterOptions();
                    var preferenceManager = (TDNetPreferenceManager)RuntimeAccessor.ServiceLocator.ResolveByComponentId("TDNetRunner.PreferenceManager");
                    var reportFormat = preferenceManager.ReportSettings.DetermineReportFormat(result.Report);
                    result.GenerateReports(reportDirectory, Path.GetFileName(assemblyPath), ReportArchive.Normal,
                        new[] { reportFormat }, reportFormatterOptions,
                        RuntimeAccessor.ServiceLocator.Resolve<IReportManager>(), NullProgressMonitor.CreateInstance());

                    // This will generate a link to the generated report
                    if (result.ReportDocumentPaths.Count != 0)
                    {
                        Uri rawUrl = new Uri(result.ReportDocumentPaths[0]);
                        string displayUrl = "file:///" + rawUrl.LocalPath.Replace(" ", "%20").Replace(@"\", "/");

                        // TDNet just prints the link on its own but it's not always clear to users what it represents.
                        // testListener.TestResultsUrl(displayUrl);
                        testListener.WriteLine("\nTest Report: " + displayUrl, FacadeCategory.Info);
                    }
                }

                // Inform no tests run, if necessary.
                if (result.ResultCode == ResultCode.NoTests)
                {
                    InformNoTestsWereRun(testListener, Resources.MbUnitTestRunner_NoTestsFound);
                }
                else if (result.Statistics.TestCount == 0)
                {
                    InformNoTestsWereRun(testListener, null);
                }

                return GetTestRunState(result);
            }
            finally
            {
                RuntimeAccessor.Instance.RemoveLogListener(logger);
            }
        }
        public void FormatWritesTheTransformedReport()
        {
            string resourcePath = Path.Combine(Path.GetDirectoryName(AssemblyUtils.GetAssemblyLocalPath(GetType().Assembly)), @"..\Reports");

            IReportWriter reportWriter = Mocks.StrictMock<IReportWriter>();
            IReportContainer reportContainer = Mocks.StrictMock<IReportContainer>();
            IProgressMonitor progressMonitor = NullProgressMonitor.CreateInstance();

            string reportPath = SpecialPathPolicy.For<XsltReportFormatter>().CreateTempFileWithUniqueName().FullName;
            using (Stream tempFileStream = File.OpenWrite(reportPath))
            {
                using (Mocks.Record())
                {
                    SetupResult.For(reportWriter.ReportContainer).Return(reportContainer);

                    reportWriter.SerializeReport(null, AttachmentContentDisposition.Link);
                    LastCall.Constraints(Is.NotNull(), Is.Equal(AttachmentContentDisposition.Link))
                        .Do((SerializeReportDelegate)delegate(XmlWriter writer, AttachmentContentDisposition contentDisposition)
                        {
                            XmlDocument doc = new XmlDocument();
                            doc.InnerXml = "<report>The report.</report>";
                            doc.Save(writer);
                        });

                    SetupResult.For(reportContainer.ReportName).Return("Foo");
                    Expect.Call(reportContainer.OpenWrite("Foo.ext", MimeTypes.PlainText, new UTF8Encoding(false)))
                        .Return(tempFileStream);
                    reportWriter.AddReportDocumentPath("Foo.ext");

                    Expect.Call(reportContainer.OpenWrite(@"Foo\MbUnitLogo.png", MimeTypes.Png, null)).Return(new MemoryStream());

                    reportWriter.SaveReportAttachments(null);
                    LastCall.Constraints(Is.NotNull());
                }

                using (Mocks.Playback())
                {
                    XsltReportFormatter formatter = new XsltReportFormatter("ext", MimeTypes.PlainText, new DirectoryInfo(resourcePath), "Diagnostic.xslt", new string[] { "MbUnitLogo.png" });
                    var reportFormatterOptions = new ReportFormatterOptions();
                    reportFormatterOptions.AddProperty(XsltReportFormatter.AttachmentContentDispositionOption, AttachmentContentDisposition.Link.ToString());

                    formatter.Format(reportWriter, reportFormatterOptions, progressMonitor);

                    string reportContents = File.ReadAllText(reportPath);
                    TestLog.EmbedXml("Diagnostic report contents", reportContents);
                    Assert.Contains(reportContents, "<resourceRoot>Foo</resourceRoot>");
                    Assert.Contains(reportContents, "The report.");

                    File.Delete(reportPath);
                }
            }
        }
        /// <summary>
        /// Generates reports of the desired forms.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method adds the paths of the generated report documents to <see cref="ReportDocumentPaths" />.
        /// </para>
        /// </remarks>
        /// <param name="reportDirectory">The report directory.</param>
        /// <param name="reportName">The report name.</param>
        /// <param name="reportArchive">Determines whether to enclose the resulting test report in a compressed archive file.</param>
        /// <param name="reportFormats">The report formats to generate.</param>
        /// <param name="reportFormatOptions">The report formatter options.</param>
        /// <param name="reportManager">The report manager.</param>
        /// <param name="progressMonitor">A progress monitor for the operation.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="reportDirectory"/>,
        /// <paramref name="reportName"/>, <paramref name="reportFormats"/>, <paramref name="reportFormatOptions"/>,
        /// <paramref name="reportManager"/>, or <paramref name="progressMonitor"/> is null.</exception>
        public void GenerateReports(string reportDirectory, string reportName, ReportArchive reportArchive, IList<string> reportFormats,
            ReportFormatterOptions reportFormatOptions, IReportManager reportManager, IProgressMonitor progressMonitor)
        {
            if (reportDirectory == null)
                throw new ArgumentNullException("reportDirectory");
            if (reportName == null)
                throw new ArgumentNullException("reportName");
            if (reportFormats == null)
                throw new ArgumentNullException("reportFormats");
            if (reportFormatOptions == null)
                throw new ArgumentNullException("reportFormatOptions");
            if (reportManager == null)
                throw new ArgumentNullException("reportManager");
            if (progressMonitor == null)
                throw new ArgumentNullException("progressMonitor");

            var factory = new ReportContainerFactory(new FileSystem(), reportDirectory, reportName);

            using (progressMonitor.BeginTask("Generating reports.", reportFormats.Count))
            using (IReportContainer reportContainer = factory.MakeForSaving(reportArchive))
            {
                IReportWriter reportWriter = reportManager.CreateReportWriter(report, reportContainer);

                // Delete the report if it exists already.
                reportContainer.DeleteReport();

                // Format the report in all of the desired ways.
                foreach (string reportFormat in reportFormats)
                {
                    using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(1))
                        reportManager.Format(reportWriter, reportFormat, reportFormatOptions, subProgressMonitor);
                }

                // Save the full paths of the documents.
                foreach (string reportDocumentPath in reportWriter.ReportDocumentPaths)
                    AddReportDocumentPath(Path.Combine(reportDirectory, reportDocumentPath));
            }
        }
 /// <summary>
 /// Creates a copy of the options.
 /// </summary>
 /// <returns>The copy.</returns>
 public ReportFormatterOptions Copy()
 {
     var copy = new ReportFormatterOptions();
     copy.properties.AddAll(properties);
     return copy;
 }