Пример #1
0
        public static void GenerateRedirectFile(
            string solutionDestinationFolder,
            string projectDestinationFolder,
            Dictionary <string, IEnumerable <string> > symbolIDToListOfLocationsMap,
            string prefix = "")
        {
            var fileName = Path.Combine(projectDestinationFolder, Constants.IDResolvingFileName + prefix + ".html");

            File.Delete(fileName);
            using (var writer = new StreamWriter(fileName, append: false, encoding: Encoding.UTF8))
            {
                Markup.WriteMetadataToSourceRedirectPrefix(writer);

                if (prefix == "")
                {
                    writer.WriteLine("redirectToNextLevelRedirectFile();");

                    var maps = SplitByFirstLetter(symbolIDToListOfLocationsMap);
                    foreach (var map in maps)
                    {
                        GenerateRedirectFile(
                            solutionDestinationFolder,
                            projectDestinationFolder,
                            map.Value,
                            map.Key.ToString());
                    }
                }
                else
                {
                    WriteMapping(
                        writer,
                        solutionDestinationFolder,
                        projectDestinationFolder,
                        symbolIDToListOfLocationsMap);
                }

                Markup.WriteMetadataToSourceRedirectSuffix(writer);
            }
        }
Пример #2
0
        private string GenerateHeader(Action <string> writeLine)
        {
            string documentDisplayName = documentRelativeFilePathWithoutHtmlExtension;
            string documentUrl         = "/#" + Document.Project.AssemblyName + "/" + documentRelativeFilePathWithoutHtmlExtension.Replace('\\', '/');
            string projectDisplayName  = projectGenerator.ProjectSourcePath;
            string projectUrl          = "/#" + Document.Project.AssemblyName;

            string documentLink = string.Format("File: <a id=\"filePath\" class=\"blueLink\" href=\"{0}\" target=\"_top\">{1}</a><br/>", documentUrl, documentDisplayName);
            string projectLink  = string.Format("Project: <a id=\"projectPath\" class=\"blueLink\" href=\"{0}\" target=\"_top\">{1}</a> ({2})", projectUrl, projectDisplayName, projectGenerator.AssemblyName);

            string fileShareLink = GetFileShareLink();

            if (fileShareLink != null)
            {
                fileShareLink = Markup.A(fileShareLink, "File", "_blank");
            }
            else
            {
                fileShareLink = "";
            }

            string webLink = GetWebLink();

            if (webLink != null)
            {
                webLink = Markup.A(webLink, "Web&nbsp;Access", "_blank");
            }
            else
            {
                webLink = "";
            }

            string firstRow  = string.Format("<tr><td>{0}</td><td>{1}</td></tr>", documentLink, webLink);
            string secondRow = string.Format("<tr><td>{0}</td><td>{1}</td></tr>", projectLink, fileShareLink);

            Markup.WriteLinkPanel(writeLine, firstRow, secondRow);

            return(documentUrl);
        }
Пример #3
0
        private void DeployFilesToRoot(string destinationFolder)
        {
            Markup.WriteReferencesNotFoundFile(destinationFolder);

            string sourcePath = Assembly.GetEntryAssembly().Location;

            sourcePath = Path.GetDirectoryName(sourcePath);
            string basePath = sourcePath;

            sourcePath = Path.Combine(sourcePath, @"Web");
            if (!Directory.Exists(sourcePath))
            {
                return;
            }

            sourcePath = Path.GetFullPath(sourcePath);
            FileUtilities.CopyDirectory(sourcePath, destinationFolder);

            StampOverviewHtmlWithDate(destinationFolder);

            DeployBin(basePath, destinationFolder);
        }
Пример #4
0
        private void GenerateDeclarations()
        {
            Log.Write("Declarations...");

            var lines = new List <string>();

            if (DeclaredSymbols != null)
            {
                foreach (var declaredSymbol in DeclaredSymbols
                         .OrderBy(s => SymbolIdService.GetName(s.Key))
                         .ThenBy(s => s.Value))
                {
                    lines.Add(string.Join(";",
                                          SymbolIdService.GetName(declaredSymbol.Key),                                   // symbol name
                                          declaredSymbol.Value,                                                          // 8-byte symbol ID
                                          SymbolKindText.GetSymbolKind(declaredSymbol.Key),                              // kind (e.g. "class")
                                          Markup.EscapeSemicolons(SymbolIdService.GetDisplayString(declaredSymbol.Key)), // symbol full name and signature
                                          SymbolIdService.GetGlyphNumber(declaredSymbol.Key)));                          // icon number
                }
            }

            if (OtherFiles != null)
            {
                foreach (var document in OtherFiles.OrderBy(d => d))
                {
                    lines.Add(string.Join(";",
                                          Path.GetFileName(document),
                                          SymbolIdService.GetId(document),
                                          "file",
                                          Markup.EscapeSemicolons(document),
                                          Serialization.GetIconForExtension(document)));
                }
            }

            Serialization.WriteDeclaredSymbols(ProjectDestinationFolder, lines);
        }
