Exemplo n.º 1
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.º 2
0
        /// <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);
            }
        }
Exemplo n.º 3
0
        /// <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);
                }
            }
        }
Exemplo n.º 4
0
        /// <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;
            }
        }
Exemplo n.º 5
0
        /// <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;
            }
        }
Exemplo n.º 6
0
        /// <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;
            }
        }
Exemplo n.º 7
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.º 8
0
        /// <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);
                }
            }
        }