/// <summary> /// 给设计节点添加签出信息,如果已签出的模型节点则用本地存储替换原模型 /// </summary> internal void BindCheckoutInfo(DesignNode node, bool isNewNode) { //if (node.NodeType == DesignNodeType.FolderNode || !node.AllowCheckout) // throw new ArgumentException("不允许绑定签出信息: " + node.NodeType.ToString()); //先判断是否新增的 if (isNewNode) { node.CheckoutInfo = new CheckoutInfo(node.NodeType, node.CheckoutInfoTargetID, node.Version, DesignHub.Session.Name, DesignHub.Session.LeafOrgUnitID); return; } //非新增的比对服务端的签出列表 string key = CheckoutInfo.MakeKey(node.NodeType, node.CheckoutInfoTargetID); if (_checkouts.TryGetValue(key, out CheckoutInfo checkout)) { node.CheckoutInfo = checkout; if (node.IsCheckoutByMe) //如果是被当前用户签出的模型 { if (node is ModelNode modelNode) { //从本地缓存加载 var stagedModel = Staged.FindModel(modelNode.Model.Id); if (stagedModel != null) { modelNode.Model = stagedModel; } } } } }
/// <summary> /// 根据当前选择的节点查找新建文件夹节点的上级节点 /// </summary> public DesignNode FindNewFolderParentNode(DesignNode selected, out uint appID, out ModelType modelType) { appID = 0; modelType = ModelType.Application; if (selected == null) { return(null); } if (selected is ModelRootNode rootNode) { appID = rootNode.AppID; modelType = rootNode.TargetType; return(selected); } if (selected.NodeType == DesignNodeType.FolderNode) { ModelFolder folder = ((FolderNode)selected).Folder; appID = folder.AppId; modelType = folder.TargetModelType; return(selected); } return(null); }
public int Add(DesignNode item) { item.Parent = owner; //特定owner找到插入点 if (owner != null && ( owner.NodeType == DesignNodeType.ModelRootNode || owner.NodeType == DesignNodeType.FolderNode)) { var index = -1; for (var i = 0; i < nodes.Count; i++) { if (item.CompareTo(nodes[i]) < 0) { index = i; break; } } if (index != -1) { nodes.Insert(index, item); return(index); } nodes.Add(item); return(nodes.Count - 1); } nodes.Add(item); return(nodes.Count - 1); }
private static async Task DropModelNodeInside(ModelNode sourceNode, DesignNode targetNode) { //注意:目标节点可能是模型根目录 if (targetNode.NodeType == DesignNodeType.ModelRootNode) { var rootNode = (ModelRootNode)targetNode; if (rootNode.AppID != sourceNode.Model.AppId) { throw new InvalidOperationException("无法拖动模型节点至不同的Application内"); } sourceNode.Parent.Nodes.Remove(sourceNode); targetNode.Nodes.Add(sourceNode); sourceNode.Model.FolderId = null; await StagedService.SaveModelAsync(sourceNode.Model); //直接保存 } else if (targetNode.NodeType == DesignNodeType.FolderNode) { var targetFolder = ((FolderNode)targetNode).Folder; var rootFolder = targetFolder.GetRoot(); if (rootFolder.AppId != sourceNode.Model.AppId) { throw new InvalidOperationException("无法拖动模型节点至不同的Application内"); } sourceNode.Parent.Nodes.Remove(sourceNode); targetNode.Nodes.Add(sourceNode); sourceNode.Model.FolderId = targetFolder.Id; await StagedService.SaveModelAsync(sourceNode.Model); //直接保存 } else { throw new NotSupportedException(); } }
public async Task <object> Handle(DesignHub hub, InvokeArgs args) { int selectedNodeType = args.GetInt32(); string selectedNodeId = args.GetString(); var deleteNode = hub.DesignTree.FindNode((DesignNodeType)selectedNodeType, selectedNodeId); if (deleteNode == null) { throw new Exception("Delete target not exists."); } if (!(deleteNode is ModelNode || deleteNode is ApplicationNode || deleteNode.NodeType == DesignNodeType.FolderNode && deleteNode.Nodes.Count == 0)) { throw new Exception("Can not delete it."); } DesignNode rootNode = null; if (deleteNode is ModelNode modelNode) { rootNode = await DeleteModelNode(hub, modelNode); } else if (deleteNode is ApplicationNode appNode) { await DeleteApplicationNode(hub, appNode); } else { throw ExceptionHelper.NotImplemented(); //rootNode = DeleteFolderNode(hub, deleteNode); } //注意:返回rootNode.ID用于前端重新刷新模型根节点 return(rootNode == null ? string.Empty : rootNode.ID); }
internal int CompareTo(DesignNode other) { if (NodeType == other.NodeType) { return(string.Compare(Text, other.Text, StringComparison.Ordinal)); } return(((int)NodeType).CompareTo((int)other.NodeType)); }
public void Remove(DesignNode item) { var index = nodes.IndexOf(item); if (index >= 0) { item.Parent = null; nodes.RemoveAt(index); } }
/// <summary> /// 根据当前选择的节点查询新建模型的上级节点 /// </summary> public DesignNode FindNewModelParentNode(DesignNode selected, out uint appID, ModelType newModelType) { appID = 0; if (selected == null) { return(null); } DesignNode target = null; FindNewModelParentNodeInternal(selected, ref target, ref appID, newModelType); return(target); }
private static void FindNewModelParentNodeInternal(DesignNode node, ref DesignNode target, ref uint appID, ModelType newModelType) { if (node == null) { return; } switch (node.NodeType) { case DesignNodeType.FolderNode: if (target == null) { target = node; } break; case DesignNodeType.ModelRootNode: ModelRootNode modelRootNode = (ModelRootNode)node; if (newModelType == modelRootNode.TargetType) { if (target == null) { target = node; } appID = modelRootNode.AppID; return; } break; case DesignNodeType.ApplicationNode: target = ((ApplicationNode)node).FindModelRootNode(newModelType); appID = ((ApplicationNode)node).Model.Id; return; } FindNewModelParentNodeInternal(node.Parent, ref target, ref appID, newModelType); }
/// <summary> /// 从上至下查找指定设计节点下的最后一个文件夹的索引号 /// </summary> public int FindLastFolderIndex(DesignNode node) { if (node.Nodes.Count == 0 || ((DesignNode)node.Nodes[0]).NodeType != DesignNodeType.FolderNode) { return(-1); } int r = -1; for (int i = 0; i < node.Nodes.Count; i++) { if (((DesignNode)node.Nodes[i]).NodeType == DesignNodeType.FolderNode) { r = i; } else { return(r); } } return(r); }
public NodeCollection(DesignNode owner) { this.owner = owner; nodes = new List <DesignNode>(); }
private static DesignNode GetRootNode(DesignNode current) { return(current.Parent == null ? current : GetRootNode(current.Parent)); }