Exemplo n.º 1
0
 public JsDocument(HostJs je, string jsroot)
 {
     _commlib    = jsroot;
     _runtimelib = jsroot + HostJsConstants.COMPILED_ROOT_PATH;
     _jsroot     = jsroot;
     jse         = je;
 }
Exemplo n.º 2
0
 public JsDocument(HostJs je, string jsroot, string commlibpath, string runtimelibpath)
 {
     _commlib    = commlibpath;
     _runtimelib = runtimelibpath;
     _jsroot     = jsroot;
     jse         = je;
 }
Exemplo n.º 3
0
        public HostLogicContext()
        {
            _currentjse = HostJs.NewInstance();
            var loadtag   = new LoadParser();
            var reftag    = new RefParser();
            var copytag   = new CopyParser();
            var actiontag = new ActionTag();

            //按照先后处理标签的顺序进行标签处理
            _hosttag.Add(loadtag.TagName, loadtag);
            _hosttag.Add(reftag.TagName, reftag);
            _hosttag.Add(copytag.TagName, copytag);
            _hosttag.Add(actiontag.TagName, actiontag);
            RootPath       = GlobalCommon.HostCommon.RootPath;
            CommonLibPath  = GlobalCommon.HostCommon.RootPath;
            RunTimeLibPath = GlobalCommon.HostCommon.RootPath + HostJsConstants.COMPILED_ROOT_PATH;
        }
