Exemplo n.º 1
0
 public override Map Execute(Map input, ServerFacade sf, ConfigHelper cfg, out bool hasMore, out bool cut)
 {
     hasMore = false;
     var text = this.GetString("content");
     var cached = this["cached"] as ScriptEngine;
     if (cached == null) {
         var script = new ScriptEngine();
         script.References("Solari.Core.dll");
         script.Using("Solari.Core");
         script.DeclareGlobal("sf", typeof(ServerFacade), sf);
         script.DeclareGlobal("cfg", typeof(Map), cfg.Data);
         script.DeclareGlobal("context", typeof(Map), this);
         try {
             script.SetCode("public bool Filter(Map input) { " + text + " ; return false; }");
             script.Compile();
             this["cached"] = script;
             cut = !(bool)script.Execute("Filter", input);
             return input;
         } catch (Exception ex) {
             throw new ScriptingException(ex);
         }
     } else {
         var script = cached;
         try {
             cut = !(bool)script.Execute("Filter", input);
             return input;
         } catch (Exception ex) {
             throw new ScriptingException(ex);
         }
     }
 }
Exemplo n.º 2
0
 public override Map Execute(Map input, ServerFacade sf, ConfigHelper cfg, out bool hasMore, out bool cut)
 {
     hasMore = cut = false;
     var text = this.GetString("content");
     var cached = this["cached"] as ScriptEngine;
     if (cached == null) {
         System.Diagnostics.Debug.WriteLine("Compila script per " + this.Uid);
         var script = new ScriptEngine();
         script.References("Solari.Core.dll");
         script.Using("Solari.Core");
         script.DeclareGlobal("sf", typeof (ServerFacade), sf);
         script.DeclareGlobal("cfg", typeof (Map), cfg.Data);
         script.DeclareGlobal("context", typeof (Map), this);
         script.DeclareGlobal("hasMore", typeof (bool), false);
         try {
             script.SetCode("public Map DoExecute(Map input) { hasMore = false; " + text + " ; return input; }");
             script.Compile();
             this["cached"] = script;
             var ret = script.Execute("DoExecute", input) as Map;
             hasMore = (bool) script.GlobalGet("hasMore");
             return ret;
         }
         catch (Exception ex) {
             throw new ScriptingException(ex);
         }
     } else {
         System.Diagnostics.Debug.WriteLine("Trova in cache script per " + this.Uid);
         var script = cached;
         try {
             var ret = script.Execute("DoExecute", input) as Map;
             hasMore = (bool)script.GlobalGet("hasMore");
             return ret;
         } catch (Exception ex) {
             throw new ScriptingException(ex);
         }
     }
 }