示例#1
0
        //用于执行完成规则
        bool IScriptParser.EvaluateFinishRule(WorkItem workItem
                                              , List <DefaultHumanFinishRuleAsserter.Execution> allOtherExecutions
                                              , IDictionary <string, string> inputs
                                              , string action
                                              , string script)
        {
            var setting = workItem.GetReferredSetting();
            //断言
            var asserter = new DefaultHumanFinishRuleAsserter(setting.IsUsingSlot ? setting.SlotCount : new int?()
                                                              , new DefaultHumanFinishRuleAsserter.Execution(action, WorkItemStatus.Executed)
                                                              , allOtherExecutions);

            //初始化脚本引擎
            var engine = new Jurassic.ScriptEngine();

            //设置表达式
            engine.SetGlobalFunction("all", new Func <string, bool>(asserter.All));
            engine.SetGlobalFunction("atLeaseOf", new Func <int, string, bool>(asserter.AtLeaseOf));
            engine.SetGlobalFunction("atMostOf", new Func <int, string, bool>(asserter.AtMostOf));
            engine.SetGlobalFunction("noneOf", new Func <string, bool>(asserter.NoneOf));
            //填充变量
            foreach (var pair in inputs)
            {
                engine.SetGlobalValue(pair.Key, pair.Value ?? "");
            }

            return(this.Evaluate <bool>(engine, script));
        }
示例#2
0
文件: ImpactGame.cs 项目: Kevnz/JS360
        protected override void Initialize()
        {
            timers = new TimerManager();

            js = new Jurassic.ScriptEngine();
            js.SetGlobalFunction("setTimeout", new Action <Jurassic.Library.FunctionInstance, int>(setTimeout));
            js.SetGlobalFunction("setInterval", new Action <Jurassic.Library.FunctionInstance, int>(setInterval));
            js.SetGlobalFunction("clearTimeout", new Action <int>(clearTimeout));
            js.SetGlobalFunction("clearInterval", new Action <int>(clearInterval));

            js.SetGlobalValue("window", js.Global);
            js.SetGlobalValue("console", new JSConsole(js));
            js.SetGlobalValue("Canvas", new JSCanvasConstructor(js));
            js.SetGlobalValue("Image", new JSImageConstructor(js));

#if !XBOX
            if (GenerateAndExit != null)
            {
                GenerateAssemblyAndExit(GenerateAndExit);
                return;
            }
#endif

#if XBOX || RELEASE
            // On the XBOX or RELEASE config, run the compiled JavaScript from the Assembly
            js.LoadFromAssembly("ImpactGame");
            Generated.Main(js, js.CreateGlobalScope(), js.Global);
#else
            // In Windows/DEBUG, run JavaScript directly from source
            js.EnableDebugging = true;
            js.Evaluate(new Jurassic.FileScriptSource("Game/index.js"));
#endif
            base.Initialize();
        }
示例#3
0
        private Jurassic.ScriptEngine PrepareScriptEngine(Statements.DataFieldExtension extension)
        {
            var engine = new Jurassic.ScriptEngine();

            //注册方法列表
            this._invoker.GetMethods().ToList().ForEach(o =>
                                                        engine.SetGlobalFunction(o.Key
                                                                                 , new Func <object, object, object, object
                                                                                             //, object, object, object, object, object
                                                                                             , string>(
                                                                                     (v1, v2, v3, v4) =>
                                                                                     //, v5, v6, v7, v8, v9) =>
                                                                                     this.Invoke(o.Key, v1, v2, v3, v4))));
            //, v5, v6, v7, v8, v9))));

            //注册内置方法 会覆盖上述方法
            engine.SetGlobalFunction("updateDataField", new Action <string, string>((k, v) => extension.Set(k, v)));
            engine.SetGlobalFunction("split"
                                     , new Func <string, string, Jurassic.Library.ArrayInstance>((s, i) =>
                                                                                                 engine.Array.Call((i ?? "").Split(new string[] { s }, StringSplitOptions.RemoveEmptyEntries))));

            //注册依赖上下文的内置方法 会覆盖上述方法
            engine.SetGlobalFunction("getSuperior", new Func <string>(() => this._userHelper.GetSuperior(extension.Originator)));

            //注册流程变量
            foreach (var pair in extension.DataFields)
            {
                engine.SetGlobalValue(pair.Key, pair.Value ?? "");
            }

            //注册内置上下文变量 会覆盖上述流程变量
            engine.SetGlobalValue(WorkflowBuilder.Variable_Originator, extension.Originator);

            return(engine);
        }
示例#4
0
        private void Init()
        {
            if (BaseLocation == null)
            {
                BaseLocation = Extensibility.Instance.GetBaseLocation(this) ?? new Uri(System.Environment.CurrentDirectory);
            }

            _ctx = new Jurassic.ScriptEngine();
            _ctx.SetGlobalFunction("getContents", (Func <string, string>)GetContents);
            _ctx.SetGlobalFunction("getFullFilename", (Func <string, string>)GetFullFilename);
            Run(Zippy.Chirp.Properties.Resources.env);
            OnInit();
        }
