MakeRelativeToFolder() public static method

Returns a path to filePath if you start in folder relativeToPath.
public static MakeRelativeToFolder ( string filePath, string relativeToPath ) : string
filePath string C:\A\B\1.txt
relativeToPath string C:\C\D
return string
        private void GenerateXamlFile(string xamlFile)
        {
            var projectSourceFolder = Path.GetDirectoryName(ProjectFilePath);

            if (!Path.IsPathRooted(xamlFile))
            {
                xamlFile = Path.Combine(Path.GetDirectoryName(ProjectFilePath), xamlFile);
            }

            xamlFile = Path.GetFullPath(xamlFile);
            var sourceXmlFile = xamlFile;

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

            var relativePath = Paths.MakeRelativeToFolder(sourceXmlFile, projectSourceFolder);

            relativePath = relativePath.Replace("..", "parent");

            var destinationHtmlFile = Path.Combine(ProjectDestinationFolder, relativePath) + ".html";

            var xamlSupport = new XamlSupport(this);

            xamlSupport.GenerateXaml(sourceXmlFile, destinationHtmlFile, relativePath);

            OtherFiles.Add(relativePath);
            AddDeclaredSymbolToRedirectMap(SymbolIDToListOfLocationsMap, SymbolIdService.GetId(relativePath), relativePath, 0);
        }
Beispiel #2
0
        public async Task Generate()
        {
            try
            {
                if (string.IsNullOrEmpty(ProjectFilePath))
                {
                    Log.Exception("ProjectFilePath is empty: " + Project.ToString());
                    return;
                }

                ProjectDestinationFolder = GetProjectDestinationPath(Project, SolutionGenerator.SolutionDestinationFolder);
                if (ProjectDestinationFolder == null)
                {
                    Log.Exception("Errors evaluating project: " + Project.Id);
                    return;
                }

                Log.Write(ProjectDestinationFolder, ConsoleColor.DarkCyan);

                ProjectSourcePath = Paths.MakeRelativeToFolder(ProjectFilePath, SolutionGenerator.SolutionSourceFolder);

                if (File.Exists(Path.Combine(ProjectDestinationFolder, Constants.DeclaredSymbolsFileName + ".txt")))
                {
                    // apparently someone already generated a project with this assembly name - their assembly wins
                    Log.Exception(string.Format(
                                      "A project with assembly name {0} was already generated, skipping current project: {1}",
                                      this.AssemblyName,
                                      this.ProjectFilePath), isSevere: false);
                    return;
                }

                if (Configuration.CreateFoldersOnDisk)
                {
                    Directory.CreateDirectory(ProjectDestinationFolder);
                }

                var documents = Project.Documents
                                .Where(IncludeDocument)
                                .OrderByDescending(GetDocumentSortOrder);

                var tasks = documents.Select(d => Task.Run(() => GenerateDocument(d))).ToArray();
                await Task.WhenAll(tasks);

                foreach (var document in documents)
                {
                    OtherFiles.Add(Paths.GetRelativeFilePathInProject(document));
                }

                if (Configuration.WriteProjectAuxiliaryFilesToDisk)
                {
                    GenerateProjectFile();
                    GenerateDeclarations();
                    GenerateBaseMembers();
                    GenerateImplementedInterfaceMembers();
                    GenerateProjectInfo();
                    GenerateReferencesDataFiles(
                        this.SolutionGenerator.SolutionDestinationFolder,
                        ReferencesByTargetAssemblyAndSymbolId);
                    GenerateSymbolIDToListOfDeclarationLocationsMap(
                        ProjectDestinationFolder,
                        SymbolIDToListOfLocationsMap);
                    GenerateReferencedAssemblyList();
                    GenerateUsedReferencedAssemblyList();
                    GenerateProjectExplorer();
                    GenerateNamespaceExplorer();
                    GenerateIndex();
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex, "Project generation failed for: " + ProjectSourcePath);
            }
        }
        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);
            }
        }
