public async Task <object> Handle(DesignHub hub, InvokeArgs args) { // 获取接收到的参数 int selectedNodeType = args.GetInt32(); string selectedNodeId = args.GetString(); string name = args.GetString(); // 验证类名称的合法性 if (string.IsNullOrEmpty(name) || !CodeHelper.IsValidIdentifier(name)) { throw new Exception("Report name invalid"); } // 获取选择的节点 var selectedNode = hub.DesignTree.FindNode((DesignNodeType)selectedNodeType, selectedNodeId); if (selectedNode == null) { throw new Exception("Can't find selected node"); } var parentNode = hub.DesignTree.FindNewModelParentNode(selectedNode, out uint appId, ModelType.Report); if (parentNode == null) { throw new Exception("Can't find parent node"); } //判断名称是否已存在 if (hub.DesignTree.FindModelNodeByName(appId, ModelType.Report, name) != null) { throw new Exception("Report name has exists"); } //判断当前模型根节点有没有签出 var rootNode = hub.DesignTree.FindModelRootNode(appId, ModelType.Report); bool rootNodeHasCheckout = rootNode.IsCheckoutByMe; if (!await rootNode.Checkout()) { throw new Exception($"Can't checkout: {rootNode.FullName}"); } ////注意:需要重新引用上级文件夹节点,因自动签出上级节点可能已重新加载(签出模型根不再重新加载) //if (!rootNodeHasCheckout && parentNode.NodeType == DesignNodeType.FolderNode) //{ // parentNode = rootNode.FindFolderNode(((FolderNode)parentNode).Folder.ID); // if (parentNode == null) // throw new Exception("上级节点已不存在,请刷新重试"); //} //生成模型标识号并新建模型及节点 var modelId = await Store.ModelStore.GenModelIdAsync(appId, ModelType.Report, ModelLayer.DEV); //TODO:fix Layer var model = new ReportModel(modelId, name); var node = new ModelNode(model, hub); //添加至设计树 var insertIndex = parentNode.Nodes.Add(node); //设置文件夹 if (parentNode.NodeType == DesignNodeType.FolderNode) { model.FolderId = ((FolderNode)parentNode).Folder.Id; } // 添加至根节点索引内 rootNode.AddModelIndex(node); //设为签出状态 node.CheckoutInfo = new CheckoutInfo(node.NodeType, node.CheckoutInfoTargetID, model.Version, hub.Session.Name, hub.Session.LeafOrgUnitID); //保存至Staged var emptyReportDfn = Resources.LoadStringResource("Resources.EmptyReport.json"); await node.SaveAsync(new object[] { emptyReportDfn }); return(new NewNodeResult { ParentNodeType = (int)parentNode.NodeType, ParentNodeID = parentNode.ID, NewNode = node, RootNodeID = rootNodeHasCheckout ? null : rootNode.ID, InsertIndex = insertIndex }); }
public async Task <object> Handle(DesignHub hub, InvokeArgs args) { //读取参数 int selectedNodeType = args.GetInt32(); string selectedNodeId = args.GetString(); string newname = args.GetString(); //先判断名称有效性 if (string.IsNullOrEmpty(newname)) { throw new Exception("名称不能为空"); } if (!CodeHelper.IsValidIdentifier(newname)) { throw new Exception("名称包含无效字符"); } //获取选择的节点 var selectedNode = hub.DesignTree.FindNode((DesignNodeType)selectedNodeType, selectedNodeId); if (selectedNode == null) { throw new Exception("无法找到当前节点"); } //根据选择的节点获取合适的插入位置 var parentNode = hub.DesignTree.FindNewModelParentNode(selectedNode, out uint appId, ModelType.Permission); if (parentNode == null) { throw new Exception("无法找到当前节点的上级节点"); } //判断名称是否已存在 if (hub.DesignTree.FindModelNodeByName(appId, ModelType.Permission, newname) != null) { throw new Exception("Name has exists"); } //判断当前模型根节点有没有签出 var rootNode = hub.DesignTree.FindModelRootNode(appId, ModelType.Permission); bool rootNodeHasCheckout = rootNode.IsCheckoutByMe; if (!await rootNode.Checkout()) { throw new Exception($"Can't checkout: {rootNode.FullName}"); } ////注意:需要重新引用上级文件夹节点,因自动签出上级节点可能已重新加载 //if (!rootNodeHasCheckout && parentNode.NodeType == DesignNodeType.FolderNode) //{ // parentNode = rootNode.FindFolderNode(((FolderNode)parentNode).Folder.ID); // if (parentNode == null) // throw new Exception("上级节点已不存在,请刷新重试"); //} //生成模型标识号并新建模型及节点 var modelId = await Store.ModelStore.GenModelIdAsync(appId, ModelType.Permission, ModelLayer.DEV); //TODO:fix Layer var model = new PermissionModel(modelId, newname); var node = new ModelNode(model, hub); //添加至设计树 var insertIndex = parentNode.Nodes.Add(node); //设置文件夹 if (parentNode.NodeType == DesignNodeType.FolderNode) { model.FolderId = ((FolderNode)parentNode).Folder.Id; } //添加至根节点索引内 rootNode.AddModelIndex(node); //设为签出状态 node.CheckoutInfo = new CheckoutInfo(node.NodeType, node.CheckoutInfoTargetID, model.Version, hub.Session.Name, hub.Session.LeafOrgUnitID); //保存至本地 await node.SaveAsync(null); //新建RoslynDocument await hub.TypeSystem.CreateModelDocumentAsync(node); return(new NewNodeResult() { ParentNodeType = (int)parentNode.NodeType, ParentNodeID = parentNode.ID, NewNode = node, RootNodeID = rootNodeHasCheckout ? null : rootNode.ID, InsertIndex = insertIndex }); }
private static async Task <DesignNode> DeleteModelNode(DesignHub hub, ModelNode node) { // 查找ModelRootNode var rootNode = hub.DesignTree.FindModelRootNode(node.Model.AppId, node.Model.ModelType); bool rootNodeHasCheckout = rootNode.IsCheckoutByMe; // 尝试签出模型节点及根节点 bool nodeCheckout = await node.Checkout(); bool rootCheckout = await rootNode.Checkout(); if (!nodeCheckout || !rootCheckout) { throw new Exception("Can't checkout nodes."); } // 注意:如果自动签出了模型根节点,当前选择的节点需要重新指向,因为Node.Checkout()时已重新加载 if (!rootNodeHasCheckout) { node = rootNode.FindModelNode(node.Model.Id); } if (node == null) //可能已不存在 { throw new Exception("Delete target not exists, please refresh."); } // 判断当前节点所属层是否是系统层 if (node.Model.ModleLayer == ModelLayer.SYS) { throw new Exception("Can't delete system model."); } var model = node.Model; // 查找引用项 var usages = await RefactoringService.FindModelReferencesAsync(hub, model.ModelType, node.AppNode.Model.Name, model.Name); if (usages != null && usages.Count > 0) { //注意排除自身引用 usages = usages.Where(u => !(u.ModelNode.Model.Id == model.Id)).ToArray(); if (usages.Count > 0) { #if DEBUG foreach (var item in usages) { Log.Warn(item.ToString()); } #endif throw new Exception("Has usages, Can't delete it."); } } // 判断当前模型是否已持久化到数据库中 if (model.PersistentState == PersistentState.Detached) { await StagedService.DeleteModelAsync(model.Id); } else { model.MarkDeleted(); await node.SaveAsync(null); } // 移除对应节点 rootNode.RemoveModel(node); // 删除Roslyn相关 RemoveRoslynFromModelNode(hub, node); return(rootNodeHasCheckout ? null : rootNode); }
public async Task <object> Handle(DesignHub hub, InvokeArgs args) { // 获取接收到的参数 int selectedNodeType = args.GetInt32(); var selectedNodeId = args.GetString(); var name = args.GetString(); var localizedName = args.GetString(); var storeName = args.GetString(); var orderByDesc = args.GetBoolean(); // 验证类名称的合法性 if (string.IsNullOrEmpty(name)) { throw new Exception("Entity name empty"); } if (!CodeHelper.IsValidIdentifier(name)) { throw new Exception("Entity name invalid"); } //获取选择的节点 var selectedNode = hub.DesignTree.FindNode((DesignNodeType)selectedNodeType, selectedNodeId); if (selectedNode == null) { throw new Exception("Can't find selected node"); } //根据选择的节点获取合适的插入位置 var parentNode = hub.DesignTree.FindNewModelParentNode(selectedNode, out uint appId, ModelType.Entity); if (parentNode == null) { throw new Exception("Can't find parent node"); } //判断名称是否已存在 if (hub.DesignTree.FindModelNodeByName(appId, ModelType.Entity, name) != null) { throw new Exception("Entity name has exists"); } //判断当前模型根节点有没有签出 var rootNode = hub.DesignTree.FindModelRootNode(appId, ModelType.Entity); bool rootNodeHasCheckout = rootNode.IsCheckoutByMe; if (!await rootNode.Checkout()) { throw new Exception($"Can't checkout: {rootNode.FullName}"); } ////注意:需要重新引用上级文件夹节点,因自动签出上级节点可能已重新加载 //if (!rootNodeHasCheckout && parentNode.NodeType == DesignNodeType.FolderNode) //{ // parentNode = rootNode.FindFolderNode(((FolderNode)parentNode).Folder.ID); // if (parentNode == null) // throw new Exception("上级节点已不存在,请刷新重试"); //} //生成模型标识号并新建模型及节点 var modelId = await Store.ModelStore.GenModelIdAsync(appId, ModelType.Entity, ModelLayer.DEV); //TODO:fix Layer //根据映射的存储创建相应的实体模型 EntityModel entityModel; if (string.IsNullOrEmpty(storeName)) { throw new NotImplementedException("Create DTO is not implemented."); } #if FUTURE else if (storeName == "Default") { entityModel = new EntityModel(modelId, name, EntityStoreType.StoreWithMvcc, orderByDesc); //TODO: fix without mvcc } #endif else { var storeNode = hub.DesignTree.FindDataStoreNodeByName(storeName); if (storeNode == null) { throw new Exception($"Can't find store: {storeName}"); } IEntityStoreOptions storeOptions; if (storeNode.Model.Kind == DataStoreKind.Sql) { storeOptions = new SqlStoreOptions(storeNode.Model.Id); } else { storeOptions = new CqlStoreOptions(storeNode.Model.Id); } entityModel = new EntityModel(modelId, name, storeOptions); } //if (!string.IsNullOrWhiteSpace(localizedName)) //entityModel.LocalizedName.Value = localizedName; //添加至设计树 var node = new ModelNode(entityModel, hub); var insertIndex = parentNode.Nodes.Add(node); // 设置文件夹 if (parentNode.NodeType == DesignNodeType.FolderNode) { entityModel.FolderId = ((FolderNode)parentNode).Folder.Id; } // 添加至根节点索引内 rootNode.AddModelIndex(node); // 设为签出状态 node.CheckoutInfo = new CheckoutInfo(node.NodeType, node.CheckoutInfoTargetID, entityModel.Version, hub.Session.Name, hub.Session.LeafOrgUnitID); //保存至Staged await node.SaveAsync(null); // 新建RoslynDocument await hub.TypeSystem.CreateModelDocumentAsync(node); return(new NewNodeResult { ParentNodeType = (int)parentNode.NodeType, ParentNodeID = parentNode.ID, NewNode = node, RootNodeID = rootNodeHasCheckout ? null : rootNode.ID, InsertIndex = insertIndex }); }
public async Task <object> Handle(DesignHub hub, InvokeArgs args) { // 获取接收到的参数 int selectedNodeType = args.GetInt32(); string selectedNodeId = args.GetString(); string name = args.GetString(); // 验证类名称的合法性 if (string.IsNullOrEmpty(name) || !CodeHelper.IsValidIdentifier(name)) { throw new Exception("Service name invalid"); } // 获取选择的节点 var selectedNode = hub.DesignTree.FindNode((DesignNodeType)selectedNodeType, selectedNodeId); if (selectedNode == null) { throw new Exception("Can't find selected node"); } var parentNode = hub.DesignTree.FindNewModelParentNode(selectedNode, out uint appId, ModelType.Service); if (parentNode == null) { throw new Exception("Can't find parent node"); } //判断名称是否已存在 if (hub.DesignTree.FindModelNodeByName(appId, ModelType.Service, name) != null) { throw new Exception("Service name has exists"); } //判断当前模型根节点有没有签出 var rootNode = hub.DesignTree.FindModelRootNode(appId, ModelType.Service); bool rootNodeHasCheckout = rootNode.IsCheckoutByMe; if (!await rootNode.Checkout()) { throw new Exception($"Can't checkout: {rootNode.FullName}"); } ////注意:需要重新引用上级文件夹节点,因自动签出上级节点可能已重新加载(签出模型根不再重新加载) //if (!rootNodeHasCheckout && parentNode.NodeType == DesignNodeType.FolderNode) //{ // parentNode = rootNode.FindFolderNode(((FolderNode)parentNode).Folder.ID); // if (parentNode == null) // throw new Exception("上级节点已不存在,请刷新重试"); //} //生成模型标识号并新建模型及节点 var modelId = await Store.ModelStore.GenModelIdAsync(appId, ModelType.Service, ModelLayer.DEV); //TODO:fix Layer var model = new ServiceModel(modelId, name); var node = new ModelNode(model, hub); //添加至设计树 var insertIndex = parentNode.Nodes.Add(node); //设置文件夹 if (parentNode.NodeType == DesignNodeType.FolderNode) { model.FolderId = ((FolderNode)parentNode).Folder.Id; } // 添加至根节点索引内 rootNode.AddModelIndex(node); //设为签出状态 node.CheckoutInfo = new CheckoutInfo(node.NodeType, node.CheckoutInfoTargetID, model.Version, hub.Session.Name, hub.Session.LeafOrgUnitID); //保存至Staged var appName = node.AppNode.Model.Name; var initServiceCode = $"using System;\nusing System.Threading.Tasks;\n\nnamespace {appName}.ServiceLogic\n{{\n\tpublic class {model.Name}\n\t{{\n\t}}\n}}"; await node.SaveAsync(new object[] { initServiceCode }); // 新建Roslyn相关 await hub.TypeSystem.CreateModelDocumentAsync(node, initServiceCode); return(new NewNodeResult { ParentNodeType = (int)parentNode.NodeType, ParentNodeID = parentNode.ID, NewNode = node, RootNodeID = rootNodeHasCheckout ? null : rootNode.ID, InsertIndex = insertIndex }); }