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).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();
}
}
catch (Exception ex)
{
Log.Exception(ex, "Project generation failed for: " + ProjectSourcePath);
}
}