/// <summary> /// 删除扩展模型。 /// </summary> /// <param name="extension">扩展对象。</param> private void RemoveNavigationByExtension(Extension extension) { NavigationNodeList.RemoveAll(node => node.Bundle.Equals(extension.Owner)); NavigationNodeList.ForEach(node => { RemoveNode(node, extension.Owner); }); }
static XpressModulePluginProvider() { NavigationNodeList.Add(new NavigationNodeItem("Cost", "Cost Inputs")); NavigationNodeList.Add(new NavigationNodeItem("Price", "Aadvanced Pricing")); InitializeCostModulePluginItems(); InitializePriceModulePluginItems(); }
private void InitializeExtensions() // 初始化扩展信息。 { NavigationNodeList.Clear(); PendingAppendedNodes.Clear(); // 获取该扩展点的所有扩展信息。 var extensions = _context.GetExtensions(NavigationExtensionPoint); // 将扩展XML信息转换成扩展模型。 extensions.ForEach(extension => AddNavigationByExtension(extension)); HandlePendingAppendedNodes(); }
private static NavigationNode GetNavigationNode(NavigationNodeList Nodes, INode Node) { for (int i = 0; i < Nodes.Count; ++i) { if (Nodes[i].Node == Node) { return(Nodes[i]); } } return(null); }
private void HandlePendingAppendedNodes() { if (PendingAppendedNodes.Count == 0) { return; } var nodesStack = new List <NavigationNode>(); NavigationNodeList.ForEach(navNode => nodesStack.Add(navNode)); PendingAppendedNodes.ToList().ForEach(navNode => nodesStack.Add(navNode)); List <NavigationNode> currentStack; NavigationNode current; foreach (var node in PendingAppendedNodes.ToArray()) { currentStack = new List <NavigationNode>(nodesStack.ToArray()); while (currentStack.Count > 0) { current = currentStack[0]; currentStack.RemoveAt(0); if (node.ParentId.Equals(current.Id)) { current.Children.Add(node); node.Parent = current; PendingAppendedNodes.Remove(node); NavigationNodeList.Remove(node); continue; } foreach (var child in current.Children) { currentStack.Add(child); } } } foreach (var node in PendingAppendedNodes) { using (var locker = NavigationNodeList.Lock()) { if (locker.Contains(node)) { continue; } } NavigationNodeList.Add(node); } }
private static bool Contains(NavigationNodeList Nodes, INode Node) { if (Nodes.Count == 0) { return(false); } NavigationNode node = Nodes[0]; for (int i = 1; i < Nodes.Count; ++i) { if (Nodes[i].Node == Node) { return(true); } } return(false); }
private static NavigationNode GetLowestCost(NavigationNodeList Nodes) { if (Nodes.Count == 0) { return(null); } NavigationNode node = Nodes[0]; for (int i = 1; i < Nodes.Count; ++i) { if (Nodes[i].TotalCost < node.TotalCost) { node = Nodes[i]; } } return(node); }
private static Vector3[] CalculatePath(IMapData Map, INode StartNode, INode GoalNode) { //1. Add the starting node to the open list. //2. Repeat the following steps: // a. Look for the node which has the lowest f on the open list. Refer to this node as the current node. // b. Switch it to the closed list. // c. For each reachable node from the current node // i. If it is on the closed list, ignore it. // ii. If it isn’t on the open list, add it to the open list. Make the current node the parent of this node. Record the f, g, and h value of this node. // iii. If it is on the open list already, check to see if this is a better path. If so, change its parent to the current node, and recalculate the f and g value. // d. Stop when // i. Add the target node to the closed list. // ii. Fail to find the target node, and the open list is empty. //3. Tracing backwards from the target node to the starting node. That is your path. if (Map == null) { return(null); } if (StartNode == null) { return(null); } if (GoalNode == null) { return(null); } if (StartNode == GoalNode) { return(null); } if (StartNode.State == NodeStates.Blocked || GoalNode.State == NodeStates.Blocked) { return(null); } NavigationNodeList openNodes = new NavigationNodeList(); NavigationNodeList closedNodes = new NavigationNodeList(); NavigationNode startNavNode = new NavigationNode(StartNode); openNodes.Add(startNavNode); NavigationNode currNode = null; bool goalFound = false; while (true) { if (openNodes.Count == 0) { break; } currNode = GetLowestCost(openNodes); closedNodes.Add(currNode); openNodes.Remove(currNode); if (currNode.Node == GoalNode) { goalFound = true; break; } INode[] adjNodes = Map.GetAdjucentNodes(currNode.Node, NodeStates.Walkable); for (int i = 0; i < adjNodes.Length; ++i) { INode adjNode = adjNodes[i]; if (adjNode.State == NodeStates.Blocked) { continue; } if (Contains(closedNodes, adjNode)) { continue; } NavigationNode adjNavNode = GetNavigationNode(openNodes, adjNode); if (adjNavNode == null) { adjNavNode = new NavigationNode(adjNode); openNodes.Add(adjNavNode); } else if (adjNavNode.GetTotalCost(GoalNode) >= currNode.ExactCost) { continue; } adjNavNode.SetParent(currNode); adjNavNode.CalculateHeuristicCost(GoalNode); adjNavNode.CalculateTotalCost(); } } if (!goalFound) { return(null); } return(Helper.GetPositions(Helper.GetOptimizedNodes(Map, (GetFullPositions(currNode))))); }
/// <summary> /// 将Xml节点转换成导航节点对象。 /// </summary> /// <param name="nav">所属Navigation。</param> /// <param name="node">Xml节点。</param> /// <param name="Parent">父导航节点。</param> /// <param name="children">子导航节点列表。</param> private void ConvertToNode(NavigationNode parent, XmlNode node, IBundle bundle) { // 获取Id、Name、Value、Order、Permisson、Icon和Tooltip属性。 string id = GetAttribute(node, "Id"); string name = GetAttribute(node, "Name"); if (string.IsNullOrEmpty(name)) { FileLogUtility.Warn("The Name attribute can not be empty for UIShell.NavigationService extension."); return; } string value = GetAttribute(node, "Value"); string order = GetAttribute(node, "Order"); float orderFloat = 0; float.TryParse(order, out orderFloat); string permission = GetAttribute(node, "Permission"); string icon = GetAttribute(node, "Icon"); string toolTip = GetAttribute(node, "Tooltip"); string parentId = GetAttribute(node, "ParentId"); // 创建导航节点。 var navNode = new NavigationNode { ParentId = string.IsNullOrEmpty(parentId) ? Guid.NewGuid().ToString() : parentId, Id = string.IsNullOrEmpty(id) ? Guid.NewGuid().ToString() : id, Name = name, Order = orderFloat, Value = value, Permission = permission, Icon = icon, ToolTip = toolTip, Bundle = bundle }; // 设置父节点,并添加到子节点列表。 if (!string.IsNullOrEmpty(parentId)) { PendingAppendedNodes.Add(navNode); } else if (string.IsNullOrEmpty(parentId)) { if (parent != null) { navNode.Parent = parent; parent.Children.Add(navNode); } else { navNode.Parent = null; navNode.ParentId = Guid.NewGuid().ToString(); NavigationNodeList.Add(navNode); } } // 将XML节点其它的属性保存到Attributes字典。 foreach (XmlAttribute attr in node.Attributes) { if (attr.Name.Equals("Id") || attr.Name.Equals("Name") || attr.Name.Equals("Value") || attr.Name.Equals("Order") || attr.Name.Equals("Permission") || attr.Name.Equals("Icon") || attr.Name.Equals("ToolTip")) { continue; } navNode.Attributes[attr.Name] = attr.Value; } // 遍历Xml子节点,并递归转换成导航节点。 foreach (XmlNode childnode in node.ChildNodes) { if (childnode is XmlComment) { continue; } ConvertToNode(navNode, childnode, bundle); } }