Beispiel #4
0
        private static void IndexSolutions(
            IEnumerable <string> solutionFilePaths,
            IReadOnlyDictionary <string, string> properties,
            Federation federation,
            IReadOnlyDictionary <string, string> serverPathMappings,
            IEnumerable <string> pluginBlacklist,
            bool doNotIncludeReferencedProjects = false,
            string rootPath = null)
        {
            var assemblyNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var path in solutionFilePaths)
            {
                using (Disposable.Timing("Reading assembly names from " + path))
                {
                    foreach (var assemblyName in GetAssemblyNames(path))
                    {
                        assemblyNames.Add(assemblyName);
                    }
                }
            }

            var processedAssemblyList = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var path in solutionFilePaths)
            {
                var solutionFolder = mergedSolutionExplorerRoot;

                if (rootPath is object)
                {
                    var relativePath = Paths.MakeRelativeToFolder(Path.GetDirectoryName(path), rootPath);
                    var segments     = relativePath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (var segment in segments)
                    {
                        solutionFolder = solutionFolder.GetOrCreateFolder(segment);
                    }
                }

                using (Disposable.Timing("Generating " + path))
                {
                    if (path.EndsWith(".binlog", StringComparison.OrdinalIgnoreCase) ||
                        path.EndsWith(".buildlog", StringComparison.OrdinalIgnoreCase))
                    {
                        var invocations = BinLogCompilerInvocationsReader.ExtractInvocations(path);
                        foreach (var invocation in invocations)
                        {
                            GenerateFromBuildLog.GenerateInvocation(
                                invocation,
                                serverPathMappings,
                                processedAssemblyList,
                                assemblyNames,
                                solutionFolder);
                        }

                        continue;
                    }

                    using (var solutionGenerator = new SolutionGenerator(
                               path,
                               Paths.SolutionDestinationFolder,
                               properties: properties.ToImmutableDictionary(),
                               federation: federation,
                               serverPathMappings: serverPathMappings,
                               pluginBlacklist: pluginBlacklist,
                               doNotIncludeReferencedProjects: doNotIncludeReferencedProjects))
                    {
                        solutionGenerator.GlobalAssemblyList = assemblyNames;
                        solutionGenerator.Generate(processedAssemblyList, solutionFolder);
                    }
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
            }
        }
