public void load(string path)
        {
            var fpath = path.Replace("~", _jsroot).Replace("$Common", _commlib).Replace("$RunTime", _runtimelib);

            if (File.Exists(fpath))
            {
                var js = File.ReadAllText(fpath, Encoding.UTF8);
                jse.Evaluate(js);
            }
        }
Beispiel #2
0
 /// <summary>
 /// 根据json创建数组对象
 /// </summary>
 /// <param name="arrjsonstring"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public static object[] CreateArray(string arrjsonstring, params KeyValuePair <string, object>[] context)
 {
     if (!string.IsNullOrEmpty(arrjsonstring))
     {
         HostJs jse = HostJs.NewInstance();
         try
         {
             string js = "var out=" + arrjsonstring;
             if (context != null)
             {
                 jse.Evaluate(js, context);
             }
             else
             {
                 jse.Evaluate(js);
             }
             var d = jse.GetOutObject("out");
             if (d is object[])
             {
                 return((object[])d);
             }
             else
             {
                 return(null);
             }
         }
         finally
         {
             jse.Release();
         }
     }
     else
     {
         return(null);
     }
 }
Beispiel #3
0
        /// <summary>
        /// 根据json串创建动态对象
        /// </summary>
        /// <param name="jsonstring"></param>
        /// <param name="flags"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static dynamic CreateInstance(string jsonstring, FrameDLRFlags flags, params KeyValuePair <string, object>[] context)
        {
            FrameDLRObject rtn = null;

            if (!string.IsNullOrEmpty(jsonstring))
            {
                HostJs jse = HostJs.NewInstance();
                try
                {
                    XmlDocument xd = null;
                    if (jsonstring.Trim().StartsWith("<") && TryParseXml(ComFunc.nvl(jsonstring), out xd))
                    {
                        if (xd.FirstChild.NodeType == XmlNodeType.XmlDeclaration)
                        {
                            if (xd.ChildNodes.Count == 2)
                            {
                                rtn = BuildLoopXml(xd.ChildNodes[1].ChildNodes, flags);
                            }
                            else
                            {
                                rtn = BuildLoopXml(xd.ChildNodes, flags);
                            }
                        }
                        else
                        {
                            if (xd.ChildNodes.Count == 1)
                            {
                                rtn = BuildLoopXml(xd.FirstChild.ChildNodes, flags);
                            }
                            else
                            {
                                rtn = BuildLoopXml(xd.ChildNodes, flags);
                            }
                        }
                    }
                    else
                    {
                        string js = "var out=" + jsonstring;
                        if (context != null)
                        {
                            jse.Evaluate(js, context);
                        }
                        else
                        {
                            jse.Evaluate(js);
                        }
                        var d = (Dictionary <string, object>)jse.GetOutObject("out");
                        rtn = BuildLoopDics(d, flags);
                    }
                }
                finally
                {
                    jse.Release();
                }
            }
            else
            {
                rtn = CreateInstance();
            }
            rtn.ori_jsongstring = jsonstring;
            return(rtn);
        }