Beispiel #1
0
        public async Task WhenRobotIsReset_ScriptCleanupIsInvoked()
        {
            var loggerConfigurator = new LoggerConfigurator(LogLevel.All);
            var builder            = new RobotBuilder(loggerConfigurator)
                                     .UseAdapter <StubAdapter>()
                                     .UseBrain <StubBrain>()
                                     .DisablePluginDiscovery()
                                     .DisableScriptDiscovery();

            var scriptRunner = new ScriptRunner(loggerConfigurator.GetLogger());

            var robot = builder
                        .Build(c => c.Register <IScriptRunner>(scriptRunner));

            scriptRunner.Initialize(robot);

            robot.LoadScript <StubEchoScript>();

            bool isCleanedUp = false;

            using (scriptRunner.StartScriptProcessingSession(new ScriptSource("TestScript", string.Empty)))
            {
                robot.RegisterCleanup(() => isCleanedUp = true);
            }

            await robot.Reset();

            Assert.True(isCleanedUp);
        }
Beispiel #2
0
        public static LoggerConfigurator CreateLogConfig(Options options)
        {
            var logConfig = new LoggerConfigurator(options.Verbose ? LogLevel.Debug : LogLevel.Info);

            if (Environment.UserInteractive)
            {
                logConfig.ConfigureForConsole();
            }
            else
            {
                logConfig.AddTraceListener();
            }

            var logger = logConfig.GetLogger();

            if (!string.IsNullOrWhiteSpace(options.LogFile))
            {
                if (Directory.Exists(Path.GetDirectoryName(options.LogFile)))
                {
                    logConfig.ConfigureForFile(options.LogFile);
                }
                else
                {
                    logger.Warn(string.Format("Failed to load log file.  Path for {0} does not exist.", options.LogFile));
                }
            }
            return(logConfig);
        }
Beispiel #3
0
 public LocalScriptStore(LoggerConfigurator logConfig, FileSystem fileSystem, IRobotPluginLocator pluginLocator)
 {
     _fileSystem    = fileSystem;
     _pluginLocator = pluginLocator;
     _scriptUpdated = new Subject <IScript>();
     _log           = logConfig.GetLogger();
 }
        private void StartScriptCs()
        {
            var name    = "WPFScript.csx";
            var console = new WPFConsoleRelay();

            var configurator = new LoggerConfigurator(LogLevel.Info);

            configurator.Configure(console);
            var logger = configurator.GetLogger();

            var init = new InitializationServices(logger);

            init.GetAppDomainAssemblyResolver().Initialize();

            var builder = new ScriptServicesBuilder(console, logger, null, null, init)
                          .Cache()
                          .Debug(false)
                          .LogLevel(LogLevel.Info)
                          .ScriptName(name)
                          .Repl();

            var modules   = new string[0];
            var extension = Path.GetExtension(name);

            //OVERRIDES
            builder.ScriptHostFactory <WPFScriptHostFactory>();
            builder.ScriptEngine <RoslynScriptEngine>();
            builder.LoadModules(extension, modules);

            //BUILD SERVICE
            _service = builder.Build();
            _service.Executor.Initialize(Enumerable.Empty <string>(), _service.ScriptPackResolver.GetPacks(), new string[0]);
            var types = new Type[] {
                typeof(IConsole),
                typeof(ScriptContext),
                typeof(Newtonsoft.Json.Converters.BinaryConverter)
            };


            _service.Executor.AddReferenceAndImportNamespaces(types);



            EventAggr.Instance.GetEvent <WriteLineEvent>().Subscribe((text) =>
            {
                string[] lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                foreach (var line in lines.Where(l => !string.IsNullOrEmpty(l)))
                {
                    _area.Document.Text += line;
                    NewLine();
                    _area.Document.Text += ">";
                }
            });

            EventAggr.Instance.GetEvent <WriteEvent>().Subscribe((text) =>
            {
                _area.Document.Text += text;
            }
                                                                 );
        }
Beispiel #5
0
    private IScriptExecutor GetExecutor(List <string> references, string rootPath)
    {
        var console      = new ScriptConsole();
        var loggerConfig = new LoggerConfigurator(ScriptCs.Contracts.LogLevel.Error);

        loggerConfig.Configure(console);
        var logger = loggerConfig.GetLogger();

        var builder = new ScriptServicesBuilder(console, logger).
                      InMemory(true).
                      ScriptName("");

        var services = builder.Build();
        var executor = services.Executor;
        var paths    = services.AssemblyResolver.GetAssemblyPaths(rootPath, null).Where(p => !p.Contains("Contracts"));

        var packs = services.ScriptPackResolver.GetPacks();

        executor.Initialize(paths, packs);

        executor.AddReferences(references.ToArray());
        var reference = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\ScriptCs.Contracts.dll";

        executor.AddReferences(reference);
        executor.ImportNamespaces("ScriptCs.Contracts");
        return(executor);
    }
        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 configurator = new LoggerConfigurator(commandArgs.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(commandArgs.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);
        }
Beispiel #7
0
        private ScriptServices CreateScriptServices(bool useLogging)
        {
            var console = new ScriptConsole();
            var configurator = new LoggerConfigurator(useLogging ? LogLevel.Debug : LogLevel.Info);

            configurator.Configure(console);
            var logger = configurator.GetLogger();
            var builder = new ScriptServicesBuilder(console, logger);

            builder.ScriptEngine<RoslynScriptEngine>();

            return builder.Build();
        }
Beispiel #8
0
        private static ScriptServices BuildScriptServices(InOutConsole console)
        {
            var logConfiguration = new LoggerConfigurator(LogLevel.Info);
            logConfiguration.Configure(console);
            var logger = logConfiguration.GetLogger();

            var initializationServices = new InitializationServices(logger);

            initializationServices.GetAppDomainAssemblyResolver().Initialize();

            var scriptServicesBuilder = new ScriptServicesBuilder(console, logger, null, null, initializationServices)
                .Repl(true);

            scriptServicesBuilder.LoadModules("");

            var scriptServices = scriptServicesBuilder.Build();

            initializationServices.GetInstallationProvider().Initialize();

            scriptServices.Repl.Initialize(Enumerable.Empty<string>(), Enumerable.Empty<IScriptPack>());
            return scriptServices;
        }
 public NuGetPackageAssemblyResolver(LoggerConfigurator logConfig)
 {
     _log = logConfig.GetLogger();
     AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
     RefreshAssemblies(_log);
 }