Exemplo n.º 4
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);
     }
 }
 public ViewDocument(HostJs hostjs)
 {
     jse = hostjs;
 }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public static void Test()
        {
            Console.OutputEncoding = Encoding.UTF8;
            var dt     = DateTime.Now;
            var sctb   = new StaticClassTest("a");
            var m_type = sctb.GetType();

            Console.WriteLine($"1.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;

            var           method = m_type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
            List <string> atl    = new List <string>();

            foreach (var m in method)
            {
                if (m.CustomAttributes.Count() > 0)
                {
                    foreach (var ca in m.CustomAttributes)
                    {
                        atl.Add(ca.AttributeType.Name.Replace("attribute", ""));
                    }
                }
            }
            //var list = m_type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)
            //       .Where(m => m.Name.ToLower() == "post")
            //       .OrderBy(p => p.GetParameters().Length)
            //       .ToList();
            Console.WriteLine($"2.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            atl.Clear();
            for (int i = 0; i < 10; i++)
            {
                var l = method
                        .Where(m => m.CustomAttributes.Count() > 0)
                        .Select(m => m.CustomAttributes.Select(sl => sl.AttributeType.Name.Replace("attribute", "")));
                Console.WriteLine($"3.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            }
            //foreach (var item in l)
            //{
            //    atl.AddRange(item);
            //}
            Console.WriteLine($"3.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            for (int i = 0; i < 10; i++)
            {
                var l = method
                        .Where(m => !m.IsGenericMethod)
                        .Where(m => m.CustomAttributes.Count() > 0)
                        .Select(m => m.CustomAttributes.Select(sl => sl.AttributeType.Name.Replace("attribute", "")));
                Console.WriteLine($"3.1.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            }
            var filterlist = atl.Distinct().ToList();

            Console.WriteLine($"4.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;

            var s = FrameExposedClass.From(typeof(StaticClassTest));

            Console.WriteLine($"5.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            var ff = FrameExposedObject.From(typeof(StaticClassTest));

            Console.WriteLine($"6.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            s.Check(new object[] { "ych", 1 });
            //StaticClassTest.Check("a");
            Console.WriteLine($"7.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            ff.CheckMe(new object[] { "ych2", 2 });
            Console.WriteLine($"8.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            s.Check(new object[] { "ych", 1 });
            //StaticClassTest.Check("a");
            Console.WriteLine($"9.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            HostJs.DefaultEngineName = "";
            var fdlr = FrameDLRObject.CreateInstance(@"{
issuccess:true,
msg:''
}");

            Console.WriteLine($"10" +
                              $".time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            for (var i = 0; i < 10; i++)
            {
                var fdlr2 = FrameDLRObject.CreateInstanceFromat(@"{
issuccess:false,
msg:'{0}'
}", DateTime.Now.ToString("fff"));
                Console.WriteLine($"11" +
                                  $".time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            }
            for (var i = 0; i < 10; i++)
            {
                var fdlr2 = FrameDLRObject.CreateInstanceFromat(@"{
issuccess:true,
name:{1},
msg:'{0}',
ep:{
        age:20,
        sex:'male'
    }
}", DateTime.Now.ToString("fff"), "ych");
                Console.Write(((FrameDLRObject)fdlr2).ToJSONString());
                Console.WriteLine($"11.1" +
                                  $".time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            }
            for (var i = 0; i < 10; i++)
            {
                var fdlr2 = FrameDLRObject.CreateInstanceFromat(@"{
issuccess:false,
msg:'{0}'
}", DateTime.Now.ToString("fff"));
                Console.WriteLine($"11.2" +
                                  $".time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            }
            //fdlr.getvalue("a");

            for (var i = 0; i < 10; i++)
            {
                var fdlr3 = FrameDLRObject.CreateInstance(new
                {
                    issuccess = false,
                    msg       = ""
                });
                Console.WriteLine($"12" +
                                  $".time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
                ((FrameDLRObject)fdlr3).ToJSONString();
                Console.WriteLine($"12.1" +
                                  $".time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            }
            for (var i = 0; i < 10; i++)
            {
                var fdlr3 = FrameDLRObject.CreateInstance(new
                {
                    issuccess = true,
                    msg       = "哈哈"
                });
                Console.WriteLine($"13" +
                                  $".time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;

                Console.WriteLine($"13.1" +
                                  $".time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            }
            //s.Check(new object[] { "ych", 1 });
            //Console.WriteLine($"time cast {(DateTime.Now - dt).TotalMilliseconds}ms");
            //dt = DateTime.Now;
            //s = FrameExposedClass.From(typeof(StaticClassTestB));
            //if (((FrameExposedClass)s).HasMethod("Check"))
            //    s.Check(new object[] { "ych", 1, 23, 1 });
            //Console.WriteLine($"time cast {(DateTime.Now - dt).TotalMilliseconds}ms");
            //dt = DateTime.Now;
            //List<int> realList = new List<int>();

            //dynamic exposedList = FrameExposedObject.From(realList);

            //// Read a private field - prints 0
            //Console.WriteLine(exposedList._size);

            //// Modify a private field
            //exposedList._items = new int[] { 5, 4, 3, 2, 1 };

            //// Modify another private field
            //exposedList._size = 5;

            //// Call a private method
            //exposedList.EnsureCapacity(20);


            //// Add a value to the list
            //exposedList.Add(0);

            //// Enumerate the list. Prints "5 4 3 2 1 0"
            //foreach (var x in exposedList) Console.WriteLine(x);

            //Console.WriteLine($"time cast {(DateTime.Now - dt).TotalMilliseconds}ms");
            var jse = HostJs.NewInstance("chakra");

            for (var i = 0; i < 10; i++)
            {
                var re = jse.Evaluate(@"function test(){c.WriteLine('js run');return {issuccess:true,msg:''}} test();", new KeyValuePair <string, object>("c", new Conss()));

                Console.WriteLine($"20.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            }
            for (var i = 0; i < 10; i++)
            {
                var re = jse.Evaluate(@"function test(){c.WriteLine('js2 run'+new Date().getYear());return {issuccess:false,msg:'呵呵'}} test();", new KeyValuePair <string, object>("c", new Conss2()));

                Console.WriteLine($"20.time cast {(DateTime.Now - dt).TotalMilliseconds}ms"); dt = DateTime.Now;
            }
            jse.Dispose();
            //dt = DateTime.Now;
            //jse = HostJs.NewInstance("");
            //re = jse.Evaluate(@"function test2(){c.WriteLine('js2 run');return {issuccess:false,msg:''}} test2();", new KeyValuePair<string, object>("c", new Conss()));
            //jse.Dispose();
            //Console.WriteLine($"time cast {(DateTime.Now - dt).TotalMilliseconds}ms");
            Console.ReadKey();
        }
Exemplo n.º 8
0
 public HostLogicContext(HostJs jse)
 {
     _currentjse = jse;
 }