Ejemplo n.º 1
0
        public HostedScriptEngine StartEngine()
        {
            engine = new HostedScriptEngine();
            engine.Initialize();

            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(v8unpack.File8Reader)));

            // Подключаем тестовую оболочку
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(EngineHelpWrapper)));

            var testrunnerSource = LoadFromAssemblyResource("NUnitTests.Tests.testrunner.os");
            var testrunnerModule = engine.GetCompilerService().CreateModule(testrunnerSource);

            engine.LoadUserScript(new ScriptEngine.UserAddedScript()
            {
                Type   = ScriptEngine.UserAddedScriptType.Class,
                Module = testrunnerModule,
                Symbol = "TestRunner"
            });

            var testRunner = AttachedScriptsFactory.ScriptFactory("TestRunner", new IValue[] { });

            TestRunner = ValueFactory.Create(testRunner);

            return(engine);
        }
Ejemplo n.º 2
0
        public HostedScriptEngine StartEngine()
        {
            engine = new HostedScriptEngine();
            engine.Initialize();

            // Тут можно указать любой класс из компоненты
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(Bracker.BrackerWriterImpl)));

            // Если проектов компонент несколько, то надо взять по классу из каждой из них
            // engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent_2.MyClass_2)));
            // engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent_3.MyClass_3)));

            // Подключаем тестовую оболочку
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(EngineHelpWrapper)));

            var testrunnerSource = LoadFromAssemblyResource("NUnitTests.Tests.testrunner.os");
            var testrunnerModule = engine.GetCompilerService().CreateModule(testrunnerSource);

            engine.LoadUserScript(new ScriptEngine.UserAddedScript()
            {
                Type   = ScriptEngine.UserAddedScriptType.Class,
                Module = testrunnerModule,
                Symbol = "TestRunner"
            });

            var testRunner = AttachedScriptsFactory.ScriptFactory("TestRunner", new IValue[] { });

            TestRunner = ValueFactory.Create(testRunner);

            return(engine);
        }
Ejemplo n.º 3
0
        public HostedScriptEngine StartEngine()
        {
            engine = new HostedScriptEngine();
            engine.Initialize();


            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(OMyGodEco)));

            // Подключаем тестовую оболочку
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(EngineHelpWrapper)));

            var testrunnerSource = LoadFromAssemblyResource("NUnitTests.Tests.testrunner.os");
            var testrunnerModule = engine.GetCompilerService()
                                   .Compile(testrunnerSource);

            {
                var mi = engine.GetType().GetMethod("SetGlobalEnvironment",
                                                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance);
                mi.Invoke(engine, new object[] { this, testrunnerSource });
            }

            engine.LoadUserScript(new ScriptEngine.UserAddedScript()
            {
                Type   = ScriptEngine.UserAddedScriptType.Class,
                Image  = testrunnerModule,
                Symbol = "TestRunner"
            });

            var testRunner = AttachedScriptsFactory.ScriptFactory("TestRunner", new IValue[] { });

            TestRunner = ValueFactory.Create(testRunner);

            return(engine);
        }
Ejemplo n.º 4
0
        public void Initialize()
        {
            SetDefaultEnvironmentIfNeeded();

            UpdateContexts();

            _attachedScriptsFactory = new AttachedScriptsFactory(this);
            AttachedScriptsFactory.SetInstance(_attachedScriptsFactory);
        }
Ejemplo n.º 5
0
        public void Initialize(RuntimeEnvironment environment)
        {
            _symbolsContext = environment.SymbolsContext;

            foreach (var item in environment.AttachedContexts)
            {
                _machine.AttachContext(item, false);
            }

            _attachedScriptsFactory = new AttachedScriptsFactory(this);
            AttachedScriptsFactory.SetInstance(_attachedScriptsFactory);
        }
Ejemplo n.º 6
0
        public void Initialize()
        {
            SetDefaultEnvironmentIfNeeded();

            var symbolsContext = Environment.SymbolsContext;

            _machine.Cleanup();
            foreach (var item in Environment.AttachedContexts)
            {
                _machine.AttachContext(item, false);
            }

            _attachedScriptsFactory = new AttachedScriptsFactory(this);
            AttachedScriptsFactory.SetInstance(_attachedScriptsFactory);
        }
Ejemplo n.º 7
0
        public static Type ReflectUserType(string typeName)
        {
            LoadedModule module;

            try
            {
                module = AttachedScriptsFactory.GetModuleOfType(typeName);
            }
            catch (KeyNotFoundException)
            {
                throw NonReflectableType();
            }

            var builder = new ClassBuilder <UserScriptContextInstance>();

            return(builder
                   .SetTypeName(typeName)
                   .SetModule(module)
                   .ExportDefaults()
                   .Build());
        }
        public void RunTestScript(string resourceName)
        {
            var source        = LoadFromAssemblyResource(resourceName);
            var bytecodeImage = engine.GetCompilerService().Compile(source);

            engine.LoadUserScript(new ScriptEngine.UserAddedScript()
            {
                Type   = ScriptEngine.UserAddedScriptType.Class,
                Image  = bytecodeImage,
                Symbol = resourceName
            });

            var       test = AttachedScriptsFactory.ScriptFactory(resourceName, new IValue[] { });
            ArrayImpl testArray;

            {
                int methodIndex = test.FindMethod("ПолучитьСписокТестов");

                {
                    IValue ivTests;
                    test.CallAsFunction(methodIndex, new IValue[] { TestRunner }, out ivTests);
                    testArray = ivTests as ArrayImpl;
                }
            }

            foreach (var ivTestName in testArray)
            {
                string testName    = ivTestName.AsString();
                int    methodIndex = test.FindMethod(testName);
                if (methodIndex == -1)
                {
                    // Тест указан, но процедуры нет или она не экспортирована
                    continue;
                }

                test.CallAsProcedure(methodIndex, new IValue[] { });
            }
        }
        public HostedScriptEngine StartEngine()
        {
            engine = new HostedScriptEngine();
            engine.Initialize();

            // Тут можно указать любой класс из компоненты
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent.MyClass)));

            // Если проектов компонент несколько, то надо взять по классу из каждой из них
            // engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent_2.MyClass_2)));
            // engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent_3.MyClass_3)));

            // Подключаем тестовую оболочку
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(EngineHelpWrapper)));

            var testrunnerSource = LoadFromAssemblyResource("NUnitTests.Tests.testrunner.os");
            var testrunnerModule = engine.GetCompilerService().Compile(testrunnerSource);

            {
                var mi = engine.GetType().GetMethod("SetGlobalEnvironment",
                                                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance);
                mi.Invoke(engine, new object[] { this, testrunnerSource });
            }

            engine.LoadUserScript(new ScriptEngine.UserAddedScript()
            {
                Type   = ScriptEngine.UserAddedScriptType.Class,
                Image  = testrunnerModule,
                Symbol = "TestRunner"
            });

            var testRunner = AttachedScriptsFactory.ScriptFactory("TestRunner", new IValue[] { });

            TestRunner = ValueFactory.Create(testRunner);

            return(engine);
        }
Ejemplo n.º 10
0
 public void Dispose()
 {
     AttachedScriptsFactory.Dispose();
 }
Ejemplo n.º 11
0
 public void Dispose()
 {
     AttachedScriptsFactory.SetInstance(null);
     GlobalsManager.Reset();
 }
Ejemplo n.º 12
0
 public void Dispose()
 {
     AttachedScriptsFactory.SetInstance(null);
 }