예제 #1
0
        public void CreateNestListDTO()
        {
            DTObject dto = DTObject.CreateReusable("{items:[{v,n,childs:[{v,n}]}]}");

            DTObject objItems = dto.CreateAndPush("items");

            objItems.SetValue("v", 0);
            objItems.SetValue("n", string.Format("item{0}", 0));

            objItems = dto.CreateAndPush("items");
            objItems.SetValue("v", 1);
            objItems.SetValue("n", string.Format("item{0}", 1));

            DTObject objChilds = objItems.CreateAndPush("childs");

            objChilds.SetValue("v", 10);
            objChilds.SetValue("n", string.Format("child{0}", 10));

            objChilds = objItems.CreateAndPush("childs");
            objChilds.SetValue("v", 20);
            objChilds.SetValue("n", string.Format("child{0}", 20));


            //Assert.AreEqual("{\"items\":[{\"v\",\"n\",\"childs\":[{\"v\",\"n\"}]}]}", dto.GetCode(false));
            Assert.AreEqual("{\"items\":[{\"childs\":[],\"n\":\"item0\",\"v\":0},{\"childs\":[{\"n\":\"child10\",\"v\":10},{\"n\":\"child20\",\"v\":20}],\"n\":\"item1\",\"v\":1}]}", dto.GetCode(true));
        }
