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); } }
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) }; }
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; } }
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 } } }; }
public void Load() { Status = new StatusViewModel(); _scriptingEngine = new RoslynScriptingEngine(); }