Пример #5
0
        private void WriteBaseMember(ulong symbolId, StreamWriter writer)
        {
            if (!BaseMembers.TryGetValue(symbolId, out Tuple <string, ulong> baseMemberLink))
            {
                return;
            }

            Write(writer, @"<div class=""rH"">Base:</div>");

            var assemblyName = baseMemberLink.Item1;
            var baseSymbolId = baseMemberLink.Item2;

            if (!this.SolutionFinalizer.assemblyNameToProjectMap.TryGetValue(assemblyName, out ProjectFinalizer baseProject))
            {
                return;
            }

            if (baseProject.DeclaredSymbols.TryGetValue(baseSymbolId, out DeclaredSymbolInfo symbol))
            {
                var sb = new StringBuilder();
                Markup.WriteSymbol(symbol, sb);
                writer.Write(sb.ToString());
            }
        }
Пример #6
0
        private string AddIdSpanForImplicitConstructorIfNecessary(HtmlElementInfo hyperlinkInfo, string html)
        {
            if (hyperlinkInfo?.DeclaredSymbol != null)
            {
                if (hyperlinkInfo.DeclaredSymbol is INamedTypeSymbol namedTypeSymbol)
                {
                    var implicitInstanceConstructor = namedTypeSymbol.Constructors.FirstOrDefault(c => !c.IsStatic && c.IsImplicitlyDeclared);
                    if (implicitInstanceConstructor != null)
                    {
                        var symbolId = SymbolIdService.GetId(implicitInstanceConstructor);
                        html = Markup.Tag("span", html, new Dictionary <string, string> {
                            { "id", symbolId }
                        });
                        projectGenerator.AddDeclaredSymbol(
                            implicitInstanceConstructor,
                            symbolId,
                            documentRelativeFilePathWithoutHtmlExtension,
                            0);
                    }
                }
            }

            return(html);
        }
Пример #7
0
        public void Generate(string sourceXmlFilePath, string destinationHtmlFilePath, string solutionDestinationFolder)
        {
            Log.Write(destinationHtmlFilePath);

            this.sourceXmlFilePath       = Path.GetFullPath(sourceXmlFilePath);
            this.destinationHtmlFilePath = destinationHtmlFilePath;

            sourceText = File.ReadAllText(sourceXmlFilePath);
            var lines = File.ReadAllLines(sourceXmlFilePath);

            lineLengths = TextUtilities.GetLineLengths(sourceText);
            var lineCount = lines.Length;
            var root      = Parser.ParseText(sourceText);

            var sb = new StringBuilder();

            var relativePathToRoot = Paths.CalculateRelativePathToRoot(destinationHtmlFilePath, solutionDestinationFolder);

            var prefix = Markup.GetDocumentPrefix(Path.GetFileName(sourceXmlFilePath), relativePathToRoot, lineCount, "ix");

            sb.Append(prefix);

            var displayName  = GetDisplayName();
            var assemblyName = GetAssemblyName();

            var url = "/#" + assemblyName + "/" + displayName.Replace('\\', '/');

            var file = string.Format("File: <a id=\"filePath\" class=\"blueLink\" href=\"{0}\" target=\"_top\">{1}</a><br/>", url, displayName);
            var row  = string.Format("<tr><td>{0}</td></tr>", file);

            Markup.WriteLinkPanel(s => sb.AppendLine(s), row);

            // pass a value larger than 0 to generate line numbers statically at HTML generation time
            var table = Markup.GetTablePrefix();

            sb.AppendLine(table);

            var ranges = new List <ClassifiedRange>();

            ClassifierVisitor.Visit(
                root,
                0,
                sourceText.Length,
                (start, length, node, classification) =>
            {
                var line     = TextUtilities.GetLineFromPosition(start, sourceText);
                var lineText = sourceText.Substring(line.Item1, line.Item2);

                ranges.Add(
                    new ClassifiedRange
                {
                    Classification = classification,
                    Node           = node,
                    Text           = sourceText.Substring(start, length),
                    LineText       = lineText,
                    LineStart      = line.Item1,
                    LineNumber     = TextUtilities.GetLineNumber(start, lineLengths),
                    Start          = start,
                    Length         = length
                });
            });

            ranges = RangeUtilities.FillGaps(
                sourceText,
                ranges,
                r => r.Start,
                r => r.Length,
                (s, l, t) => new ClassifiedRange
            {
                Start  = s,
                Length = l,
                Text   = t.Substring(s, l)
            }).ToList();
            foreach (var range in ranges)
            {
                GenerateRange(range, sb);
            }

            var suffix = Markup.GetDocumentSuffix();

            sb.AppendLine(suffix);

            var folder = Path.GetDirectoryName(destinationHtmlFilePath);

            Directory.CreateDirectory(folder);
            File.WriteAllText(destinationHtmlFilePath, sb.ToString());
        }
