/// <summary> /// 解析操作 /// </summary> /// <param name="element"></param> /// <param name="bundle"></param> /// <returns></returns> protected override void OnResolver(XElement element, IBundle bundle) { // 首先获取当前页签的唯一标示 string id = element.AttibuteStringValue("id"); if (string.IsNullOrEmpty(id)) { return; } // 获取上级容器的唯一标示 string containerId = element.Parent.AttibuteStringValue("id"); // 检查缓存中是否存在 if (ribbonAdmin.Contains <T>(id)) { return; } // 创建指定类型的对象 T xRibbonElement = Activator.CreateInstance <T>(); bool success = xRibbonElement.InitProperties(element, bundle); if (!success) { return; } // 将当前元素的容器 CompositeRibbonElement xRibbonContainer = ribbonAdmin.Find <CompositeRibbonElement>(containerId); xRibbonContainer.Append(xRibbonElement); // 添加到缓存 ribbonAdmin.CacheRibbonElement(id, xRibbonElement); }
/// <summary> /// 解析操作 /// </summary> /// <param name="element"></param> /// <param name="bundle"></param> /// <returns></returns> protected override void OnResolver(XElement element, IBundle bundle) { // 首先获取当前页签的唯一标示 string id = element.AttibuteStringValue("id"); if (string.IsNullOrEmpty(id)) { return; } // 获取上级页签的唯一标示 string ContainerId = element.Parent.AttibuteStringValue("id"); // 尝试从缓存中加载 XRibbonMenu xRibbonMenu = ribbonAdmin.Find <XRibbonMenu>(id); // 将当前菜单的容器对象 CompositeRibbonElement xRibbonContainer = ribbonAdmin.Find <CompositeRibbonElement>(ContainerId); if (xRibbonMenu != null) { if (xRibbonContainer != xRibbonMenu.Parent) { return; } } else { // 创建分组对象 xRibbonMenu = new XRibbonMenu(); bool success = xRibbonMenu.InitProperties(element, bundle); if (!success) { return; } // 将当前菜单添加到容器中 xRibbonContainer.Append(xRibbonMenu); // 添加到缓存 ribbonAdmin.CacheRibbonElement(id, xRibbonMenu); } // 获取所有的元素列表 IEnumerable <XElement> xChildElements = element.Elements(); if (xChildElements == null && xChildElements.Count() == 0) { return; } // 遍历所有元素 foreach (XElement xChildElement in xChildElements) { if (SupportNestedType(xChildElement.Name.LocalName)) { IRibbonResolver resolver = CreateResolver(xChildElement.Name.LocalName, ribbonAdmin); if (resolver != null) { resolver.Resolve(xChildElement, bundle); } } } }