Exemplo n.º 1
0
 /// <inheritdoc />
 public void WithUpdatedContentPathsAndDisposition(AttachmentContentDisposition attachmentContentDisposition, Action action)
 {
     using (new UpdatedContentPathsAndDisposition(attachmentPathResolver, attachmentContentDisposition, report.TestPackageRun))
     {
         action();
     }
 }
Exemplo n.º 2
0
        /// <inheritdoc />
        public void SerializeReport(XmlWriter xmlWriter, AttachmentContentDisposition attachmentContentDisposition)
        {
            if (xmlWriter == null)
            {
                throw new ArgumentNullException(@"xmlWriter");
            }

            var ignoreAttributes = new XmlAttributes();

            ignoreAttributes.XmlIgnore = true;
            var overrides = new XmlAttributeOverrides();

            // Prune unnecessary ids that can be determined implicitly from the report structure.
            overrides.Add(typeof(TestStepData), @"ParentId", ignoreAttributes);

            // Only include content path when linking.
            if (attachmentContentDisposition != AttachmentContentDisposition.Link)
            {
                overrides.Add(typeof(AttachmentData), @"ContentPath", ignoreAttributes);
            }

            // Only include content data when inline.
            if (attachmentContentDisposition != AttachmentContentDisposition.Inline)
            {
                overrides.Add(typeof(AttachmentData), @"SerializedContents", ignoreAttributes);
            }

            WithUpdatedContentPathsAndDisposition(attachmentContentDisposition, () =>
            {
                // Serialize the report.
                var serializer = new XmlSerializer(typeof(Report), overrides);
                serializer.Serialize(xmlWriter, report);
            });
        }
        public UpdatedContentPathsAndDisposition(IAttachmentPathResolver attachmentPathResolver, AttachmentContentDisposition attachmentContentDisposition, TestPackageRun testPackageRun)
        {
            this.attachmentPathResolver = attachmentPathResolver;
            this.attachmentContentDisposition = attachmentContentDisposition;
            this.testPackageRun = testPackageRun;

            UpdateContentPathsAndDispositions();
        }
        public UpdatedContentPathsAndDisposition(IAttachmentPathResolver attachmentPathResolver, AttachmentContentDisposition attachmentContentDisposition, TestPackageRun testPackageRun)
        {
            this.attachmentPathResolver       = attachmentPathResolver;
            this.attachmentContentDisposition = attachmentContentDisposition;
            this.testPackageRun = testPackageRun;

            UpdateContentPathsAndDispositions();
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
        /// <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;
            }
        }
Exemplo n.º 7
0
        /// <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);
        }
Exemplo n.º 8
0
        /// <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);
                }
            }
        }
Exemplo n.º 9
0
        /// <inheritdoc />
        public override void Format(IReportWriter reportWriter, ReportFormatterOptions options, IProgressMonitor progressMonitor)
        {
            AttachmentContentDisposition attachmentContentDisposition = GetAttachmentContentDisposition(options);

            reportWriter.SaveReport(attachmentContentDisposition, progressMonitor);
        }
Exemplo n.º 10
0
 private static XPathDocument SerializeReportToXPathDocument(IReportWriter reportWriter,
     AttachmentContentDisposition attachmentContentDisposition)
 {
     return XmlUtils.WriteToXPathDocument(
         xmlWriter => reportWriter.SerializeReport(xmlWriter, attachmentContentDisposition));
 }
Exemplo n.º 11
0
        /// <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);
        }
Exemplo n.º 12
0
 /// <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);
 }
Exemplo n.º 13
0
 /// <inheritdoc />
 public void WithUpdatedContentPathsAndDisposition(AttachmentContentDisposition attachmentContentDisposition, Action action)
 {
     using (new UpdatedContentPathsAndDisposition(attachmentPathResolver, attachmentContentDisposition, report.TestPackageRun))
     {
         action();
     }
 }
Exemplo n.º 14
0
        /// <inheritdoc />
        public void SerializeReport(XmlWriter xmlWriter, AttachmentContentDisposition attachmentContentDisposition)
        {
            if (xmlWriter == null)
                throw new ArgumentNullException(@"xmlWriter");

            var ignoreAttributes = new XmlAttributes();
            ignoreAttributes.XmlIgnore = true;
            var overrides = new XmlAttributeOverrides();

            // Prune unnecessary ids that can be determined implicitly from the report structure.
            overrides.Add(typeof(TestStepData), @"ParentId", ignoreAttributes);

            // Only include content path when linking.
            if (attachmentContentDisposition != AttachmentContentDisposition.Link)
            {
                overrides.Add(typeof(AttachmentData), @"ContentPath", ignoreAttributes);
            }

            // Only include content data when inline.
            if (attachmentContentDisposition != AttachmentContentDisposition.Inline)
            {
                overrides.Add(typeof(AttachmentData), @"SerializedContents", ignoreAttributes);
            }

            WithUpdatedContentPathsAndDisposition(attachmentContentDisposition, () =>
            {
                // Serialize the report.
                var serializer = new XmlSerializer(typeof(Report), overrides);
                serializer.Serialize(xmlWriter, report);
            });
        }
Exemplo n.º 15
0
        /// <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;
            }
        }
Exemplo n.º 16
0
 private static XPathDocument SerializeReportToXPathDocument(IReportWriter reportWriter,
                                                             AttachmentContentDisposition attachmentContentDisposition)
 {
     return(XmlUtils.WriteToXPathDocument(
                xmlWriter => reportWriter.SerializeReport(xmlWriter, attachmentContentDisposition)));
 }