Пример #8
0
 protected virtual string ProcessRange(ClassifiedRange range, string text)
 {
     text = Markup.HtmlEscape(text);
     return(text);
 }
        private string GenerateRange(StreamWriter writer, Classification.Range range, int lineCount = 0)
        {
            var html = range.Text;

            html = Markup.HtmlEscape(html);
            bool            isLargeFile         = IsLargeFile(lineCount);
            string          classAttributeValue = GetClassAttribute(html, range);
            HtmlElementInfo hyperlinkInfo       = GenerateLinks(range, isLargeFile);

            if (hyperlinkInfo == null)
            {
                if (classAttributeValue == null || isLargeFile)
                {
                    return(html);
                }

                if (classAttributeValue == "k")
                {
                    return("<b>" + html + "</b>");
                }
            }

            var sb = new StringBuilder();

            var elementName = "span";

            if (hyperlinkInfo != null)
            {
                elementName = hyperlinkInfo.Name;
            }

            sb.Append("<" + elementName);
            bool overridingClassAttributeSpecified = false;

            if (hyperlinkInfo != null)
            {
                foreach (var attribute in hyperlinkInfo.Attributes)
                {
                    AddAttribute(sb, attribute.Key, attribute.Value);
                    if (attribute.Key == "class")
                    {
                        overridingClassAttributeSpecified = true;
                    }
                }
            }

            if (!overridingClassAttributeSpecified)
            {
                AddAttribute(sb, "class", classAttributeValue);
            }

            sb.Append('>');

            html = AddIdSpanForImplicitConstructorIfNecessary(hyperlinkInfo, html);

            sb.Append(html);
            sb.Append("</" + elementName + ">");

            html = sb.ToString();

            if (hyperlinkInfo != null && hyperlinkInfo.DeclaredSymbol != null)
            {
                writer.Flush();
                long streamPosition = writer.BaseStream.Length;

                streamPosition += html.IndexOf(hyperlinkInfo.Attributes["id"] + ".html");
                projectGenerator.AddDeclaredSymbol(
                    hyperlinkInfo.DeclaredSymbol,
                    hyperlinkInfo.DeclaredSymbolId,
                    documentRelativeFilePathWithoutHtmlExtension,
                    streamPosition);
            }

            return(html);
        }
        public void AddReference(
            string documentDestinationPath,
            string lineText,
            int referenceStartOnLine,
            int referenceLength,
            int lineNumber,
            string fromAssemblyName,
            string toAssemblyName,
            ISymbol symbol,
            string symbolId,
            ReferenceKind kind)
        {
            string localPath = Paths.MakeRelativeToFolder(
                documentDestinationPath,
                Path.Combine(SolutionGenerator.SolutionDestinationFolder, fromAssemblyName));

            localPath = Path.ChangeExtension(localPath, null);

            int referenceEndOnLine = referenceStartOnLine + referenceLength;

            lineText = Markup.HtmlEscape(lineText, ref referenceStartOnLine, ref referenceEndOnLine);

            string symbolName = GetSymbolName(symbol, symbolId);

            var reference = new Reference()
            {
                ToAssemblyId         = toAssemblyName,
                ToSymbolId           = symbolId,
                ToSymbolName         = symbolName,
                FromAssemblyId       = fromAssemblyName,
                FromLocalPath        = localPath,
                ReferenceLineText    = lineText,
                ReferenceLineNumber  = lineNumber,
                ReferenceColumnStart = referenceStartOnLine,
                ReferenceColumnEnd   = referenceEndOnLine,
                Kind = kind
            };

            if (referenceStartOnLine < 0 ||
                referenceStartOnLine >= referenceEndOnLine ||
                referenceEndOnLine > lineText.Length)
            {
                Log.Exception(
                    string.Format("AddReference: start = {0}, end = {1}, lineText = {2}, documentDestinationPath = {3}",
                                  referenceStartOnLine,
                                  referenceEndOnLine,
                                  lineText,
                                  documentDestinationPath));
            }

            string linkRelativePath = GetLinkRelativePath(reference);

            reference.Url = linkRelativePath;

            Dictionary <string, List <Reference> > referencesToAssembly = GetReferencesToAssembly(reference.ToAssemblyId);
            List <Reference> referencesToSymbol = GetReferencesToSymbol(reference, referencesToAssembly);

            lock (referencesToSymbol)
            {
                referencesToSymbol.Add(reference);
            }
        }
