コード例 #1
0
 public TradeViewModel(TradeModel model)
 {
     Model = model;
     Children = new ObservableCollection<TradeViewModel>();
 }
コード例 #2
0
ファイル: TradeMenuManager.cs プロジェクト: OceanYan/Platform
        /// <summary>
        /// xml解析成TradeModel集合
        /// </summary>
        /// <param name="parentElement"></param>
        /// <returns></returns>
        private void GetModel(XElement parentElement, TradeModel parent)
        {
            var children = parentElement.Elements();

            foreach (var ele in children)
            {
                string guid = string.Empty;
                var    id   = ele.Attribute("id");
                if (id == null)
                {
                    guid = Guid.NewGuid().ToString("N");
                }
                else
                {
                    guid = id.Value.Trim();
                }
                //加载基础信息
                TradeModel model = new TradeModel()
                {
                    ID        = guid,
                    IsVisible = GetAttribute(ele, "isvisible") == "1",
                    Parent    = parent,
                    Name      = GetAttribute(ele, "name"),
                    Desc      = GetAttribute(ele, "desc")
                };
                //考虑isvisible属性,采用true/false模式设定
                bool isVisible;
                if (bool.TryParse(GetAttribute(ele, "isvisible"), out isVisible))
                {
                    model.IsVisible = isVisible;
                }
                switch (ele.Name.LocalName)
                {
                case "category":
                    //获取子项,并填充父元素
                    GetModel(ele, model);
                    break;

                case "trade":
                    model.Code   = GetAttribute(ele, "code");
                    model.Action = GetAttribute(ele, "action");
                    foreach (var meta in ele.Elements())
                    {
                        model.Metadata.Add(
                            GetAttribute(meta, "key"),
                            GetAttribute(meta, "value")
                            );
                    }
                    //检测是否存在重复Code节点
                    if (TradeModelList.Exists(x => x.Code == model.Code))
                    {
                        throw new ArgumentException(string.Format("菜单解析:存在重复Code的交易节点=[{0}]{1}", model.Code, model.Name));
                    }
                    break;

                default:
                    break;
                }
                TradeModelList.Add(model);
            }
        }