protected KernelBase() { _disposables = new CompositeDisposable(); Pipeline = new KernelCommandPipeline(this); AddSetKernelMiddleware(); AddDirectiveMiddleware(); }
protected KernelBase() { _disposables = new CompositeDisposable(); Pipeline = new KernelCommandPipeline(this); Pipeline.AddMiddleware(async(command, pipelineContext, next) => { switch (command) { case SubmitCode submitCode: var modified = false; var directiveParser = BuildDirectiveParser(pipelineContext); var lines = new Queue <string>( submitCode.Code.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None)); var unhandledLines = new List <string>(); while (lines.Count > 0) { var currentLine = lines.Dequeue(); var parseResult = directiveParser.Parse(currentLine); if (parseResult.Errors.Count == 0) { modified = true; await directiveParser.InvokeAsync(parseResult); } else { unhandledLines.Add(currentLine); } } var code = string.Join("\n", unhandledLines); if (modified) { if (string.IsNullOrWhiteSpace(code)) { pipelineContext.OnExecute(context => { context.OnNext(new CodeSubmissionEvaluated(submitCode)); context.OnCompleted(); return(Task.CompletedTask); }); return; } else { submitCode.Code = code; } } break; } await next(command, pipelineContext); }); }