Beispiel #5
0
        public async Task Generate()
        {
            try
            {
                if (string.IsNullOrEmpty(ProjectFilePath))
                {
                    Log.Exception("ProjectFilePath is empty: " + Project.ToString());
                    return;
                }

                ProjectDestinationFolder = GetProjectDestinationPath(Project, SolutionGenerator.SolutionDestinationFolder);
                if (ProjectDestinationFolder == null)
                {
                    Log.Exception("Errors evaluating project: " + Project.Id);
                    return;
                }

                Log.Write(ProjectDestinationFolder, ConsoleColor.DarkCyan);

                if (SolutionGenerator.SolutionSourceFolder is string solutionFolder)
                {
                    ProjectSourcePath = Paths.MakeRelativeToFolder(ProjectFilePath, solutionFolder);
                }
                else
                {
                    ProjectSourcePath = ProjectFilePath;
                }

                if (File.Exists(Path.Combine(ProjectDestinationFolder, Constants.DeclaredSymbolsFileName + ".txt")))
                {
                    // apparently someone already generated a project with this assembly name - their assembly wins
                    Log.Exception(string.Format(
                                      "A project with assembly name {0} was already generated, skipping current project: {1}",
                                      this.AssemblyName,
                                      this.ProjectFilePath), isSevere: false);
                    return;
                }

                if (Configuration.CreateFoldersOnDisk)
                {
                    Directory.CreateDirectory(ProjectDestinationFolder);
                }

                var documents = Project.Documents.Where(IncludeDocument).ToList();

                var generationTasks = Partitioner.Create(documents)
                                      .GetPartitions(Environment.ProcessorCount)
                                      .Select(partition =>
                                              Task.Run(async() =>
                {
                    using (partition)
                    {
                        while (partition.MoveNext())
                        {
                            await GenerateDocument(partition.Current);
                        }
                    }
                }));

                await Task.WhenAll(generationTasks);

                foreach (var document in documents)
                {
                    OtherFiles.Add(Paths.GetRelativeFilePathInProject(document));
                }

                if (Configuration.WriteProjectAuxiliaryFilesToDisk)
                {
                    GenerateProjectFile();
                    GenerateDeclarations();
                    GenerateBaseMembers();
                    GenerateImplementedInterfaceMembers();
                    GenerateProjectInfo();
                    GenerateReferencesDataFiles(
                        this.SolutionGenerator.SolutionDestinationFolder,
                        ReferencesByTargetAssemblyAndSymbolId);
                    GenerateSymbolIDToListOfDeclarationLocationsMap(
                        ProjectDestinationFolder,
                        SymbolIDToListOfLocationsMap);
                    GenerateReferencedAssemblyList();
                    GenerateUsedReferencedAssemblyList();
                    GenerateProjectExplorer();
                    GenerateNamespaceExplorer();
                    GenerateIndex();
                }

                var compilation = Project.GetCompilationAsync().Result;
                var diagnostics = compilation.GetDiagnostics().Select(d => d.ToString()).ToArray();
                if (diagnostics.Length > 0)
                {
                    var diagnosticsTxt = Path.Combine(this.ProjectDestinationFolder, "diagnostics.txt");
                    File.WriteAllLines(diagnosticsTxt, diagnostics);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex, "Project generation failed for: " + ProjectSourcePath);
            }
        }
        private static void IndexSolutions(
            IEnumerable <string> solutionFilePaths,
            IReadOnlyDictionary <string, string> properties,
            Federation federation,
            IReadOnlyDictionary <string, string> serverPathMappings,
            IEnumerable <string> pluginBlacklist,
            bool doNotIncludeReferencedProjects = false,
            string rootPath = null)
        {
            var assemblyNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var path in solutionFilePaths)
            {
                using (Disposable.Timing("Reading assembly names from " + path))
                {
                    foreach (var assemblyName in GetAssemblyNames(path))
                    {
                        assemblyNames.Add(assemblyName);
                    }
                }
            }

            var processedAssemblyList = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var typeForwards          = new Dictionary <ValueTuple <string, string>, string>();

            var domain = AppDomain.CreateDomain("TypeForwards");

            foreach (var path in solutionFilePaths)
            {
                if (
                    path.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ||
                    path.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)
                    )
                {
                    continue;
                }
                using (Disposable.Timing($"Reading type forwards from {path}"))
                {
                    GetTypeForwards(path, properties, typeForwards, domain);
                }
            }
            AppDomain.Unload(domain);
            domain = null;

            foreach (var path in solutionFilePaths)
            {
                var solutionFolder = mergedSolutionExplorerRoot;

                if (rootPath is object)
                {
                    var relativePath = Paths.MakeRelativeToFolder(Path.GetDirectoryName(path), rootPath);
                    var segments     = relativePath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (var segment in segments)
                    {
                        solutionFolder = solutionFolder.GetOrCreateFolder(segment);
                    }
                }

                using (Disposable.Timing("Generating " + path))
                {
                    if (path.EndsWith(".binlog", StringComparison.OrdinalIgnoreCase) ||
                        path.EndsWith(".buildlog", StringComparison.OrdinalIgnoreCase))
                    {
                        var invocations = BinLogCompilerInvocationsReader.ExtractInvocations(path);
                        foreach (var invocation in invocations)
                        {
                            if (Path.GetFileName(invocation.ProjectDirectory) == "ref")
                            {
                                Log.Write($"Skipping Ref Assembly project {invocation.ProjectFilePath}");
                                continue;
                            }

                            if (Path.GetFileName(Path.GetDirectoryName(invocation.ProjectDirectory)) == "cycle-breakers")
                            {
                                Log.Write($"Skipping Wpf Cycle-Breaker project {invocation.ProjectFilePath}");
                                continue;
                            }
                            Log.Write($"Indexing Project: {invocation.ProjectFilePath}");
                            GenerateFromBuildLog.GenerateInvocation(
                                invocation,
                                serverPathMappings,
                                processedAssemblyList,
                                assemblyNames,
                                solutionFolder,
                                typeForwards);
                        }

                        continue;
                    }

                    using (var solutionGenerator = new SolutionGenerator(
                               path,
                               Paths.SolutionDestinationFolder,
                               properties: properties.ToImmutableDictionary(),
                               federation: federation,
                               serverPathMappings: serverPathMappings,
                               pluginBlacklist: pluginBlacklist,
                               doNotIncludeReferencedProjects: doNotIncludeReferencedProjects,
                               typeForwards: typeForwards))
                    {
                        solutionGenerator.GlobalAssemblyList = assemblyNames;
                        solutionGenerator.Generate(processedAssemblyList, solutionFolder);
                    }
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
            }
        }