mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Calling from clr to dlr without using dynamic callsite
Avoids callsite rule table - enables more memory to gc sooner --HG-- branch : perf
This commit is contained in:
@@ -38,6 +38,10 @@
|
||||
<HintPath>..\..\..\..\lib\claysharp\ClaySharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.Scripting, Version=1.1.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\lib\dlr\Microsoft.Scripting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Web.DynamicData" />
|
||||
|
@@ -14,7 +14,7 @@ namespace Orchard.Widgets.RuleEngine {
|
||||
}
|
||||
|
||||
public bool Matches(string expression) {
|
||||
dynamic execContext = _scriptingManager.ExecuteExpression(@"
|
||||
object execContextType = _scriptingManager.ExecuteExpression(@"
|
||||
class ExecContext
|
||||
def execute(callbacks, text)
|
||||
@callbacks = callbacks;
|
||||
@@ -27,13 +27,16 @@ namespace Orchard.Widgets.RuleEngine {
|
||||
@callbacks.send(name, args, &block);
|
||||
end
|
||||
end
|
||||
ExecContext.new()");
|
||||
return execContext.execute(new CallbackApi(this), expression);
|
||||
ExecContext
|
||||
");
|
||||
|
||||
object execContext = _scriptingManager.ExecuteOperation(ops => ops.CreateInstance(execContextType));
|
||||
return _scriptingManager.ExecuteOperation(ops => ops.InvokeMember(execContext, "execute", new CallbackApi(this), expression));
|
||||
}
|
||||
|
||||
public class CallbackApi {
|
||||
private readonly RuleManager _ruleManager;
|
||||
|
||||
|
||||
public CallbackApi(RuleManager ruleManager) {
|
||||
_ruleManager = ruleManager;
|
||||
}
|
||||
@@ -44,7 +47,7 @@ namespace Orchard.Widgets.RuleEngine {
|
||||
}
|
||||
|
||||
private object Evaluate(string name, IList<object> args) {
|
||||
RuleContext ruleContext = new RuleContext {FunctionName = name, Arguments = args.ToArray()};
|
||||
RuleContext ruleContext = new RuleContext { FunctionName = name, Arguments = args.ToArray() };
|
||||
|
||||
foreach (var ruleProvider in _ruleProviders) {
|
||||
ruleProvider.Process(ruleContext);
|
||||
|
@@ -1,8 +1,12 @@
|
||||
namespace Orchard.Scripting {
|
||||
using System;
|
||||
using Microsoft.Scripting.Hosting;
|
||||
|
||||
namespace Orchard.Scripting {
|
||||
public interface IScriptingManager : IDependency {
|
||||
dynamic GetVariable(string name);
|
||||
void SetVariable(string name, object value);
|
||||
dynamic ExecuteExpression(string expression);
|
||||
void ExecuteFile(string fileName);
|
||||
dynamic ExecuteOperation(Func<ObjectOperations, object> invoke);
|
||||
}
|
||||
}
|
||||
|
@@ -5,10 +5,12 @@ namespace Orchard.Scripting {
|
||||
public class ScriptingManager : IScriptingManager {
|
||||
private readonly IScriptingRuntime _scriptingRuntime;
|
||||
private Lazy<ScriptScope> _scope;
|
||||
private Lazy<ObjectOperations> _operations;
|
||||
|
||||
public ScriptingManager(IScriptingRuntime scriptingRuntime) {
|
||||
_scriptingRuntime = scriptingRuntime;
|
||||
_scope = new Lazy<ScriptScope>(()=>_scriptingRuntime.CreateScope());
|
||||
_operations = new Lazy<ObjectOperations>(()=>_scope.Value.Engine.CreateOperations());
|
||||
}
|
||||
|
||||
public dynamic GetVariable(string name) {
|
||||
@@ -23,6 +25,10 @@ namespace Orchard.Scripting {
|
||||
return _scriptingRuntime.ExecuteExpression(expression, _scope.Value);
|
||||
}
|
||||
|
||||
public dynamic ExecuteOperation(Func<ObjectOperations, dynamic> invoke) {
|
||||
return invoke(_operations.Value);
|
||||
}
|
||||
|
||||
public void ExecuteFile(string fileName) {
|
||||
_scriptingRuntime.ExecuteFile(fileName, _scope.Value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user