public void MakeForSaving_with_archive()
        {
            var mockFileSystem = MockRepository.GenerateStub <IFileSystem>();
            var factory        = new ReportContainerFactory(mockFileSystem, @"C:\Directory", "name");
            var container      = (AbstractReportContainer)factory.MakeForSaving(ReportArchive.Zip);

            Assert.IsInstanceOfType <ArchiveReportContainer>(container);
            Assert.AreEqual("name", container.ReportName);
            Assert.AreEqual(@"C:\Directory\", container.ReportDirectory);
        }
        public void MakeForReading_from_archive_file()
        {
            var mockFileSystem = MockRepository.GenerateMock <IFileSystem>();

            mockFileSystem.Expect(x => x.FileExists(@"C:\directory\name.zip")).Return(true);
            var factory   = new ReportContainerFactory(mockFileSystem, @"C:\directory", "name");
            var container = factory.MakeForReading();

            Assert.IsInstanceOfType <ArchiveReportContainer>(container);
            mockFileSystem.VerifyAllExpectations();
        }
        /// <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));
                    }
                }
        }
Exemple #4
0
        /// <summary>
        /// Saves the specified report.
        /// </summary>
        /// <param name="report"></param>
        /// <param name="reportArchive"></param>
        /// <param name="formatterName"></param>
        /// <param name="outputPath"></param>
        /// <param name="getOutputName"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        protected bool SaveReport(Report report, ReportArchive reportArchive, string formatterName, string outputPath, Func <string> getOutputName, ReportFormatterOptions options)
        {
            return(CaptureFileException(() => "The specified output directory is not a valid file path.", () =>
            {
                var factory = new ReportContainerFactory(new FileSystem(), outputPath, getOutputName());

                using (IReportContainer outputContainer = factory.MakeForSaving(reportArchive))
                {
                    IReportWriter reportWriter = reportManager.CreateReportWriter(report, outputContainer);
                    Context.ProgressMonitorProvider.Run(pm => reportManager.Format(reportWriter, formatterName, options, pm));
                    return true;
                }
            }));
        }
Exemple #5
0
        /// <summary>
        /// Loads the specified report.
        /// </summary>
        /// <param name="inputPath"></param>
        /// <param name="inputName"></param>
        /// <param name="report"></param>
        /// <returns></returns>
        protected bool LoadReport(string inputPath, string inputName, out Report report)
        {
            report = CaptureFileException(() => "The specified report is not a valid file path.", () =>
            {
                var factory = new ReportContainerFactory(new FileSystem(), inputPath, inputName);

                using (IReportContainer inputContainer = factory.MakeForReading())
                {
                    IReportReader reportReader = reportManager.CreateReportReader(inputContainer);
                    return(Context.ProgressMonitorProvider.Run(pm => reportReader.LoadReport(true, pm)));
                }
            });

            return(report != null);
        }