Exemple #1
2
 public static string JSON2RJSON(string inpJson) {
   using (var engine = new Microsoft.ClearScript.V8.V8ScriptEngine()) {
     var script = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\RJSON.js";
     if (!File.Exists(script)) script = Machines.rootPath + @"JsLib\JS\External\RJSON.js";
     engine.Execute(script, File.ReadAllText(script));
     var par = new rjsonObj { inpJson = inpJson };
     engine.AddHostObject("inpJson", par);
     return (string)engine.Evaluate("JSON.stringify(RJSON.pack(JSON.parse(inpJson.inpJson)))");
   }
 }
Exemple #2
2
 public static void JsReflection(string tsFileName, string jsonMapFn) {
   using (var engine = new Microsoft.ClearScript.V8.V8ScriptEngine()) {
     engine.Execute("typescript.js", File.ReadAllText(@"d:\LMCom\rew\Web4\JsLib\Scripts\typescript.js"));
     engine.Execute("underscore.js", File.ReadAllText(@"d:\LMCom\rew\Web4\JsLib\Scripts\underscore.js"));
     engine.Execute("GenerateReflection.js", File.ReadAllText(@"d:\LMCom\rew\Web4\Author\GenerateReflection.js"));
     var par = new reflectionObj { inpTSCode = File.ReadAllText(tsFileName) };
     engine.AddHostObject("inpTSCode", par);
     File.WriteAllText(jsonMapFn + ".json", (string)engine.Evaluate("author.parseReflection(inpTSCode.inpTSCode, false)"));
     File.WriteAllText(jsonMapFn + ".debug.json", (string)engine.Evaluate("author.parseReflection(inpTSCode.inpTSCode, true)"));
   }
 }
Exemple #3
0
        private void ProcessRequire(string rootPath, Package package, Module module)
        {
            string currentPath = _fileSystem.Path.GetDirectoryName(module.FullPath);

            using (Microsoft.ClearScript.ScriptEngine engine = new Microsoft.ClearScript.V8.V8ScriptEngine())
            {
                Action <string> require = (entryPoint) =>
                {
                    ProcessModule(rootPath, package, entryPoint, currentPath);
                };
                engine.AddHostObject("require", new Action <string>(require));
                engine.Execute("(function(exports){try{" + module.TransformedContent + "}catch(e){}}({}));");
            }
        }
Exemple #4
0
        protected override void InnerEmbedHostObject(string itemName, object value)
        {
            object processedValue = MapToScriptType(value);

            try
            {
                _jsEngine.AddHostObject(itemName, processedValue);
            }
            catch (OriginalException e)
            {
                throw WrapScriptEngineException(e);
            }
            catch (OriginalInterruptedException e)
            {
                throw WrapScriptInterruptedException(e);
            }
        }
Exemple #5
0
        /// <summary>
        /// 编译传递的JavaScript 代码
        /// </summary>
        /// <param name="cid">默认需求本期开奖id,回测系统使用</param>
        /// <param name="code">编译代码</param>
        /// <returns></returns>
        public MessageScriptModel Builder(string expect, string code)
        {
            StringBuilder stringBuilder = new StringBuilder();

            string system     = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("/Js/CPQaunt.js"));
            string jsonparese = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("/Js/json_parse.js"));
            string json2      = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("/Js/json2.js"));

            stringBuilder.AppendLine(jsonparese);
            stringBuilder.AppendLine(json2);

            stringBuilder.AppendLine(system);
            stringBuilder.AppendLine(code);

            try
            {
                using (Microsoft.ClearScript.ScriptEngine engine = new Microsoft.ClearScript.V8.V8ScriptEngine())
                {
                    engine.AddHostObject("LotteryFacade", new CPQaunt.Facade.LotteryFacade());
                    engine.Execute(stringBuilder.ToString());

                    var s = engine.Script.main(expect);

                    MessageScriptModel message = new MessageScriptModel();
                    message.type   = MessageType.List;
                    message.status = true;

                    JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
                    jsSerializer.MaxJsonLength = Int32.MaxValue;

                    message.numbers = jsSerializer.Deserialize <List <NumberModel> >(s);

                    return(message);
                }
            }
            catch (Exception e)
            {
                MessageScriptModel message = new MessageScriptModel();
                message.type    = MessageType.Log;
                message.status  = false;
                message.message = e.Message;
                return(message);
            }
        }
        public static ServerScriptModelRow Execute(
            Context context,
            SiteSettings ss,
            BaseItemModel itemModel,
            View view,
            ServerScript[] scripts,
            bool onTesting = false)
        {
            if (!(Parameters.Script.ServerScript != false &&
                  context.ContractSettings.NewFeatures() &&
                  context.ContractSettings.Script != false))
            {
                return(null);
            }
            if (!(context?.ServerScriptDepth < 10))
            {
                return(null);
            }
            itemModel = itemModel ?? new BaseItemModel();
            ServerScriptModelRow scriptValues = null;

            using (var model = new ServerScriptModel(
                       context: context,
                       ss: ss,
                       data: Values(
                           context: context,
                           ss: ss,
                           model: itemModel),
                       columns: Columns(
                           context: context,
                           ss: ss),
                       columnFilterHash: view?.ColumnFilterHash,
                       columnSorterHash: view?.ColumnSorterHash,
                       onTesting: onTesting))
            {
                using (var engine = new Microsoft.ClearScript.V8.V8ScriptEngine(
                           Microsoft.ClearScript.V8.V8ScriptEngineFlags.EnableDateTimeConversion))
                {
                    try
                    {
                        engine.ContinuationCallback = model.ContinuationCallback;
                        engine.AddHostObject("context", model.Context);
                        engine.AddHostObject("model", model.Model);
                        engine.AddHostObject("depts", model.Depts);
                        engine.AddHostObject("groups", model.Groups);
                        engine.AddHostObject("users", model.Users);
                        engine.AddHostObject("columns", model.Columns);
                        engine.AddHostObject("siteSettings", model.SiteSettings);
                        engine.AddHostObject("view", model.View);
                        engine.AddHostObject("items", model.Items);
                        engine.AddHostObject("hidden", model.Hidden);
                        engine.AddHostObject("extendedSql", model.ExtendedSql);
                        engine.AddHostObject("notifications", model.Notification);
                        foreach (var script in scripts)
                        {
                            engine.Execute(script.Body);
                        }
                    }
                    finally
                    {
                        engine.ContinuationCallback = null;
                    }
                }
                scriptValues = SetValues(
                    context: context,
                    ss: ss,
                    model: itemModel,
                    view: view,
                    data: model);
            }
            return(scriptValues);
        }