Skip to content

Commit f545f6b

Browse files
committed
Layout for ProjectJson support
1 parent dd09c3e commit f545f6b

File tree

3 files changed

+54
-36
lines changed

3 files changed

+54
-36
lines changed

src/SourceBrowser.Generator/SolutionAnalyzer.cs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace SourceBrowser.Generator
2121
{
2222
public class SolutionAnalayzer
2323
{
24+
public bool WorkspaceFailed { get; set; }
2425
MSBuildWorkspace _workspace;
2526
Solution _solution;
2627
private ReferencesourceLinkProvider _refsourceLinkProvider = new ReferencesourceLinkProvider();
@@ -35,6 +36,7 @@ public SolutionAnalayzer(string solutionPath)
3536

3637
private void _workspace_WorkspaceFailed(object sender, WorkspaceDiagnosticEventArgs e)
3738
{
39+
WorkspaceFailed = true;
3840
try
3941
{
4042
var logDirectory = System.Web.Hosting.HostingEnvironment.MapPath("/WorkspaceLogs/");

src/SourceBrowser.Site/Controllers/UploadController.cs

+31-35
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using SourceBrowser.Site.Repositories;
88
using System;
99
using System.Linq;
10-
10+
using Generator.Model;
1111
public class UploadController : Controller
1212
{
1313
// GET: Upload
@@ -62,49 +62,45 @@ public ActionResult Submit(string githubUrl)
6262
var omnisharpPaths = Directory.GetFiles(repoRootPath, "omnisharp.json", SearchOption.AllDirectories);
6363
var projectJsonPaths= Directory.GetFiles(repoRootPath, "project.json", SearchOption.AllDirectories);
6464

65-
// TODO: Use parallel for.
66-
// TODO: Process all solutions.
67-
// For now, we're assuming the shallowest and shortest .sln file is the one we're interested in
68-
foreach (var solutionPath in solutionPaths.OrderBy(n => n.Length).Take(1))
69-
{
70-
try
71-
{
72-
var workspaceModel = UploadRepository.ProcessSolution(solutionPath, repoRootPath);
73-
74-
//One pass to lookup all declarations
75-
var typeTransformer = new TokenLookupTransformer();
76-
typeTransformer.Visit(workspaceModel);
77-
var tokenLookup = typeTransformer.TokenLookup;
78-
79-
//Another pass to generate HTMLs
80-
var htmlTransformer = new HtmlTransformer(tokenLookup, repoPath);
81-
htmlTransformer.Visit(workspaceModel);
65+
string solutionPath = solutionPaths.OrderBy(n => n.Length).FirstOrDefault();
66+
string omnisharpPath = omnisharpPaths.OrderBy(n => n.Length).FirstOrDefault();
8267

83-
var searchTransformer = new SearchIndexTransformer(retriever.UserName, retriever.RepoName);
84-
searchTransformer.Visit(workspaceModel);
68+
WorkspaceModel workspaceModel = null;
69+
if(solutionPath != null)
70+
{
71+
workspaceModel = UploadRepository.ProcessSolution(solutionPath, repoRootPath);
72+
}
8573

86-
// Generate HTML of the tree view
87-
var treeViewTransformer = new TreeViewTransformer(repoPath, retriever.UserName, retriever.RepoName);
88-
treeViewTransformer.Visit(workspaceModel);
89-
}
90-
catch (Exception ex)
91-
{
92-
// TODO: Log this
93-
ViewBag.Error = "There was an error processing solution " + Path.GetFileName(solutionPath);
94-
return View("Index");
95-
}
74+
if(workspaceModel == null && omnisharpPath != null)
75+
{
76+
workspaceModel = UploadRepository.ProcessOmnisharp(omnisharpPath, repoRootPath);
9677
}
9778

98-
try
79+
if(workspaceModel == null && projectJsonPaths.Count() > 0)
9980
{
100-
UploadRepository.SaveReadme(repoPath, retriever.ProvideParsedReadme());
81+
workspaceModel = UploadRepository.ProcessProjectJson(projectJsonPaths, repoRootPath);
10182
}
102-
catch (Exception ex)
83+
84+
if (workspaceModel != null)
10385
{
104-
// TODO: Log and swallow - readme is not essential.
86+
//One pass to lookup all declarations
87+
var typeTransformer = new TokenLookupTransformer();
88+
typeTransformer.Visit(workspaceModel);
89+
var tokenLookup = typeTransformer.TokenLookup;
90+
91+
//Another pass to generate HTMLs
92+
var htmlTransformer = new HtmlTransformer(tokenLookup, repoPath);
93+
htmlTransformer.Visit(workspaceModel);
94+
95+
var searchTransformer = new SearchIndexTransformer(retriever.UserName, retriever.RepoName);
96+
searchTransformer.Visit(workspaceModel);
97+
98+
// Generate HTML of the tree view
99+
var treeViewTransformer = new TreeViewTransformer(repoPath, retriever.UserName, retriever.RepoName);
100+
treeViewTransformer.Visit(workspaceModel);
101+
processingSuccessful = true;
105102
}
106103

107-
processingSuccessful = true;
108104
return Redirect("/Browse/" + retriever.UserName + "/" + retriever.RepoName);
109105
}
110106
finally

src/SourceBrowser.Site/Repositories/UploadRepository.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Security;
88
using System.IO;
99
using System.Configuration;
10+
using SourceBrowser.Generator.Model;
1011

1112
namespace SourceBrowser.Site.Repositories
1213
{
@@ -18,7 +19,7 @@ public class UploadRepository
1819
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
1920
private extern static bool CloseHandle(IntPtr handle);
2021

21-
internal static Generator.Model.WorkspaceModel ProcessSolution(string solutionPath, string repoRootPath)
22+
internal static WorkspaceModel ProcessSolution(string solutionPath, string repoRootPath)
2223
{
2324
SafeTokenHandle safeTokenHandle;
2425
string safeUserName = ConfigurationManager.AppSettings["safeUserName"];
@@ -28,6 +29,11 @@ internal static Generator.Model.WorkspaceModel ProcessSolution(string solutionPa
2829
if (String.IsNullOrEmpty(safeUserName))
2930
{
3031
var sourceGenerator = new Generator.SolutionAnalayzer(solutionPath);
32+
if(sourceGenerator.WorkspaceFailed)
33+
{
34+
return null;
35+
}
36+
3137
var workspaceModel = sourceGenerator.BuildWorkspaceModel(repoRootPath);
3238
return workspaceModel;
3339
}
@@ -54,13 +60,27 @@ internal static Generator.Model.WorkspaceModel ProcessSolution(string solutionPa
5460
using (WindowsImpersonationContext impersonatedUser = WindowsIdentity.Impersonate(safeTokenHandle.DangerousGetHandle()))
5561
{
5662
var sourceGenerator = new Generator.SolutionAnalayzer(solutionPath);
63+
if (sourceGenerator.WorkspaceFailed)
64+
{
65+
return null;
66+
}
5767
var workspaceModel = sourceGenerator.BuildWorkspaceModel(repoRootPath);
5868
return workspaceModel;
5969
}
6070
// Releasing the context object stops the impersonation
6171
}
6272
}
6373

74+
internal static WorkspaceModel ProcessOmnisharp(string omnisharpPath, string repoRootPath)
75+
{
76+
throw new NotImplementedException();
77+
}
78+
79+
internal static WorkspaceModel ProcessProjectJson(string[] projectJsonPaths, string repoRootPath)
80+
{
81+
throw new NotImplementedException();
82+
}
83+
6484
internal static void SaveReadme(string repoPath, string readmeInHtml)
6585
{
6686
string readmePath = Path.Combine(repoPath, "readme.html");

0 commit comments

Comments
 (0)