Exemplo n.º 1
0
        static (XElement Document, XElement Footnotes) Execute([NotNull] XElement footnotes, [NotNull] XElement document, int footnoteId, int revisionId)
        {
            ReportVisitor visitor = new ReportVisitor();

            if (!(visitor.Visit(footnotes) is XElement visited))
            {
                throw new ArgumentException("This should never be thrown.");
            }

            XElement modifiedFootnotes =
                visited

                .RemoveByAll(W + "commentRangeStart")
                .RemoveByAll(W + "commentRangeEnd")
                .RemoveByAll(W + "commentReference")
                .RemoveByAll(x => (string)x.Attribute(W + "val") == "CommentReference")

                // Remove elements that should almost never exist.
                .RemoveByAll(x => x.Name == W + "jc" && !x.Ancestors(W + "tbl").Any())

                // Alter bold, italic, and underline elements.
                .ChangeBoldToStrong()
                .ChangeItalicToEmphasis()
                .ChangeUnderlineToTableCaption()
                .ChangeUnderlineToFigureCaption()
                .ChangeUnderlineToSourceNote()
                .ChangeSuperscriptToReference()

                // Mark insert requests for the production team.
                .MergeRuns()

                // Set table styles.
                .SetTableStyles(revisionId)

                // Remove elements used above, but not needed in the output.
                .RemoveByAll(W + "u")
                .RemoveByAllIfEmpty(W + "tcPr")
                .RemoveByAllIfEmpty(W + "rPr")
                .RemoveByAllIfEmpty(W + "pPr")
                .RemoveByAllIfEmpty(W + "t")
                .RemoveByAllIfEmpty(W + "r")
                .RemoveByAll(x => x.Name == W + "p" && !x.HasElements && x.Parent?.Name != W + "tc")
                .RemoveBy(x => (int)x.Attribute(W + "id") < 1);

            modifiedFootnotes.Descendants(W + "p")
            .Attributes()
            .Remove();

            // There shouldn't be more than one run style.
            foreach (XElement runProperties in modifiedFootnotes.Descendants(W + "rPr").Where(x => x.Elements(W + "rStyle").Count() > 1))
            {
                XElement[] styles =
                    runProperties.Elements(W + "rStyle")
                    .ToArray();

                styles.Remove();

                IEnumerable <XElement> distinct =
                    styles.Distinct(XNode.EqualityComparer)
                    .Cast <XElement>()
                    .ToArray();

                if (distinct.Any(x => (string)x.Attribute(W + "val") == "FootnoteReference"))
                {
                    distinct = distinct.Where(x => (string)x.Attribute(W + "val") == "FootnoteReference");
                }

                runProperties.AddFirst(distinct);
            }

            (int oldId, int newId)[] footnoteMapping =
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var arguments = new Dictionary <string, string>();

            for (var index = 0; index < args.Length; index = index + 2)
            {
                arguments.Add(args[index].Substring(1), args[index + 1]);
            }

            GraphClient.Connect();

            if (arguments.ContainsKey("dacpac"))
            {
                var databaseVisitor    = new DatabaseVisitor(GraphClient);
                var databaseServerNode = GetDatabaseServerNode(arguments["server"]);

                GraphClient.CreateRelationship(databaseServerNode, new DatabaseServerContainsDatabase(databaseVisitor.Visit(arguments["dacpac"])));
            }
            else if (arguments.ContainsKey("dacpac-references"))
            {
                var storedProcedureDependencyVisitor = new StoredProcedureDependencyVisitor(GraphClient);
                storedProcedureDependencyVisitor.Visit(arguments["dacpac-references"]);

                var viewDependencyVisitor = new ViewDependencyVisitor(GraphClient);
                viewDependencyVisitor.Visit(arguments["dacpac-references"]);
            }
            else if (arguments.ContainsKey("assembly"))
            {
                var assemblyVisitor = new AssemblyVisitor(GraphClient);
                GraphClient.CreateRelationship(GraphClient.RootNode, new RootContainsAssembly(assemblyVisitor.Visit(arguments["assembly"])));
            }
            else if (arguments.ContainsKey("reports"))
            {
                var reportVisitor    = new ReportVisitor(GraphClient);
                var reportServerNode = GetReportServerNode(arguments["server"]);

                var directory = new DirectoryInfo(arguments["reports"]);
                foreach (var report in directory.EnumerateFiles("*.rdl"))
                {
                    GraphClient.CreateRelationship(reportServerNode, new ReportServerContainsReport(reportVisitor.Visit(report.FullName)));
                }
            }
            else if (arguments.ContainsKey("dotnet"))
            {
                var projectVisitor = new DotNetProjectVisitor(GraphClient);
                projectVisitor.Visit(arguments["dotnet"]);
            }
        }