Exemplo n.º 1
0
        public BaseRuntime(IPersistentStorage storage)
        {
            _compilation               = new Compilation(storage);
            _compilation.ToolStarted  += (sender, args) => notify(NotificationKind.System, "Starting tool: " + args.Tool.displayName + " for " + args.Document);
            _compilation.ToolFinished += (sender, args) =>
            {
                if (args.Result != null)
                {
                    bool hasError = args.Result.ContainsKey("error");
                    if (hasError)
                    {
                        notify(NotificationKind.Error, "Tool failed: " + args.Result["error"]);
                    }
                    else
                    {
                        foreach (var msg in args.Result)
                        {
                            notify(NotificationKind.System, msg.Key);
                        }
                    }
                }

                notify(NotificationKind.System, "Finished: " + args.Tool.displayName + " for " + args.Document);
            };


            foreach (var tool in _tools)
            {
                _compilation.registerTool(tool.Key, tool.Value);
            }

            _compilation.addCSharpFile("console", consoleTree);
            _compilation.addCSharpFile("random", randomTree);
        }
Exemplo n.º 2
0
        public BaseRuntime(IPersistentStorage storage)
        {
            _compilation = new Compilation(storage);
            _compilation.ToolStarted += (sender, args) => notify(NotificationKind.System, "Starting tool: " + args.Tool.displayName + " for " + args.Document);
            _compilation.ToolFinished += (sender, args) =>
            {
                if (args.Result != null)
                {
                    bool hasError = args.Result.ContainsKey("error");
                    if (hasError)
                        notify(NotificationKind.Error, "Tool failed: " + args.Result["error"]);
                    else
                    {
                        foreach(var msg in args.Result)
                            notify(NotificationKind.System, msg.Key);
                    }
                }

                notify(NotificationKind.System, "Finished: " + args.Tool.displayName + " for " + args.Document);
            };

            foreach (var tool in _tools)
            {
                _compilation.registerTool(tool.Key, tool.Value);
            }

            _compilation.addCSharpFile("console", consoleTree);
            _compilation.addCSharpFile("random", randomTree);
        }
Exemplo n.º 3
0
        public static dynamic ExecuteTest(string text, Action <ICompiler <SyntaxToken, SyntaxNode, SemanticModel> > config)
        {
            var compilation = new Excess.Compiler.Roslyn.Compilation(null);
            var injector    = new CompositeInjector <SyntaxToken, SyntaxNode, SemanticModel>(new[] {
                _main,
                new DelegateInjector <SyntaxToken, SyntaxNode, SemanticModel>(compiler => config(compiler))
            });

            compilation.addDocument("test", text, injector);

            Assembly assembly = compilation.build();

            if (assembly == null)
            {
                //debug
                StringBuilder errorLines = new StringBuilder();
                foreach (var error in compilation.errors())
                {
                    errorLines.AppendLine(error.ToString());
                }

                var errorString = errorLines.ToString();
                return(null);
            }

            Type testtype = assembly.GetType("testclass");
            //var method = console.GetMethod("test", BindingFlags.Static);

            var result = new Dictionary <string, object>();

            testtype.InvokeMember("test", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[] { result });

            var xo  = new ExpandoObject();
            var xod = xo as IDictionary <string, object>;

            foreach (var kp in result)
            {
                xod.Add(kp.Key, kp.Value);
            }

            return(xo);
        }
Exemplo n.º 4
0
    public static dynamic ExecuteTest(string text, Action<ICompiler<SyntaxToken, SyntaxNode, SemanticModel>> config)
    {
        var compilation = new Excess.Compiler.Roslyn.Compilation(null);
            var injector = new CompositeInjector<SyntaxToken, SyntaxNode, SemanticModel>(new[] {
                _main,
                new DelegateInjector<SyntaxToken, SyntaxNode, SemanticModel>(compiler => config(compiler))
            });

            compilation.addDocument("test", text, injector);

            Assembly assembly = compilation.build();
            if (assembly == null)
            {
                //debug
                StringBuilder errorLines = new StringBuilder();
                foreach (var error in compilation.errors())
                {
                    errorLines.AppendLine(error.ToString());
                }

                var errorString = errorLines.ToString();
                return null;
            }

            Type testtype = assembly.GetType("testclass");
            //var method = console.GetMethod("test", BindingFlags.Static);

            var result = new Dictionary<string, object>();
            testtype.InvokeMember("test", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[] { result });

            var xo = new ExpandoObject();
            var xod = xo as IDictionary<string, object>;
            foreach (var kp in result)
                xod.Add(kp.Key, kp.Value);

            return xo;
    }