示例#5
0
        public void EngineTest()
        {
            var engine = new Jurassic.ScriptEngine();
            engine.SetGlobalValue("i", 1);
            engine.SetGlobalValue("i", 2);
            Assert.AreEqual(2, engine.GetGlobalValue("i"));

            engine.SetGlobalFunction("test", new Func<object, object, object, object, string>(Test));

            Trace.WriteLine(engine.Evaluate<string>("test(1)"));
            Trace.WriteLine(engine.CallGlobalFunction<string>("test", new object[] { 1 }));

            Trace.WriteLine(engine.Array.Call(1, 2, 3).ElementValues.ToList()[2]);
        }
示例#6
0
        public void EngineTest()
        {
            var engine = new Jurassic.ScriptEngine();

            engine.SetGlobalValue("i", 1);
            engine.SetGlobalValue("i", 2);
            Assert.AreEqual(2, engine.GetGlobalValue("i"));

            engine.SetGlobalFunction("test", new Func <object, object, object, object, string>(Test));

            Trace.WriteLine(engine.Evaluate <string>("test(1)"));
            Trace.WriteLine(engine.CallGlobalFunction <string>("test", new object[] { 1 }));

            Trace.WriteLine(engine.Array.Call(1, 2, 3).ElementValues.ToList()[2]);
        }
        public bool Jurassic(Parameter parameter)
        {
            StringBuilder statementBuilder = new StringBuilder();

            for (int i = 0; i < parameter.Statements.Length; ++i)
            {
                statementBuilder.Append("setValue(").Append(i).Append(", ").Append(parameter.Statements[i]).AppendLine(");");
            }

            Jurassic.ScriptEngine engine = new Jurassic.ScriptEngine();

            int[] results = new int[parameter.Statements.Length];

            engine.SetGlobalFunction("setValue", new Action <int, int>((index, value) => results[index] = value));

            engine.Execute(statementBuilder.ToString());

            return(Assert(results, parameter.Sum));
        }
        protected override void InnerEmbedHostObject(string itemName, object value)
        {
            object processedValue = MapToJurassicType(value);

            try
            {
                var delegateValue = processedValue as Delegate;
                if (delegateValue != null)
                {
                    _jsEngine.SetGlobalFunction(itemName, delegateValue);
                }
                else
                {
                    _jsEngine.SetGlobalValue(itemName, processedValue);
                }
            }
            catch (OriginalJsException e)
            {
                throw ConvertJavascriptExceptionToJsRuntimeException(e);
            }
        }
        protected override void InnerEmbedHostObject(string itemName, object value)
        {
            object processedValue = MapToScriptType(value);

            lock (_executionSynchronizer)
            {
                try
                {
                    var delegateValue = processedValue as Delegate;
                    if (delegateValue != null)
                    {
                        _jsEngine.SetGlobalFunction(itemName, delegateValue);
                    }
                    else
                    {
                        _jsEngine.SetGlobalValue(itemName, processedValue);
                    }
                }
                catch (OriginalJavaScriptException e)
                {
                    throw WrapJavaScriptException(e);
                }
            }
        }
示例#10
0
        private void Init()
        {
            if (BaseLocation == null)
                BaseLocation = Extensibility.Instance.GetBaseLocation(this) ?? new Uri(System.Environment.CurrentDirectory);

            _ctx = new Jurassic.ScriptEngine();
            _ctx.SetGlobalFunction("getContents", (Func<string, string>)GetContents);
            _ctx.SetGlobalFunction("getFullFilename", (Func<string, string>)GetFullFilename);
            Run(Zippy.Chirp.Properties.Resources.env);
            OnInit();
        }
示例#11
0
        protected override void Initialize()
        {
            timers = new TimerManager();

            js = new Jurassic.ScriptEngine();
            js.SetGlobalFunction("setTimeout", new Action<Jurassic.Library.FunctionInstance, int>(setTimeout));
            js.SetGlobalFunction("setInterval", new Action<Jurassic.Library.FunctionInstance, int>(setInterval));
            js.SetGlobalFunction("clearTimeout", new Action<int>(clearTimeout));
            js.SetGlobalFunction("clearInterval", new Action<int>(clearInterval));

            js.SetGlobalValue("window", js.Global);
            js.SetGlobalValue("console", new JSConsole(js));
            js.SetGlobalValue("Canvas", new JSCanvasConstructor(js));
            js.SetGlobalValue("Image", new JSImageConstructor(js));

            #if !XBOX
            if (GenerateAndExit != null)
            {
                GenerateAssemblyAndExit(GenerateAndExit);
                return;
            }

            #endif

            #if XBOX || RELEASE
            // On the XBOX or RELEASE config, run the compiled JavaScript from the Assembly
            js.LoadFromAssembly("ImpactGame");
            Generated.Main(js, js.CreateGlobalScope(), js.Global);
            #else
            // In Windows/DEBUG, run JavaScript directly from source
            js.EnableDebugging = true;
            js.Evaluate(new Jurassic.FileScriptSource("Game/index.js"));
            #endif
            base.Initialize();
        }