public void Execute() { ConfigOptions options = ConfigParser.GetForProject(ProjectPath); if (options == null || !options.Enabled) { Log.LogMessage("Script generation skipped: disabled by configuration"); Success = true; return; } Log.LogMessage("Beginning script generation for project: " + ProjectPath); BuildHelper.StartBuild(ProjectPath); AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; try { IScriptGenerationResult result; // Generate the scripts for the given project WorkspaceBuilder builder = WorkspaceBuilder.CreateBuilder(ProjectPath, Parameters); using (Workspace workspace = builder.BuildWorkspace()) { ProjectId mainProjId = workspace.CurrentSolution.Projects .Where(pr => pr.FilePath == ProjectPath).FirstOrDefault()?.Id; ProjectParser parser = new ProjectParser(workspace, mainProjId); ScriptGenEngine engine = new ScriptGenEngine(ProjectPath, parser); result = engine.GenerateScripts(); } if (!result.Sucess) { Log.LogError("Script generation failed: " + result.ErrorMessage); } Success = result.Sucess; } catch (Exception e) { Log.LogError($"Script generation failed: {e.Message}"); Success = false; } finally { BuildHelper.EndBuild(ProjectPath); AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve; } }
/// <summary> /// Creates the script generation engine /// </summary> /// <param name="workspace">The workspace</param> /// <param name="projPath">The project path</param> /// <returns>The script generation engine</returns> public static IResponse GenerateScripts(IRequest request) { GenerateScriptsRequest message = GenerateScriptsRequest.Read(request); Workspace workspace = message.Workspace; string projPath = message.ProjectPath; // Can i just use proj path in package builder? ProjectId mainProjId = workspace.CurrentSolution.Projects .Where(pr => pr.FilePath == projPath && pr.SupportsCompilation).FirstOrDefault()?.Id; ProjectParser parser = new ProjectParser(workspace, mainProjId); var result = new ScriptGenEngine().GenerateScripts(new ScriptGenerationParameters() { ProjectPath = projPath, TypeIterator = parser, Force = message.Force }); return(new GenerateScriptsResponse(result.Success, result.ErrorMessage)); }