public string BuildNavigatableSourceCodeFromFile(string username, string project, string path)
        {
            var projectCodeDirectory = new DirectoryInfo(this.applicationConfigurationProvider.GetProjectSourceCodePath(username, project));
            string fullPath = Path.Combine(projectCodeDirectory.FullName, path.Replace(@"/", @"\"));
            string fileExtension = Path.GetExtension(fullPath);
            string sourceCode = File.ReadAllText(fullPath);

            try
            {
                if (fileExtension == ".cs")
                {
                    var documentInfo = this.sourceCodeQueryService.GetFileDetails(projectCodeDirectory.MakeRelativePath(fullPath));
                    if (documentInfo != null)
                    {
                        var workspace = Roslyn.Services.Workspace.LoadSolution(Path.Combine(projectCodeDirectory.FullName, documentInfo.SolutionPath));
                            //.LoadStandAloneProject(Path.Combine(projectCodeDirectory.FullName, documentInfo.ProjectPath));  //
                        var solution = workspace.CurrentSolution;
                        IDocument selectedDocument = null;
                        foreach (var projectItem in solution.Projects)
                        {
                            try
                            {
                                if (!projectItem.HasDocuments)
                                {
                                    continue;
                                }

                                selectedDocument = projectItem.Documents.SingleOrDefault(document => document.FilePath == fullPath);
                                if (selectedDocument != null)
                                {
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                this.logger.Error(ex, "An error has occured while loading the project {0}", projectItem.Name);
                            }
                        }

                        if (selectedDocument != null)
                        {
                            ISyntaxNavigationBuilder syntaxNavigationBuilder = new DotNetSyntaxNavigationBuilder();
                            var semanticModel = selectedDocument.GetSemanticModel();
                            return syntaxNavigationBuilder.GetCodeAsNavigatableHtml(semanticModel, new CSharpCodeNavigationSyntaxWalker());
                        }
                    }

                    return sourceCode;
                }
            }
            catch (Exception ex)
            {
                this.logger.Error(ex, "Error occured while highlighting sytnax on file {0}", path);
            }

            return HttpUtility.HtmlEncode(sourceCode);
        }
        public string BuildNavigatableSourceCodeFromFile(string username, string project, string path)
        {
            var    projectCodeDirectory = new DirectoryInfo(this.applicationConfigurationProvider.GetProjectSourceCodePath(username, project));
            string fullPath             = Path.Combine(projectCodeDirectory.FullName, path.Replace(@"/", @"\"));
            string fileExtension        = Path.GetExtension(fullPath);
            string sourceCode           = File.ReadAllText(fullPath);

            try
            {
                if (fileExtension == ".cs")
                {
                    var documentInfo = this.sourceCodeQueryService.GetFileDetails(projectCodeDirectory.MakeRelativePath(fullPath));
                    if (documentInfo != null)
                    {
                        var workspace = Roslyn.Services.Workspace.LoadSolution(Path.Combine(projectCodeDirectory.FullName, documentInfo.SolutionPath));
                        //.LoadStandAloneProject(Path.Combine(projectCodeDirectory.FullName, documentInfo.ProjectPath));  //
                        var       solution         = workspace.CurrentSolution;
                        IDocument selectedDocument = null;
                        foreach (var projectItem in solution.Projects)
                        {
                            try
                            {
                                if (!projectItem.HasDocuments)
                                {
                                    continue;
                                }

                                selectedDocument = projectItem.Documents.SingleOrDefault(document => document.FilePath == fullPath);
                                if (selectedDocument != null)
                                {
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                this.logger.Error(ex, "An error has occured while loading the project {0}", projectItem.Name);
                            }
                        }

                        if (selectedDocument != null)
                        {
                            ISyntaxNavigationBuilder syntaxNavigationBuilder = new DotNetSyntaxNavigationBuilder();
                            var semanticModel = selectedDocument.GetSemanticModel();
                            return(syntaxNavigationBuilder.GetCodeAsNavigatableHtml(semanticModel, new CSharpCodeNavigationSyntaxWalker()));
                        }
                    }

                    return(sourceCode);
                }
            }
            catch (Exception ex)
            {
                this.logger.Error(ex, "Error occured while highlighting sytnax on file {0}", path);
            }

            return(HttpUtility.HtmlEncode(sourceCode));
        }
        public string BuildNavigatableSourceCodeFromFile(string filename)
        {
            var sourceCode = File.ReadAllText(filename);
            var fileExtension = Path.GetExtension(filename).ToLowerInvariant();

            ISyntaxNavigationBuilder syntaxNavigationBuilder = new DotNetSyntaxNavigationBuilder();

            if (fileExtension == ".cs")
            {
                return syntaxNavigationBuilder.GetCodeAsNavigatableHtml(sourceCode, new CSharpCodeNavigationSyntaxWalker());
            }
            else if (fileExtension == ".vb")
            {
                return syntaxNavigationBuilder.GetCodeAsNavigatableHtml(sourceCode, new VisualBasicCodeNavigationSyntaxWalker());
            }
            else
            {
                return sourceCode;
            }
        }
 public void SetUp()
 {
     codeNavigationBuilder = new DotNetSyntaxNavigationBuilder();
 }