Пример #11
0
        private void PatchProjectExplorer(ProjectFinalizer project)
        {
            if (project.ReferencingAssemblies.Count == 0 || project.ReferencingAssemblies.Count > 100)
            {
                return;
            }

            var fileName = Path.Combine(project.ProjectDestinationFolder, Constants.ProjectExplorer + ".html");

            if (!File.Exists(fileName))
            {
                return;
            }

            var           sourceLines = File.ReadAllLines(fileName);
            List <string> lines       = new List <string>(sourceLines.Length + project.ReferencingAssemblies.Count + 2);

            RelativeState state = RelativeState.Before;

            foreach (var sourceLine in sourceLines)
            {
                switch (state)
                {
                case RelativeState.Before:
                    if (sourceLine == "<div class=\"folderTitle\">References</div><div class=\"folder\">")
                    {
                        state = RelativeState.Inside;
                    }

                    break;

                case RelativeState.Inside:
                    if (sourceLine == "</div>")
                    {
                        state = RelativeState.InsertionPoint;
                    }

                    break;

                case RelativeState.InsertionPoint:
                    lines.Add("<div class=\"folderTitle\">Used By</div><div class=\"folder\">");

                    foreach (var referencingAssembly in project.ReferencingAssemblies)
                    {
                        string referenceHtml = Markup.GetProjectExplorerReference("/#" + referencingAssembly, referencingAssembly);
                        lines.Add(referenceHtml);
                    }

                    lines.Add("</div>");

                    state = RelativeState.After;
                    break;

                case RelativeState.After:
                    break;

                default:
                    break;
                }

                lines.Add(sourceLine);
            }

            File.WriteAllLines(fileName, lines);
        }
