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;
            }
                                                                 );
        }
Example #2
0
        static void Main(string[] args)
        {
            var console     = (IConsole) new ScriptConsole();
            var logProvider = new ColoredConsoleLogProvider(LogLevel.Info, console);
            var builder     = new ScriptServicesBuilder(console, logProvider);

            builder.ScriptHostFactory <DictionaryScriptHostFactory>();
            SetEngine(builder);
            var services = builder.Build();

            var executor = (ScriptExecutor)services.Executor;

            //add the Message reference and using so we can use the Message type.
            executor.AddReferences(typeof(Message).Assembly);
            executor.ImportNamespaces("DynamicHostExample");

            executor.Initialize(Enumerable.Empty <string>(), Enumerable.Empty <IScriptPack>());

            ExecuteLooseScript(executor);
            Console.ReadLine();
        }