public GenerateParametersFileCommand( ILogger logger, IDiagnosticLogger diagnosticLogger, InvocationContext invocationContext, CompilationService compilationService, ParametersFileWriter writer) { this.logger = logger; this.diagnosticLogger = diagnosticLogger; this.invocationContext = invocationContext; this.compilationService = compilationService; this.writer = writer; }
public DecompileCommand( ILogger logger, IDiagnosticLogger diagnosticLogger, InvocationContext invocationContext, CompilationService compilationService, DecompilationWriter writer) { this.logger = logger; this.diagnosticLogger = diagnosticLogger; this.invocationContext = invocationContext; this.compilationService = compilationService; this.writer = writer; }
public PublishCommand( IDiagnosticLogger diagnosticLogger, CompilationService compilationService, CompilationWriter compilationWriter, IModuleDispatcher moduleDispatcher, IConfigurationManager configurationManager) { this.diagnosticLogger = diagnosticLogger; this.compilationService = compilationService; this.compilationWriter = compilationWriter; this.moduleDispatcher = moduleDispatcher; this.configurationManager = configurationManager; }
public void CompileSourceCode_CompileAssemblyFromSource() { var mockCodeProvider = MockRepository.GenerateMock<CSharpCodeProvider>(); mockCodeProvider.Stub( s => s.CompileAssemblyFromSource(Arg<CompilerParameters>.Is.Anything, Arg<string>.Is.Anything)).Return( new CompilerResults(new TempFileCollection())); var stubParameters = new CompilerParameters(); const string stubSourceCode = "sourceCode"; var compilationService = new CompilationService(mockCodeProvider, stubParameters); compilationService.CompileSourceCode(stubSourceCode); mockCodeProvider.AssertWasCalled(m => m.CompileAssemblyFromSource(stubParameters, stubSourceCode)); }
public void CheckAnswer_WhenExistsCompilationErrors_SetsErrorList() { var stubCompilationService = new CompilationService(); CompilerResults compilerResults = stubCompilationService.CompileSourceCode("NotCompilingSourceCode"); var stubTestsRunnerService = MockRepository.GenerateStub<RunnerService>(); var correctionProcess = new CorrectionProcess(stubCompilationService, stubTestsRunnerService); CorrectionResult correctionResult = correctionProcess.CheckAnswer(new Question {SourceCode = "NotCompilingSourceCode"}); Assert.AreEqual(compilerResults.Errors.Count, correctionResult.Errors.Count); Assert.AreEqual(compilerResults.Errors[0].ErrorText, correctionResult.Errors[0]); Assert.AreEqual(compilerResults.Errors[compilerResults.Errors.Count - 1].ErrorText, correctionResult.Errors[correctionResult.Errors.Count - 1]); }
public void CheckAnswer_WhenExistsCompilationErrors_SetsErrorList() { var stubCompilationService = new CompilationService(); CompilerResults compilerResults = stubCompilationService.CompileSourceCode("NotCompilingSourceCode"); var stubTestsRunnerService = MockRepository.GenerateStub <RunnerService>(); var correctionProcess = new CorrectionProcess(stubCompilationService, stubTestsRunnerService); CorrectionResult correctionResult = correctionProcess.CheckAnswer(new Question { SourceCode = "NotCompilingSourceCode" }); Assert.AreEqual(compilerResults.Errors.Count, correctionResult.Errors.Count); Assert.AreEqual(compilerResults.Errors[0].ErrorText, correctionResult.Errors[0]); Assert.AreEqual(compilerResults.Errors[compilerResults.Errors.Count - 1].ErrorText, correctionResult.Errors[correctionResult.Errors.Count - 1]); }
public void CompileSourceCode_CompileAssemblyFromSource() { var mockCodeProvider = MockRepository.GenerateMock <CSharpCodeProvider>(); mockCodeProvider.Stub( s => s.CompileAssemblyFromSource(Arg <CompilerParameters> .Is.Anything, Arg <string> .Is.Anything)).Return( new CompilerResults(new TempFileCollection())); var stubParameters = new CompilerParameters(); const string stubSourceCode = "sourceCode"; var compilationService = new CompilationService(mockCodeProvider, stubParameters); compilationService.CompileSourceCode(stubSourceCode); mockCodeProvider.AssertWasCalled(m => m.CompileAssemblyFromSource(stubParameters, stubSourceCode)); }
public void RunMethod_RunSourceCodeAndReturnTheResult() { const string sourceCode = "public class stubClass{ public int stubMethod(){ return 1; }}"; var stubQuestion = new Question(new Definition { ClassName = "stubClass", MethodName = "stubMethod" }) { SourceCode = sourceCode }; var compilationService = new CompilationService(); CompilerResults compilerResults = compilationService.CompileSourceCode(stubQuestion.SourceCode); var runnerService = new RunnerService(); var result = runnerService.RunMethod(compilerResults.CompiledAssembly, stubQuestion); Assert.AreEqual("1", result.Result); }
public RestoreCommand(CompilationService compilationService, IDiagnosticLogger diagnosticLogger) { this.compilationService = compilationService; this.diagnosticLogger = diagnosticLogger; }
private bool GenerateCode(IList <string> sources, bool useViewEngine, int iterations, bool dump = false) { if (useViewEngine) { for (var i = 0; i < sources.Count; i++) { var source = sources[i]; var relativePath = source.Substring(BasePath.Length).Replace('\\', '/'); Console.WriteLine($"Creating view {relativePath}"); for (var j = 0; j < iterations; j++) { var view = ViewEngine.GetView(null, relativePath, isMainPage: true); view.EnsureSuccessful(new string[0]); GC.KeepAlive(view.View); if (j > 0 && j % 10 == 0) { Console.WriteLine($"Completed iteration {j}"); } } } } else { for (var i = 0; i < sources.Count; i++) { var source = sources[i]; var relativePath = source.Substring(BasePath.Length); var fileNameNoExtension = Path.GetFileNameWithoutExtension(source); Console.WriteLine($"Generating {source}"); using (var stream = new FileStream(source, FileMode.Open)) { for (var j = 0; j < iterations; j++) { var codeDocument = CompilationService.CreateCodeDocument(relativePath, stream); var result = CompilationService.ProcessCodeDocument(codeDocument); if (result.Diagnostics.Count > 0) { Console.WriteLine($"Code generation failed for {source}"); foreach (var error in result.GeneratedCode) { Console.WriteLine("\t" + error); } return(false); } if (j > 0 && j % 10 == 0) { Console.WriteLine($"Completed iteration {j}"); } if (dump && j == iterations - 1) { var output = Path.ChangeExtension(source, ".cs"); Console.WriteLine($"Dumping generated code to {output}"); File.WriteAllText(output, result.GeneratedCode); } } stream.Seek(0L, SeekOrigin.Begin); } } } return(true); }
private bool?CompileFile(string path) { (string folder, string filenamePrefix, string[] exportFormats) = ParsePath(path); //get version information var metaDataService = new MetaDataService(_configModel, path); var metaData = metaDataService.Process(); var fexVersionService = new FexVersionService(metaData, folder, filenamePrefix); if (fexVersionService.NoChangesNeeded()) { return(null); } var document = new DocumentModel() { MetaDataModel = metaData }; //read out file StepStarted("read out lines"); document.RawLines = _fileService.ReadFile(path); StepCompleted(); //convert to fexLines StepStarted("parsing lines"); var fexService = new FexService(document.RawLines); document.FexLines = fexService.Process(); StepCompleted(); //create statistic StepStarted("gathering statistics"); var statisticService = new StatisticService(document.FexLines); document.StatisticModel = statisticService.Process(); StepCompleted(); //convert to content StepStarted("processing content"); var contentService = new ContentService(document.FexLines); document.RootSection = contentService.Process(); StepCompleted(); var successful = true; if (exportFormats.Contains("json") || exportFormats.Contains("xlsx")) { //learning cards create StepStarted("creating learning cards"); var learningCardsService = new GenerationService(document.StatisticModel, document.MetaDataModel, document.RootSection.Children); var cards = learningCardsService.Process(); StepCompleted(); if (exportFormats.Contains("json")) { //learning cards persist StepStarted("persisting learning cards (json)"); var learningCardsExportService = new JsonExportService(cards, folder, filenamePrefix); var learningCardsFeedback = learningCardsExportService.Process(); StepCompleted(learningCardsFeedback); successful &= learningCardsFeedback; } if (exportFormats.Contains("xlsx")) { //learning cards persist StepStarted("persisting learning cards (xlsx)"); var learningCardsExportService = new XlsxExportService(cards, folder, filenamePrefix); var learningCardsFeedback = learningCardsExportService.Process(); StepCompleted(learningCardsFeedback); successful &= learningCardsFeedback; } } if (exportFormats.Contains("md")) { //latex create StepStarted("creating & storing markdown"); var markdownService = new Services.Markdown.ExportService(document.RootSection.Children, document.MetaDataModel.Title, folder, filenamePrefix); var markdownFeedback = markdownService.Process(); StepCompleted(); successful &= markdownFeedback; } if (exportFormats.Contains("pdf") || exportFormats.Contains("handout_pdf")) { //latex create StepStarted("creating latex"); var latexService = new Services.Latex.GenerationService(document.RootSection.Children); var latex = latexService.Process(); StepCompleted(); if (exportFormats.Contains("pdf")) { //latex template StepStarted("preparing PDF template"); var latexTemplateService = new TemplateService(latex, document.StatisticModel, document.MetaDataModel, TemplateService.DefaultTemplate); var templatedLatex = latexTemplateService.Process(); StepCompleted(); //latex compile StepStarted("compiling PDF latex"); var latexCompilerService = new CompilationService(templatedLatex, folder, filenamePrefix); var latexCompileFeedback = latexCompilerService.Process(); StepCompleted(latexCompileFeedback); successful &= latexCompileFeedback; } if (exportFormats.Contains("handout_pdf")) { //latex template StepStarted("preparing handout PDF template"); var latexTemplateService = new TemplateService(latex, document.StatisticModel, document.MetaDataModel, TemplateService.HandoutTemplate); var templatedLatex = latexTemplateService.Process(); StepCompleted(); //latex compile StepStarted("compiling handout PDF latex"); var latexCompilerService = new CompilationService(templatedLatex, folder, filenamePrefix + "_handout"); var latexCompileFeedback = latexCompilerService.Process(); StepCompleted(latexCompileFeedback); successful &= latexCompileFeedback; } } if (successful) { StepStarted("saving version information"); fexVersionService.MarkFexCompileSuccessful(); StepCompleted(); } return(successful); }
public Program() { _compilationService = CompilationService.Instance; _printService = PrintService.Instance; }
protected override async Task OnInitializedAsync() { await CompilationService.InitAsync(this.HttpClient); await base.OnInitializedAsync(); }
public RestoreCommand(CompilationService compilationService) { this.compilationService = compilationService; }
public CorrectionProcess(CompilationService compilationService, RunnerService runnerService) { _compilationService = compilationService; _runnerService = runnerService; }
public CorrectionProcess() { _compilationService = new CompilationService(); _runnerService = new RunnerService(); }
/// <summary> /// Creates a new instance of the class. /// </summary> public ScriptGenerationTask() { _service = new CompilationService(); }
public void CompilationService_InitializeCodeProvider() { var compilationService = new CompilationService(); Assert.IsNotNull(compilationService.GetFieldValue <CodeDomProvider>("_codeProvider")); }
public void CompilationService_InitializeCompilerParameters() { var compilationService = new CompilationService(); Assert.IsNotNull(compilationService.GetFieldValue <CompilerParameters>("_compilerParameters")); }
public void CompilationService_InitializeCodeProvider() { var compilationService = new CompilationService(); Assert.IsNotNull(compilationService.GetFieldValue<CodeDomProvider>("_codeProvider")); }
public void CompilationService_AssemblyGeneratedInMemory() { var compilationService = new CompilationService(); var compilerParameters = compilationService.GetFieldValue<CompilerParameters>("_compilerParameters"); Assert.IsTrue(compilerParameters.GenerateInMemory); }
public void CompilationService_InitializeCompilerParameters() { var compilationService = new CompilationService(); Assert.IsNotNull(compilationService.GetFieldValue<CompilerParameters>("_compilerParameters")); }