Пример #12
0
        private HtmlElementInfo GenerateLinks(ClassifiedRange range, string destinationHtmlFilePath, Dictionary <string, int> localSymbolIdMap)
        {
            HtmlElementInfo result = null;

            var localRelativePath = destinationHtmlFilePath.Substring(
                Path.Combine(
                    Paths.SolutionDestinationFolder,
                    Constants.TypeScriptFiles).Length);

            if (!string.IsNullOrEmpty(range.definitionSymbolId))
            {
                var definitionSymbolId = SymbolIdService.GetId(range.definitionSymbolId);

                if (range.IsSymbolLocalOnly())
                {
                    var localId = GetLocalId(definitionSymbolId, localSymbolIdMap);
                    result = new HtmlElementInfo
                    {
                        Name       = "span",
                        Attributes =
                        {
                            { "id",    "r" + localId + " rd" },
                            { "class", "r" + localId + " r"  }
                        }
                    };
                    return(result);
                }

                result = new HtmlElementInfo
                {
                    Name       = "a",
                    Attributes =
                    {
                        { "id",     definitionSymbolId                                                                      },
                        { "href",   "/TypeScriptFiles/" + Constants.ReferencesFileName + "/" + definitionSymbolId + ".html" },
                        { "target", "n"                                                                                     }
                    }
                };

                var searchString = range.searchString;
                if (!string.IsNullOrEmpty(searchString) && searchString.Length > 2)
                {
                    lock (declarations)
                    {
                        searchString = searchString.StripQuotes();
                        if (IsWellFormed(searchString))
                        {
                            var declaration = string.Join(";",
                                                          searchString,                            // symbol name
                                                          definitionSymbolId,                      // 8-byte symbol ID
                                                          range.definitionKind,                    // kind (e.g. "class")
                                                          Markup.EscapeSemicolons(range.fullName), // symbol full name and signature
                                                          GetGlyph(range.definitionKind)           // glyph number
                                                          );
                            declarations.Add(declaration);
                        }
                    }
                }
            }

            if (range.hyperlinks == null || range.hyperlinks.Length == 0)
            {
                return(result);
            }

            var hyperlink = range.hyperlinks[0];
            var symbolId  = SymbolIdService.GetId(hyperlink.symbolId);

            if (range.IsSymbolLocalOnly() || localSymbolIdMap.ContainsKey(symbolId))
            {
                var localId = GetLocalId(symbolId, localSymbolIdMap);
                result = new HtmlElementInfo
                {
                    Name       = "span",
                    Attributes =
                    {
                        { "class", "r" + localId + " r" }
                    }
                };
                return(result);
            }

            var hyperlinkDestinationFile = Path.GetFullPath(hyperlink.sourceFile);

            hyperlinkDestinationFile = GetDestinationFilePath(hyperlinkDestinationFile);

            string href = "";

            if (!string.Equals(hyperlinkDestinationFile, destinationHtmlFilePath, StringComparison.OrdinalIgnoreCase))
            {
                href = Paths.MakeRelativeToFile(hyperlinkDestinationFile, destinationHtmlFilePath);
                href = href.Replace('\\', '/');
            }

            href = href + "#" + symbolId;

            if (result == null)
            {
                result = new HtmlElementInfo
                {
                    Name       = "a",
                    Attributes =
                    {
                        { "href",   href },
                        { "target", "s"  },
                    }
                };
            }
            else if (!result.Attributes.ContainsKey("href"))
            {
                result.Attributes.Add("href", href);
                result.Attributes.Add("target", "s");
            }

            lock (this.references)
            {
                var lineNumber      = range.lineNumber + 1;
                var linkToReference = ".." + localRelativePath + "#" + lineNumber.ToString();
                var start           = range.column;
                var end             = range.column + range.text.Length;
                var lineText        = Markup.HtmlEscape(range.lineText, ref start, ref end);
                var reference       = new Reference
                {
                    FromAssemblyId       = Constants.TypeScriptFiles,
                    ToAssemblyId         = Constants.TypeScriptFiles,
                    FromLocalPath        = localRelativePath.Substring(0, localRelativePath.Length - ".html".Length).Replace('\\', '/'),
                    Kind                 = ReferenceKind.Reference,
                    ToSymbolId           = symbolId,
                    ToSymbolName         = range.text,
                    ReferenceLineNumber  = lineNumber,
                    ReferenceLineText    = lineText,
                    ReferenceColumnStart = start,
                    ReferenceColumnEnd   = end,
                    Url = linkToReference.Replace('\\', '/')
                };

                if (!references.TryGetValue(symbolId, out List <Reference> bucket))
                {
                    bucket = new List <Reference>();
                    references.Add(symbolId, bucket);
                }

                bucket.Add(reference);
            }

            return(result);
        }
Пример #13
0
        private void GenerateRange(
            StringBuilder sb,
            ClassifiedRange range,
            string destinationFilePath,
            Dictionary <string, int> localSymbolIdMap)
        {
            var html = range.text;

            html = Markup.HtmlEscape(html);

            var localRelativePath = destinationFilePath.Substring(
                Path.Combine(
                    Paths.SolutionDestinationFolder,
                    Constants.TypeScriptFiles).Length + 1);

            localRelativePath = localRelativePath.Substring(0, localRelativePath.Length - ".html".Length);

            string          classAttributeValue = GetSpanClass(range.classification);
            HtmlElementInfo hyperlinkInfo       = GenerateLinks(range, destinationFilePath, localSymbolIdMap);

            if (hyperlinkInfo == null)
            {
                if (classAttributeValue == null)
                {
                    sb.Append(html);
                    return;
                }

                if (classAttributeValue == "k")
                {
                    sb.Append("<b>").Append(html).Append("</b>");
                    return;
                }
            }

            var elementName = "span";

            if (hyperlinkInfo != null)
            {
                elementName = hyperlinkInfo.Name;
            }

            sb.Append("<").Append(elementName);
            bool overridingClassAttributeSpecified = false;

            if (hyperlinkInfo != null)
            {
                foreach (var attribute in hyperlinkInfo.Attributes)
                {
                    const string typeScriptFilesR = "/TypeScriptFiles/R/";
                    if (attribute.Key == "href" && attribute.Value.StartsWith(typeScriptFilesR, StringComparison.Ordinal))
                    {
                        var streamPosition = sb.Length + 7 + typeScriptFilesR.Length; // exact offset into <a href="HERE
                        ProjectGenerator.AddDeclaredSymbolToRedirectMap(
                            SymbolIDToListOfLocationsMap,
                            attribute.Value.Substring(typeScriptFilesR.Length, 16),
                            localRelativePath,
                            streamPosition);
                    }

                    AddAttribute(sb, attribute.Key, attribute.Value);
                    if (attribute.Key == "class")
                    {
                        overridingClassAttributeSpecified = true;
                    }
                }
            }

            if (!overridingClassAttributeSpecified)
            {
                AddAttribute(sb, "class", classAttributeValue);
            }

            sb.Append('>');

            sb.Append(html);
            sb.Append("</").Append(elementName).Append(">");
        }
