示例#1
0
        public void CreateSocketMessageDTO()
        {
            DTObject dto  = DTObject.CreateReusable("{\"RCN\":\"ControlBigScreenCapability\",\"REN\":\"PlayEvent\",\"MT\":7,\"Ds\":[\"[::ffff:192.168.0.13]:59714\"]}");
            var      ds   = dto.GetList("Ds");
            var      code = dto.GetCode();

            Assert.AreEqual("[::ffff:192.168.0.13]:59714", ds[0].GetValue());
        }
        private static void FillItems(DTObject itemData, List <UIMenuItem> items)
        {
            var name         = itemData.GetValue <string>("name", string.Empty);
            var icon         = itemData.GetValue <string>("icon", string.Empty);
            var iconFontSize = itemData.GetValue <string>("iconFontSize", string.Empty);
            var tags         = string.Join(",", itemData.GetList("tags").ToArray <string>());
            var code         = itemData.GetValue <string>("code", string.Empty);

            UIMenuItem item   = new UIMenuItem(name, icon, iconFontSize, tags, code);
            var        childs = itemData.GetList("childs", false);

            if (childs != null)
            {
                item.AddChilds(MapChildItems(childs));
            }

            items.Add(item);
        }
示例#3
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"));
        }
示例#4
0
        public override void Read(DTObject data)
        {
            var values = data.GetList(this.MemberName);

            foreach (var value in values)
            {
                var itemData = AddItem();
                if (itemData != null)
                {
                    value.Save(itemData);
                }
            }
        }
示例#5
0
        private string GetOptionsHtml(DTObject item)
        {
            var           items = item.GetList("options");
            StringBuilder html  = new StringBuilder();

            html.AppendLine("<items>");
            foreach (var option in items)
            {
                html.AppendFormat("<item value=\"{0}\">{0}</item>", option.GetValue <string>());
                html.AppendLine();
            }
            html.AppendLine("</items>");
            return(html.ToString());
        }
        private static IEnumerable <UIMenuItem> MapMenuItems(DTObject data)
        {
            List <UIMenuItem> items = new List <UIMenuItem>();

            if (data.GetValue <int>("dataCount") == 0)
            {
                return(items);
            }

            foreach (var itemData in data.GetList("rows"))
            {
                FillItems(itemData, items);
            }
            return(items);
        }
        private string[] GetContents(DTObject obj)
        {
            var contents = obj.GetList("contents");

            if (contents == null || contents.Count == 0)
            {
                return(Array.Empty <string>());
            }

            var list = new List <string>();

            foreach (DTObject content in contents)
            {
                list.Add(content.GetValue <string>());
            }
            return(list.ToArray());
        }
        private string[] GetTags(DTObject obj)
        {
            var tagList = obj.GetList("tags", false);

            if (tagList == null || tagList.Count == 0)
            {
                return(Array.Empty <string>());
            }

            var list = new List <string>();

            foreach (DTObject tag in tagList)
            {
                list.Add(tag.GetValue <string>());
            }

            return(list.ToArray());
        }
示例#9
0
        private string GetInputsHtml(DTObject config)
        {
            var           items = config.GetList("items");
            StringBuilder html  = new StringBuilder();

            html.AppendLine("<ContentControl xmlns=\"http://schemas.codeart.cn/web/xaml\" xmlns:m=\"http://schemas.codeart.cn/web/xaml/metronic\" xmlns:ms=\"http://schemas.codeart.cn/web/xaml/metronic/sealed\">");
            foreach (var item in items)
            {
                html.Append("<Column xs=\"12\" md=\"12\" class=\"col-trim dynamicItem\">");
                html.Append(GenerateHtml(item));
                html.AppendLine("</Column>");
            }
            html.Append("</ContentControl>");

            ContentControl content = XamlReader.ReadComponent(html.ToString()) as ContentControl;
            var            brush   = new PageBrush();

            content.Render(brush);
            var code = brush.GetCode();

            return(code);
        }
示例#10
0
        /// <summary>
        /// 根据登录人拥有的角色过滤菜单项
        /// </summary>
        /// <param name="rawMenu"></param>
        /// <param name="principalRoles"></param>
        /// <returns></returns>
        private static DTObject FilterMenu(DTObject rawMenu, Principal.Role[] principalRoles)
        {
            var menuRoles = rawMenu.GetList("roles", false);

            if (menuRoles != null)
            {
                var roleCodes = menuRoles.ToArray <string>();
                var result    = principalRoles.FirstOrDefault((role) =>
                {
                    return(roleCodes.Contains(role.MarkedCode, StringComparer.OrdinalIgnoreCase));
                });
                if (result == null)
                {
                    return(null);                //当前登录人没有菜单需要的角色,不能显示
                }
            }

            DTObject menu = DTObject.CreateReusable();

            foreach (var member in _outputMembers)
            {
                if (rawMenu.Exist(member))
                {
                    menu[member] = rawMenu[member];
                }
            }

            rawMenu.Each("childs", (child) =>
            {
                var target = FilterMenu(child, principalRoles);
                if (target != null)
                {
                    menu.Push("childs", target);
                }
            });

            return(menu);
        }
示例#11
0
        public static MockContract Create(DTObject dto, IContractPackage package)
        {
            var id          = dto.GetValue <string>("id", string.Empty);
            var description = dto.GetValue <string>("description", string.Empty);

            //request
            var requestDTO = dto.GetObject("request", DTObject.Empty);
            var request    = ServiceRequest.Create(requestDTO);

            //response
            var responseDTO = dto.GetObject("response", DTObject.Empty);
            var response    = ServiceResponse.Create(responseDTO);

            var events = dto.GetList("events", false) ?? DTObjects.Empty;
            List <IContractEvent> ces = new List <IContractEvent>(events.Count);

            foreach (var e in events)
            {
                ces.Add(ContractEventFactory.CreateCE(e));
            }

            return(new MockContract(id, description, request, response, ces.ToArray(), package));
        }