Exemplo n.º 1
0
        /// <inheritdoc />
        /// <summary>
        ///
        /// </summary>
        /// <param name="subject"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"/>
        protected override IOpenXmlVisitor Create(IOpenXmlVisitor subject)
        {
            if (subject is null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            return(new ReportVisitor(subject));
        }
Exemplo n.º 2
0
        protected override IOpenXmlVisitor VisitDocument(IOpenXmlVisitor subject, int revisionId)
        {
            if (subject is null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            return(Create(new DocumentVisit(subject, revisionId).Result));
        }
Exemplo n.º 3
0
        protected override IOpenXmlVisitor VisitNumbering(IOpenXmlVisitor subject)
        {
            if (subject is null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            return(new NumberingVisit(subject).Result);
        }
Exemplo n.º 4
0
        protected virtual IOpenXmlVisitor VisitFootnoteRelations([NotNull] IOpenXmlVisitor subject, int footnoteRelationId)
        {
            if (subject is null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            return(Create(subject));
        }
Exemplo n.º 5
0
        protected override IOpenXmlVisitor VisitFootnoteRelations(IOpenXmlVisitor subject, int footnoteRelationId)
        {
            if (subject is null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            return(new FootnoteRelationVisit(subject, footnoteRelationId).Result);
        }
Exemplo n.º 6
0
        protected virtual IOpenXmlVisitor VisitNumbering([NotNull] IOpenXmlVisitor subject)
        {
            if (subject is null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            return(Create(subject));
        }
Exemplo n.º 7
0
        protected virtual IOpenXmlVisitor VisitDocument([NotNull] IOpenXmlVisitor subject, int revisionId)
        {
            if (subject is null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            return(Create(subject));
        }
Exemplo n.º 8
0
        public virtual IOpenXmlVisitor Fold(IOpenXmlVisitor subject)
        {
            if (subject is null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            return(Create(StaticFold(this, subject)));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Marshals content from the source document to be added into the container.
        /// </summary>
        /// <param name="subject">The file from which content is copied.</param>
        /// <param name="revisionId">
        /// The current revision number incremented by one.
        /// </param>
        /// <returns>The updated document node of the source file.</returns>
        public DocumentVisit(IOpenXmlVisitor subject, int revisionId)
        {
            XElement document = Execute(subject.Document, revisionId);

            Result =
                new OpenXmlVisitor(
                    subject.ContentTypes,
                    document,
                    subject.DocumentRelations,
                    subject.Footnotes,
                    subject.FootnoteRelations,
                    subject.Styles,
                    subject.Numbering,
                    subject.Theme1,
                    subject.Charts);
        }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="subject"></param>
        public StyleVisit(IOpenXmlVisitor subject)
        {
            XElement styles = Execute(subject.Styles.Clone());

            Result =
                new OpenXmlVisitor(
                    subject.ContentTypes,
                    subject.Document,
                    subject.DocumentRelations,
                    subject.Footnotes,
                    subject.FootnoteRelations,
                    styles,
                    subject.Numbering,
                    subject.Theme1,
                    subject.Charts);
        }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="subject"></param>
        public NumberingVisit(IOpenXmlVisitor subject)
        {
            XElement numbering = Numbering.Clone();

            Result =
                new OpenXmlVisitor(
                    subject.ContentTypes,
                    subject.Document,
                    subject.DocumentRelations,
                    subject.Footnotes,
                    subject.FootnoteRelations,
                    subject.Styles,
                    numbering,
                    subject.Theme1,
                    subject.Charts);
        }
        /// <summary>
        /// Marshals footnotes from the source document into the container.
        /// </summary>
        /// <param name="subject">The file from which content is copied.</param>
        /// <param name="footnoteRelationId"></param>
        /// <returns>The updated document node of the source file.</returns>
        public FootnoteRelationVisit(IOpenXmlVisitor subject, int footnoteRelationId)
        {
            (var footnotes, var footnoteRelations) = Execute(subject.Footnotes, subject.FootnoteRelations, footnoteRelationId);

            Result =
                new OpenXmlVisitor(
                    subject.ContentTypes,
                    subject.Document,
                    subject.DocumentRelations,
                    footnotes,
                    footnoteRelations,
                    subject.Styles,
                    subject.Numbering,
                    subject.Theme1,
                    subject.Charts);
        }
Exemplo n.º 13
0
        public virtual IOpenXmlVisitor Visit(DocxFilePath file)
        {
            if (file is null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            IOpenXmlVisitor subject                 = new OpenXmlVisitor(file);
            IOpenXmlVisitor documentVisitor         = VisitDocument(subject, NextRevisionId);
            IOpenXmlVisitor footnoteVisitor         = VisitFootnotes(documentVisitor, NextFootnoteId, NextRevisionId);
            IOpenXmlVisitor documentRelationVisitor = VisitDocumentRelations(footnoteVisitor, NextDocumentRelationId);
            IOpenXmlVisitor footnoteRelationVisitor = VisitFootnoteRelations(documentRelationVisitor, NextFootnoteRelationId);
            IOpenXmlVisitor styleVisitor            = VisitStyles(footnoteRelationVisitor);
            IOpenXmlVisitor numberingVisitor        = VisitNumbering(styleVisitor);

            return(numberingVisitor);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new <see cref="OpenXmlVisitor"/> from an existing <see cref="IOpenXmlVisitor"/>.
        /// </summary>
        /// <param name="subject">
        /// The <see cref="IOpenXmlVisitor"/> to visit.
        /// </param>
        /// <exception cref="ArgumentNullException"/>
        public OpenXmlVisitor([NotNull] IOpenXmlVisitor subject)
        {
            if (subject is null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            Document          = subject.Document.Clone();
            DocumentRelations = subject.DocumentRelations.Clone();
            ContentTypes      = subject.ContentTypes.Clone();
            Footnotes         = subject.Footnotes.Clone();
            FootnoteRelations = subject.FootnoteRelations.Clone();
            Styles            = subject.Styles.Clone();
            Numbering         = subject.Numbering.Clone();
            Theme1            = subject.Theme1.Clone();
            Charts            = subject.Charts.Select(x => new ChartInformation(x.Name, x.Chart.Clone())).ToImmutableArray();
        }
Exemplo n.º 15
0
 /// <inheritdoc />
 /// <summary>
 /// Initialize a new <see cref="ReportVisitor"/> from the supplied <see cref="OpenXmlVisitor"/>.
 /// </summary>
 /// <param name="subject">
 /// The <see cref="OpenXmlVisitor"/> used to initialize the new <see cref="ReportVisitor"/>.
 /// </param>
 private ReportVisitor([NotNull] IOpenXmlVisitor subject) : base(subject)
 {
 }
Exemplo n.º 16
0
        private static OpenXmlVisitor StaticFold([NotNull] IOpenXmlVisitor source, [NotNull] IOpenXmlVisitor subject)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (subject is null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            XElement document =
                new XElement(
                    source.Document.Name,
                    source.Document.Attributes(),
                    new XElement(
                        source.Document.Elements().First().Name,
                        source.Document.Elements().First().Elements(),
                        subject.Document.Elements().First().Elements()));

            document = document.RemoveDuplicateSectionProperties();

            XElement footnotes =
                new XElement(
                    source.Footnotes.Name,
                    source.Footnotes.Attributes(),
                    source.Footnotes
                    .Elements()
                    .Union(
                        subject.Footnotes.Elements(),
                        XNode.EqualityComparer));

            XElement footnoteRelations =
                new XElement(
                    source.FootnoteRelations.Name,
                    source.FootnoteRelations.Attributes(),
                    source.FootnoteRelations
                    .Elements()
                    .Union(
                        subject.FootnoteRelations.Elements(),
                        XNode.EqualityComparer));

            XElement documentRelations =
                new XElement(
                    source.DocumentRelations.Name,
                    source.DocumentRelations.Attributes(),
                    source.DocumentRelations
                    .Elements()
                    .Union(
                        subject.DocumentRelations.Elements(),
                        XNode.EqualityComparer));

            XElement contentTypes =
                new XElement(
                    source.ContentTypes.Name,
                    source.ContentTypes.Attributes(),
                    source.ContentTypes
                    .Elements()
                    .Union(
                        subject.ContentTypes.Elements(),
                        XNode.EqualityComparer));

            XElement styles =
                new XElement(
                    source.Styles.Name,
                    source.Styles.Attributes(),
                    source.Styles
                    .Elements()
                    .Union(
                        subject.Styles
                        .Elements()
                        .Where(x => x.Name != W + "docDefaults")
                        .Where(x => (string)x.Attribute(W + "styleId") != "Normal"),
                        XNode.EqualityComparer));

            XElement numbering =
                new XElement(
                    source.Numbering.Name,
                    source.Numbering.Attributes(),
                    source.Numbering
                    .Elements()
                    .Union(
                        subject.Numbering.Elements(),
                        XNode.EqualityComparer));

            // TODO: write a ThemeVisit
//            XElement theme1 =
//                new XElement(
//                    source.Theme1.Name,
//                    source.Theme1.Attributes(),
//                    source.Theme1
//                          .Elements()
//                          .Union(
//                              subject.Theme1.Elements(),
//                              XNode.EqualityComparer));

            IEnumerable <ChartInformation> charts =
                source.Charts
                .Union(
                    subject.Charts,
                    ChartInformation.Comparer);

            return
                (new OpenXmlVisitor(
                     contentTypes,
                     document,
                     documentRelations,
                     footnotes,
                     footnoteRelations,
                     styles,
                     numbering,
                     subject.Theme1,
                     charts));
        }