Пример #14
0
        private void GenerateReferencesFile(string referencesFile)
        {
            string[] referencesLines   = File.ReadAllLines(referencesFile, Encoding.UTF8);
            string   rawReferencesFile = referencesFile;

            referencesFile = Path.ChangeExtension(referencesFile, ".html");

            var referenceKindGroups = CreateReferences(referencesLines, out int totalReferenceCount, out string symbolName);

            using (var writer = new StreamWriter(referencesFile, append: false, encoding: Encoding.UTF8))
            {
                Markup.WriteReferencesFileHeader(writer, symbolName);

                if (this.AssemblyId != Constants.MSBuildItemsAssembly &&
                    this.AssemblyId != Constants.MSBuildPropertiesAssembly &&
                    this.AssemblyId != Constants.MSBuildTargetsAssembly &&
                    this.AssemblyId != Constants.MSBuildTasksAssembly &&
                    this.AssemblyId != Constants.GuidAssembly)
                {
                    string symbolId = Path.GetFileNameWithoutExtension(referencesFile);
                    var    id       = Serialization.HexStringToULong(symbolId);
                    WriteBaseMember(id, writer);
                    WriteImplementedInterfaceMembers(id, writer);
                }

                foreach (var referenceKind in referenceKindGroups.OrderBy(t => (int)t.Item1))
                {
                    string formatString = "";

                    switch (referenceKind.Item1)
                    {
                    case ReferenceKind.Reference:
                        formatString = "{0} reference{1} to {2}";
                        break;

                    case ReferenceKind.DerivedType:
                        formatString = "{0} type{1} derived from {2}";
                        break;

                    case ReferenceKind.InterfaceInheritance:
                        formatString = "{0} interface{1} inheriting from {2}";
                        break;

                    case ReferenceKind.InterfaceImplementation:
                        formatString = "{0} implementation{1} of {2}";
                        break;

                    case ReferenceKind.Read:
                        formatString = "{0} read{1} of {2}";
                        break;

                    case ReferenceKind.Write:
                        formatString = "{0} write{1} to {2}";
                        break;

                    case ReferenceKind.Instantiation:
                        formatString = "{0} instantiation{1} of {2}";
                        break;

                    case ReferenceKind.Override:
                        formatString = "{0} override{1} of {2}";
                        break;

                    case ReferenceKind.InterfaceMemberImplementation:
                        formatString = "{0} implementation{1} of {2}";
                        break;

                    case ReferenceKind.GuidUsage:
                        formatString = "{0} usage{1} of Guid {2}";
                        break;

                    case ReferenceKind.EmptyArrayAllocation:
                        formatString = "{0} allocation{1} of empty arrays";
                        break;

                    case ReferenceKind.MSBuildPropertyAssignment:
                        formatString = "{0} assignment{1} to MSBuild property {2}";
                        break;

                    case ReferenceKind.MSBuildPropertyUsage:
                        formatString = "{0} usage{1} of MSBuild property {2}";
                        break;

                    case ReferenceKind.MSBuildItemAssignment:
                        formatString = "{0} assignment{1} to MSBuild item {2}";
                        break;

                    case ReferenceKind.MSBuildItemUsage:
                        formatString = "{0} usage{1} of MSBuild item {2}";
                        break;

                    case ReferenceKind.MSBuildTargetDeclaration:
                        formatString = "{0} declaration{1} of MSBuild target {2}";
                        break;

                    case ReferenceKind.MSBuildTargetUsage:
                        formatString = "{0} usage{1} of MSBuild target {2}";
                        break;

                    case ReferenceKind.MSBuildTaskDeclaration:
                        formatString = "{0} import{1} of MSBuild task {2}";
                        break;

                    case ReferenceKind.MSBuildTaskUsage:
                        formatString = "{0} call{1} to MSBuild task {2}";
                        break;

                    default:
                        throw new NotImplementedException("Missing case for " + referenceKind.Item1);
                    }

                    var referencesOfSameKind = referenceKind.Item2.OrderBy(g => g.Item1);
                    totalReferenceCount = CountItems(referenceKind);
                    string headerText = string.Format(
                        formatString,
                        totalReferenceCount,
                        totalReferenceCount == 1 ? "" : "s",
                        symbolName);

                    Write(writer, string.Format(@"<div class=""rH"">{0}</div>", headerText));

                    foreach (var sameAssemblyReferencesGroup in referencesOfSameKind)
                    {
                        string assemblyName = sameAssemblyReferencesGroup.Item1;
                        Write(writer, "<div class=\"rA\">{0} ({1})</div>", assemblyName, CountItems(sameAssemblyReferencesGroup));
                        Write(writer, "<div class=\"rG\" id=\"{0}\">", assemblyName);

                        foreach (var sameFileReferencesGroup in sameAssemblyReferencesGroup.Item2.OrderBy(g => g.Item1))
                        {
                            Write(writer, "<div class=\"rF\">");
                            WriteLine(writer, "<div class=\"rN\">{0} ({1})</div>", sameFileReferencesGroup.Item1, CountItems(sameFileReferencesGroup));

                            foreach (var sameLineReferencesGroup in sameFileReferencesGroup.Item2)
                            {
                                var url = sameLineReferencesGroup.First().Url;
                                Write(writer, "<a href=\"{0}\">", url);

                                Write(writer, "<b>{0}</b>", sameLineReferencesGroup.Key);
                                MergeOccurrences(writer, sameLineReferencesGroup);
                                WriteLine(writer, "</a>");
                            }

                            WriteLine(writer, "</div>");
                        }

                        WriteLine(writer, "</div>");
                    }
                }

                Write(writer, "</body></html>");
            }

            File.Delete(rawReferencesFile);
        }
