public void PrintCorrectResult_WhenCalledWithSize6() { // Arrange var instance = MatrixEngine.Instance; var testFilename = "TestOutputOfMatrixSize6.txt"; var consoleStub = new FileConsole(testFilename); instance.Size = 6; instance.MatrixConsole = consoleStub; // Act instance.Start(); consoleStub.Dispose(); var path = AppDomain.CurrentDomain.BaseDirectory; var result = File.ReadAllText(path + '\\' + testFilename); File.Delete(path + '\\' + testFilename); var expected = @" 1 16 17 18 19 20 15 2 27 28 29 21 14 31 3 26 30 22 13 36 32 4 25 23 12 35 34 33 5 24 11 10 9 8 7 6 "; // Assert Assert.AreEqual(expected, result); }
public static IScriptServicesBuilder Create(Config config, string[] scriptArgs) { Guard.AgainstNullArgument("commandArgs", config); Guard.AgainstNullArgument("scriptArgs", scriptArgs); IConsole console = new ScriptConsole(); if (!string.IsNullOrWhiteSpace(config.OutputFile)) { console = new FileConsole(config.OutputFile, console); } var logProvider = new ColoredConsoleLogProvider(config.LogLevel, console); var initializationServices = new InitializationServices(logProvider); initializationServices.GetAppDomainAssemblyResolver().Initialize(); // NOTE (adamralph): this is a hideous assumption about what happens inside the CommandFactory. // It is a result of the ScriptServicesBuilderFactory also having to know what is going to happen inside the // Command Factory so that it builds the builder(:-p) correctly in advance. // This demonstrates the technical debt that exists with the ScriptServicesBuilderFactory and CommandFactory // in their current form. We have a separate refactoring task raised to address this. var repl = config.Repl || (!config.Clean && config.PackageName == null && !config.Save && config.ScriptName == null); var scriptServicesBuilder = new ScriptServicesBuilder(console, logProvider, null, null, initializationServices) .Cache(config.Cache) .Debug(config.Debug) .LogLevel(config.LogLevel) .ScriptName(config.ScriptName) .Repl(repl); return(scriptServicesBuilder.LoadModules(Path.GetExtension(config.ScriptName) ?? ".csx", config.Modules)); }
public void PrintCorrectResult_WhenCalledWithSize5() { // Arrange var instance = MatrixEngine.Instance; var testFilename = "TestOutputOfMatrixSize5.txt"; var consoleStub = new FileConsole(testFilename); instance.Size = 5; instance.MatrixConsole = consoleStub; // Act instance.Start(); consoleStub.Dispose(); var path = AppDomain.CurrentDomain.BaseDirectory; var result = File.ReadAllText(path + '\\' + testFilename); File.Delete(path + '\\' + testFilename); var expected = @" 1 13 14 15 16 12 2 21 22 17 11 23 3 20 18 10 25 24 4 19 9 8 7 6 5 "; // Assert Assert.AreEqual(expected, result); }
public void PrintCorrectResult_WhenCalledWithSize11() { // Arrange var instance = MatrixEngine.Instance; var testFilename = "TestOutputOfMatrixSize11.txt"; var consoleStub = new FileConsole(testFilename); instance.Size = 11; instance.MatrixConsole = consoleStub; // Act instance.Start(); consoleStub.Dispose(); var path = AppDomain.CurrentDomain.BaseDirectory; var result = File.ReadAllText(path + '\\' + testFilename); File.Delete(path + '\\' + testFilename); var expected = @" 1 31 32 33 34 35 36 37 38 39 40 30 2 57 58 59 60 61 62 63 64 41 29 86 3 56 75 76 77 78 79 65 42 28106 87 4 55 74 84 85 80 66 43 27105107 88 5 54 73 83 81 67 44 26104118108 89 6 53 72 82 68 45 25103117119109 90 7 52 71 69 46 24102116121120110 91 8 51 70 47 23101115114113112111 92 9 50 48 22100 99 98 97 96 95 94 93 10 49 21 20 19 18 17 16 15 14 13 12 11 "; // Assert Assert.AreEqual(expected, result); }
public static IScriptServicesBuilder Create(ScriptCsArgs commandArgs, string[] scriptArgs) { Guard.AgainstNullArgument("commandArgs", commandArgs); Guard.AgainstNullArgument("scriptArgs", scriptArgs); IConsole console = new ScriptConsole(); if (!string.IsNullOrWhiteSpace(commandArgs.Output)) { console = new FileConsole(commandArgs.Output, console); } var logLevel = commandArgs.LogLevel ?? LogLevel.Info; var configurator = new LoggerConfigurator(logLevel); configurator.Configure(console); var logger = configurator.GetLogger(); var initializationServices = new InitializationServices(logger); initializationServices.GetAppDomainAssemblyResolver().Initialize(); var scriptServicesBuilder = new ScriptServicesBuilder(console, logger, null, null, initializationServices) .Cache(commandArgs.Cache) .Debug(commandArgs.Debug) .LogLevel(logLevel) .ScriptName(commandArgs.ScriptName) .Repl(commandArgs.Repl); var modules = commandArgs.Modules == null ? new string[0] : commandArgs.Modules.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); var extension = Path.GetExtension(commandArgs.ScriptName); if (string.IsNullOrWhiteSpace(extension) && !commandArgs.Repl) { // No extension was given, i.e we might have something like // "scriptcs foo" to deal with. We activate the default extension, // to make sure it's given to the LoadModules below. extension = ".csx"; if (!string.IsNullOrWhiteSpace(commandArgs.ScriptName)) { // If the was in fact a script specified, we'll extend it // with the default extension, assuming the user giving // "scriptcs foo" actually meant "scriptcs foo.csx". We // perform no validation here thought; let it be done by // the activated command. If the file don't exist, it's // up to the command to detect and report. commandArgs.ScriptName += extension; } } return(scriptServicesBuilder.LoadModules(extension, modules)); }
private void InitializeInfusion() { proxy = new InfusionProxy(); fileConsole = new FileConsole(proxy.LogConfig, new CircuitBreaker(HandleFileLoggingException)); var wpfConsole = _console.CreateWpfConsole(); infusionConsole = new InfusionConsole(fileConsole, wpfConsole); proxy.Console = infusionConsole; var commandHandler = new CommandHandler(proxy.Console); _console.Initialize(commandHandler); proxy.Initialize(commandHandler, new SoundPlayer(), new Infusion.Injection.Avalonia.InjectionWindowHandler()); CSharpScriptEngine = new Lazy <CSharpScriptEngine>(() => new CSharpScriptEngine(infusionConsole)); ScriptEngine = new Lazy <ScriptEngine>(() => new ScriptEngine(CSharpScriptEngine.Value, new InjectionScriptEngine(UO.Injection, infusionConsole))); _console.ShowNoDebug(); }
public static void AttachErrorHandling(Application app, StartupEventArgs e) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; #if DEBUG DebugFlag = true; #endif if (e.Args.Length > 0) { var arg = e.Args[0]; if (arg == "-d" || arg == "--debug") { DebugFlag = true; } } if (DebugFlag) { FileConsole.Activate(); } app.DispatcherUnhandledException += App_DispatcherUnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; }