예제 #2
0
        private static DTObject Load(string language, string fileName, string group)
        {
            DTObject dto = DTObject.Create("{childs:[{name,icon,code,childs:[{}]}]}");

            try
            {
                var groupNode = GetGroupNode(fileName, group);
                if (groupNode != null)
                {
                    foreach (XmlNode node in groupNode.ChildNodes)
                    {
                        if (node.NodeType != XmlNodeType.Element)
                        {
                            continue;
                        }
                        var child = dto.CreateAndPush("childs");
                        FillMenuItem(child, node, language);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(dto);
        }
예제 #3
0
        private static void FillMenuItem(DTObject item, XmlNode node, string language)
        {
            string url = GetNodeValue(node, "url"), target = GetNodeValue(node, "target");
            var    codeDTO = DTObject.Create();

            if (!string.IsNullOrEmpty(url))
            {
                codeDTO.SetValue("url", url);
                if (!string.IsNullOrEmpty(target))
                {
                    codeDTO.SetValue("target", target);
                }
            }

            string name = GetNodeValue(node, "name");

            name = ParseName(name, language);
            string icon         = GetNodeValue(node, "icon");
            string iconFontSize = GetNodeValue(node, "iconFontSize");
            string tags         = GetNodeValue(node, "tags");
            string roles        = GetNodeValue(node, "roles");

            if (!string.IsNullOrEmpty(icon))
            {
                item.SetValue("icon", icon);
            }
            if (!string.IsNullOrEmpty(iconFontSize))
            {
                item.SetValue("iconFontSize", iconFontSize);
            }
            if (!string.IsNullOrEmpty(tags))
            {
                var temp = tags.Split(',');
                item.Push("tags", temp, (t, tag) =>
                {
                    t.SetValue(tag);
                });
            }
            if (!string.IsNullOrEmpty(roles))
            {
                var temp = roles.Split(',');
                item.Push("roles", temp, (t, role) =>
                {
                    t.SetValue(role);
                });
            }
            item.SetValue("name", name);
            item.SetObject("code", codeDTO);

            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                var child = item.CreateAndPush("childs");
                FillMenuItem(child, childNode, language);
            }
        }
예제 #4
0
 public override void Write(DTObject data)
 {
     foreach (var item in _items)
     {
         if (!item.IsNull())
         {
             var d = data.CreateAndPush(this.MemberName);
             d.Load(item);
         }
     }
 }
예제 #5
0
        public void CreateListDTO()
        {
            DTObject dto = DTObject.CreateReusable("{id,name,hobby:[{v,n}]}");

            dto.SetValue("id", 1);
            dto.SetValue("name", "Louis");
            DTObject obj = dto.CreateAndPush("hobby");

            obj.SetValue("v", 0);
            obj.SetValue("n", string.Format("LS{0}", 0));

            obj = dto.CreateAndPush("hobby");
            obj.SetValue("v", 1);
            obj.SetValue("n", string.Format("LS{0}", 1));

            DTObjects list = dto.GetList("hobby");

            for (int i = 0; i < list.Count; i++)
            {
                Assert.AreEqual(i, list[i].GetValue <int>("v"));
                Assert.AreEqual(string.Format("LS{0}", i), list[i].GetValue <string>("n"));
            }

            Assert.AreEqual(1, dto.GetValue <int>("id"));
            Assert.AreEqual("Louis", dto.GetValue <string>("name"));
            //Assert.AreEqual("{\"id\",\"name\",\"hobby\":[{\"v\",\"n\"}]}", dto.GetCode(false));
            //Assert.AreEqual("{\"id\":1,\"name\":\"Louis\",\"hobby\":[{\"v\":0,\"n\":\"LS0\"},{\"v\":1,\"n\":\"LS1\"}]}", dto.GetCode());

            var code = dto.GetCode();
            var copy = DTObject.CreateReusable(code);

            list = dto.GetList("hobby");
            for (int i = 0; i < list.Count; i++)
            {
                Assert.AreEqual(i, list[i].GetValue <int>("v"));
                Assert.AreEqual(string.Format("LS{0}", i), list[i].GetValue <string>("n"));
            }

            Assert.AreEqual(1, dto.GetValue <int>("id"));
            Assert.AreEqual("Louis", dto.GetValue <string>("name"));
        }
예제 #6
0
        public void CreateDTOByPerformance()
        {
            DTObject dto = DTObject.CreateReusable("{id,name,childs:[{id,name}]}");

            dto.SetValue("id", 1);
            dto.SetValue("name", "刘备");

            var child0 = dto.CreateAndPush("childs");

            child0.SetValue("id", 2);
            child0.SetValue("name", "赵云");

            var child1 = dto.CreateAndPush("childs");

            child1.SetValue("id", 3);
            child1.SetValue("name", "马超");

            //Assert.AreEqual("{\"id\",\"name\",\"childs\":[{\"id\",\"name\"}]}", dto.GetCode(false));

            StringBuilder code = new StringBuilder();

            code.Append("{\"childs\":[");
            code.Append("{\"id\":2,\"name\":\"赵云\"},");
            code.Append("{\"id\":3,\"name\":\"马超\"}");
            code.Append("],\"id\":1,\"name\":\"刘备\"}");

            Assert.AreEqual(code.ToString(), dto.GetCode(true));

            //var data = TimeMonitor.Oversee(() =>
            //{
            //    for (var i = 0; i < 10000; i++)
            //    {
            //        DTObject.Create("{id,name,childs:[{id,name}]}");
            //    }
            //});
            //Assert.IsTrue(false, data.GetTime(0).ElapsedMilliseconds.ToString());
        }
예제 #7
0
        public void CreateSymbolDTO()
        {
            DTObject dto = DTObject.CreateReusable("{id,name,sex,hobbys:[{v,n}]}");

            dto.SetValue("id", 1);
            dto.SetValue("name", "loui's");
            dto.SetValue("sex", 9);

            DTObject objHobbys = dto.CreateAndPush("hobbys");

            objHobbys.SetValue("v", "1");
            objHobbys.SetValue("n", "!@#09/");

            Assert.AreEqual(1, dto.GetValue <int>("id"));
            Assert.AreEqual("loui's", dto.GetValue <string>("name"));
            Assert.AreEqual(9, dto.GetValue <int>("sex"));
            //Assert.AreEqual("{\"id\",\"name\",\"sex\",\"hobbys\":[{\"v\",\"n\"}]}", dto.GetCode(false));
            Assert.AreEqual("{\"hobbys\":[{\"n\":\"!@#09/\",\"v\":\"1\"}],\"id\":1,\"name\":\"loui's\",\"sex\":9}", dto.GetCode(true));
        }