Пример #15
0
 public void CreateReferencesFiles()
 {
     BackpatchUnreferencedDeclarations(referencesFolder);
     Markup.WriteRedirectFile(ProjectDestinationFolder);
     GenerateFinalReferencesFiles(referencesFolder);
 }
Пример #16
0
        private string ProcessExpressions(ClassifiedRange range, string text, bool isRootProject, Func <ClassifiedRange, string, bool, int, string> customStringProcessor = null)
        {
            var parts = MSBuildExpressionParser.SplitStringByPropertiesAndItems(text);

            if (parts.Count() == 1 && !text.StartsWith("$(", StringComparison.Ordinal) && !text.StartsWith("@(", StringComparison.Ordinal))
            {
                var processed = text;
                if (customStringProcessor != null)
                {
                    return(customStringProcessor(range, processed, isRootProject, range.Start));
                }
                else
                {
                    return(Markup.HtmlEscape(processed));
                }
            }

            var sb          = new StringBuilder();
            int lengthSoFar = 0;

            foreach (var part in parts)
            {
                if (part.StartsWith("$(", StringComparison.Ordinal) && part.EndsWith(")", StringComparison.Ordinal) && part.Length > 3)
                {
                    var    propertyName = part.Substring(2, part.Length - 3);
                    string suffix       = "";
                    int    dot          = propertyName.IndexOf('.');
                    if (dot > -1)
                    {
                        suffix       = propertyName.Substring(dot);
                        propertyName = propertyName.Substring(0, dot);
                    }

                    var currentPosition = range.Start + lengthSoFar;
                    var line            = TextUtilities.GetLineFromPosition(currentPosition, sourceText);
                    var lineNumber      = TextUtilities.GetLineNumber(currentPosition, this.lineLengths);
                    var lineText        = sourceText.Substring(line.Item1, line.Item2);
                    var url             = ProcessPropertyName(
                        lineText,
                        lineNumber + 1,
                        currentPosition - line.Item1 + 2,
                        propertyName,
                        isRootProject,
                        isUsage: true);

                    sb.Append("$(" + url + Markup.HtmlEscape(suffix) + ")");
                }
                else if (
                    part.StartsWith("@(", StringComparison.Ordinal) &&
                    (part.EndsWith(")", StringComparison.Ordinal) || part.EndsWith("-", StringComparison.Ordinal) || part.EndsWith(",", StringComparison.Ordinal)) &&
                    !part.Contains("%") &&
                    part.Length > 3)
                {
                    const int suffixLength = 1;
                    var       itemName     = part.Substring(2, part.Length - 2 - suffixLength);
                    string    suffix       = part.Substring(part.Length - suffixLength, suffixLength);

                    var currentPosition = range.Start + lengthSoFar;
                    var line            = TextUtilities.GetLineFromPosition(currentPosition, sourceText);
                    var lineNumber      = TextUtilities.GetLineNumber(currentPosition, this.lineLengths);
                    var lineText        = sourceText.Substring(line.Item1, line.Item2);
                    var url             = ProcessItemName(
                        lineText,
                        lineNumber + 1,
                        currentPosition - line.Item1 + 2,
                        itemName,
                        isRootProject,
                        isUsage: true);

                    sb.Append("@(").Append(url).Append(Markup.HtmlEscape(suffix));
                }
                else
                {
                    var processed = part;
                    if (customStringProcessor != null)
                    {
                        var currentPosition = range.Start + lengthSoFar;
                        processed = customStringProcessor(range, processed, isRootProject, currentPosition);
                    }
                    else
                    {
                        processed = Markup.HtmlEscape(processed);
                    }

                    sb.Append(processed);
                }

                lengthSoFar += part.Length;
            }

            return(sb.ToString());
        }
        private string GetHtml(string sourceXmlFilePath, string destinationHtmlFilePath, string displayName)
        {
            var lines = File.ReadAllLines(sourceXmlFilePath);

            lineLengths = sourceText.GetLineLengths();
            var lineCount = lines.Length;

            var sb = new StringBuilder();

            var relativePathToRoot = Paths.CalculateRelativePathToRoot(destinationHtmlFilePath, ProjectGenerator.SolutionGenerator.SolutionDestinationFolder);

            var prefix = Markup.GetDocumentPrefix(Path.GetFileName(sourceXmlFilePath), relativePathToRoot, lineCount, "ix");

            sb.Append(prefix);

            var assemblyName = GetAssemblyName();

            var url = "/#" + assemblyName + "/" + displayName.Replace('\\', '/');

            Markup.WriteLinkPanel(
                s => sb.AppendLine(s),
                fileLink: (displayName, url),
                webAccessUrl: ProjectGenerator.GetWebAccessUrl(sourceXmlFilePath),
                projectLink: (ProjectGenerator.ProjectSourcePath, Url: "/#" + assemblyName, assemblyName));

            // pass a value larger than 0 to generate line numbers statically at HTML generation time
            var table = Markup.GetTablePrefix();

            sb.AppendLine(table);

            if (sourceText.Length > 1000000)
            {
                sb.AppendLine(Markup.HtmlEscape(sourceText));
            }
            else
            {
                var ranges = new List <ClassifiedRange>();

                var root = Parser.ParseText(sourceText);
                ClassifierVisitor.Visit(
                    root,
                    0,
                    sourceText.Length,
                    (start, length, node, classification) =>
                {
                    var line     = TextUtilities.GetLineFromPosition(start, sourceText);
                    var lineText = sourceText.Substring(line.Item1, line.Item2);

                    ranges.Add(
                        new ClassifiedRange
                    {
                        Classification = classification,
                        Node           = node,
                        Text           = sourceText.Substring(start, length),
                        LineText       = lineText,
                        LineStart      = line.Item1,
                        LineNumber     = TextUtilities.GetLineNumber(start, lineLengths),
                        Start          = start,
                        Length         = length
                    });
                });

                ranges = RangeUtilities.FillGaps(
                    sourceText,
                    ranges,
                    r => r.Start,
                    r => r.Length,
                    (s, l, t) => new ClassifiedRange
                {
                    Start  = s,
                    Length = l,
                    Text   = t.Substring(s, l)
                }).ToList();
                foreach (var range in ranges)
                {
                    GenerateRange(range, sb);
                }
            }

            var suffix = Markup.GetDocumentSuffix();

            sb.AppendLine(suffix);
            return(sb.ToString());
        }
Пример #18
0
 private void WriteNamespace(string title, StreamWriter sw)
 {
     sw.Write(string.Format("<div class=\"folderTitle\">{0}</div>", Markup.HtmlEscape(title)));
 }