Exemple #1
0
        public HostedScriptEngine()
        {
            _engine = new ScriptingEngine();
            _env    = new RuntimeEnvironment();
            _engine.AttachAssembly(System.Reflection.Assembly.GetExecutingAssembly(), _env);

            _globalCtx = new SystemGlobalContext();
            _globalCtx.EngineInstance = _engine;

            _env.InjectObject(_globalCtx, false);
        }
        private static void RegisterGlobalContext(Type contextType, RuntimeEnvironment environment)
        {
            var attribData = (GlobalContextAttribute)contextType.GetCustomAttributes(typeof(GlobalContextAttribute), false)[0];
            if (attribData.ManualRegistration)
                return;

            var method = contextType.GetMethod(INSTANCE_RETRIEVER_NAME, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
            System.Diagnostics.Trace.Assert(method != null, "Global context must have a static method " + INSTANCE_RETRIEVER_NAME);
            var instance = (IAttachableContext)method.Invoke(null, null);
            GlobalsManager.RegisterInstance(instance);
            environment.InjectObject(instance, false);

        }
        public WebApplicationEngine()
        {
            Engine             = new ScriptingEngine();
            Environment        = new RuntimeEnvironment();
            Engine.Environment = Environment;

            Engine.AttachAssembly(System.Reflection.Assembly.GetExecutingAssembly(), Environment);
            Engine.AttachAssembly(typeof(SystemGlobalContext).Assembly, Environment);
            Environment.InjectObject(new WebGlobalContext());
            Engine.Initialize();
            // TODO Убрать после реализации https://github.com/EvilBeaver/OneScript/issues/641
            TypeManager.RegisterType("Сценарий", typeof(UserScriptContextInstance));
            Engine.UpdateContexts();
        }
        public HostedScriptEngine()
        {
            _engine = new ScriptingEngine();
            _env = new RuntimeEnvironment();
            _engine.AttachAssembly(System.Reflection.Assembly.GetExecutingAssembly(), _env);

            _globalCtx = new SystemGlobalContext();
            _globalCtx.EngineInstance = _engine;

            _env.InjectObject(_globalCtx, false);
            _engine.Environment = _env;
            
            InitLibrariesByDefault();

        }
        private static void RegisterGlobalContext(Type contextType, RuntimeEnvironment environment)
        {
            var attribData = (GlobalContextAttribute)contextType.GetCustomAttributes(typeof(GlobalContextAttribute), false)[0];

            if (attribData.ManualRegistration)
            {
                return;
            }

            var method = contextType.GetMethod(INSTANCE_RETRIEVER_NAME, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);

            System.Diagnostics.Trace.Assert(method != null, "Global context must have a static method " + INSTANCE_RETRIEVER_NAME);
            var instance = (IAttachableContext)method.Invoke(null, null);

            GlobalsManager.RegisterInstance(instance);
            environment.InjectObject(instance, false);
        }
        public HostedScriptEngine()
        {
            _engine = new ScriptingEngine();
            _env    = new RuntimeEnvironment();
            _engine.AttachAssembly(System.Reflection.Assembly.GetExecutingAssembly(), _env);

            _globalCtx = new SystemGlobalContext();
            _globalCtx.EngineInstance = _engine;

            _env.InjectObject(_globalCtx, false);

            InitializationCallback = (eng, env) =>
            {
                var templateFactory = new DefaultTemplatesFactory();
                var storage         = new TemplateStorage(templateFactory);
                env.InjectObject(storage);
                GlobalsManager.RegisterInstance(storage);
            };

            _engine.Environment = _env;
        }
 public void InjectObject(IAttachableContext obj, bool asDynamicScope)
 {
     _env.InjectObject(obj, asDynamicScope);
 }