예제 #1
0
 internal ScriptingSystem()
 {
     //AddinManager.AddExtensionNodeHandler("/Sharplike/Scripting", ScriptsChanged);
     foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes("/Sharplike/Scripting"))
     {
         IScriptingEngine eng = (IScriptingEngine)node.CreateInstance();
         engines.Add(node.Id, eng.Engine);
     }
 }
예제 #2
0
        public BeforeInsertValidator(string tableName, string script, ScriptingProvider provider)
        {
            _tableName = tableName;
            _provider  = provider;

            _scriptingEngine = provider switch
            {
                ScriptingProvider.Lua => new LuaScriptingEngine(script),
                ScriptingProvider.Javascript => new JavascriptScriptingEngine(script),
                _ => throw new ArgumentOutOfRangeException(nameof(provider), provider, null)
            };
        }
예제 #3
0
        void ScriptsChanged(object s, ExtensionNodeEventArgs args)
        {
            IScriptingEngine eng = (IScriptingEngine)args.ExtensionObject;

            switch (args.Change)
            {
            case ExtensionChange.Add:
                engines.Add(args.ExtensionNode.Id, eng.Engine);
                break;

            case ExtensionChange.Remove:
                engines.Remove(args.ExtensionNode.Id);
                break;
            }
        }
예제 #4
0
        static RuleBenchmark()
        {
            var services = RuleTests.CreateRuleServiceCollection()
                           .AddCondition <HomepageCondition, HomepageConditionEvaluator, ConditionFactory <HomepageCondition> >()
                           .AddSingleton <IGlobalMethodProvider, DefaultLayersMethodProvider>()
                           .AddMemoryCache()
                           .AddScripting()
                           .AddJavaScriptEngine();

            var mockHttpContextAccessor = new Mock <IHttpContextAccessor>();
            var context = new DefaultHttpContext();

            context.Request.Path = new PathString("/");
            mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(context);

            services.AddSingleton <IHttpContextAccessor>(mockHttpContextAccessor.Object);

            var serviceProvider = services.BuildServiceProvider();

            var scriptingManager = serviceProvider.GetRequiredService <IScriptingManager>();

            _engine = scriptingManager.GetScriptingEngine("js");
            _scope  = _engine.CreateScope(scriptingManager.GlobalMethodProviders.SelectMany(x => x.GetMethods()), serviceProvider, null, null);

            _ruleService = serviceProvider.GetRequiredService <IRuleService>();
            _rule        = new Rule
            {
                Conditions = new List <Condition>
                {
                    new HomepageCondition
                    {
                        Value = true
                    }
                }
            };
        }
예제 #5
0
        public void Load()
        {
            Status = new StatusViewModel();

            _scriptingEngine = new RoslynScriptingEngine();
        }
예제 #6
0
        public void Load()
        {
            Status = new StatusViewModel();

            _scriptingEngine = new RoslynScriptingEngine();
        }