Esempio n. 1
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var modelID     = args.GetString();
            var methodName  = args.GetString();
            var methodArgs  = args.GetString();
            var breakpoints = args.GetString();

            //先编译服务模型,将编译结果保存至当前会话的调试目录内
            var debugFolder = Path.Combine(Runtime.RuntimeContext.Current.AppPath, "debug", hub.Session.SessionID.ToString());

            if (Directory.Exists(debugFolder))
            {
                Directory.Delete(debugFolder, true);
            }
            Directory.CreateDirectory(debugFolder);

            var serviceNode = hub.DesignTree.FindModelNode(ModelType.Service, ulong.Parse(modelID));
            await PublishService.CompileServiceAsync(hub, (ServiceModel)serviceNode.Model, debugFolder);

            //释放第三方组件库 TODO:暂简单实现
            var debugLibPath = Path.Combine(debugFolder, "lib");
            await Store.ModelStore.ExtractAppAssemblies(serviceNode.AppNode.Model.Name, debugLibPath);

            //启动调试进程
            var appName = serviceNode.AppNode.Model.Name;

            hub.DebugService.DebugSourcePath = $"{appName}.Services.{serviceNode.Model.Name}.cs";
            hub.DebugService.StartDebugger($"{appName}.{serviceNode.Model.Name}.{methodName}", methodArgs, breakpoints);

            return(null);
        }
Esempio n. 2
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            //TODO:先判断DataStoreRootNode有没有被当前用户签出

            // 获取接收到的参数
            var storeType     = (DataStoreKind)args.GetInt32();
            var storeProvider = args.GetString();
            var storeName     = args.GetString();

            // 验证类名称的合法性
            if (string.IsNullOrEmpty(storeName))
            {
                throw new Exception("DataStore name can not be null");
            }
            if (!CodeHelper.IsValidIdentifier(storeName) || storeName == "Default")
            {
                throw new Exception("DataStore name invalid");
            }
            // TODO: 验证名称是否已存在

            // 开始新建存储节点
            var model = new DataStoreModel(storeType, storeProvider, storeName);
            //添加节点至模型树并绑定签出信息
            var node = hub.DesignTree.StoreRootNode.AddModel(model, hub);

            // 保存至本地
            await node.SaveAsync();

            // 新建RoslynDocument
            hub.TypeSystem.CreateStoreDocument(node);

            return(node);
        }
Esempio n. 3
0
        public Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var modelID     = args.GetString();
            var routeEnable = args.GetBoolean();
            var routeParent = args.GetString();
            var routePath   = args.GetString();

            if (routeEnable && !string.IsNullOrEmpty(routeParent) && string.IsNullOrEmpty(routePath))
            {
                throw new InvalidOperationException("Assign RouteParent must set RoutePath");
            }
            //TODO:判断路径有效性,以及是否重复

            var modelNode = hub.DesignTree.FindModelNode(ModelType.View, ulong.Parse(modelID));

            if (modelNode == null)
            {
                throw new Exception($"Cannot find view model node: {modelID}");
            }

            var viewModel = (ViewModel)modelNode.Model;

            viewModel.Flag        = routeEnable == true ? ViewModelFlag.ListInRouter : ViewModelFlag.None;
            viewModel.RouteParent = routeParent;
            viewModel.RoutePath   = routePath;

            return(Task.FromResult <object>(true));
        }
Esempio n. 4
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            string fileName = args.GetString();
            string tempFile = args.GetString();
            string appName  = args.GetString();

            if (string.IsNullOrEmpty(appName))
            {
                throw new ArgumentException("必须指明App");
            }

            //找到对应的ApplicationNode
            var appNode = hub.DesignTree.FindApplicationNodeByName(appName);

            if (appNode == null)
            {
                throw new Exception("未能找到应用节点: " + appName);
            }

            //判断组件类型
            AssemblyPlatform platform = AssemblyPlatform.Common;
            var ext = Path.GetExtension(fileName);

            if (ext == "so")
            {
                platform = AssemblyPlatform.Linux;
            }
            else if (ext == "dylib")
            {
                platform = AssemblyPlatform.OSX;
            }
            else if (!IsDotNetAssembly(tempFile))
            {
                platform = AssemblyPlatform.Windows;
            }

            //压缩组件
            using var dllStream = new MemoryStream(1024);
            using var cs        = new BrotliStream(dllStream, CompressionMode.Compress, true);
            using var fs        = File.OpenRead(tempFile);
            await fs.CopyToAsync(cs);

            await cs.FlushAsync();

            var asmData = dllStream.ToArray();

            //保存组件
            var asmName = $"{appName}.{fileName}";
            await Store.ModelStore.UpsertAppAssemblyAsync(asmName, asmData, platform);

            //TODO:*****
            // 1. 通知所有DesignHub.TypeSystem更新MetadataReference缓存,并更新相关项目引用
            //TypeSystem.RemoveMetadataReference(fileName, appID);
            // 2. 如果相应的AppContainer已启动,通知其移除所有引用该第三方组件的服务实例缓存,使其自动重新加载
            // 3. 如果集群模式,通知集群其他节点做上述1,2操作

            return(platform == AssemblyPlatform.Common ? true : false); //返回true表示.net 组件可引用, false表示native不可直接引用
        }
Esempio n. 5
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var appName = args.GetString();
            var path    = args.GetString();

            var app = await RuntimeContext.Current.GetApplicationModelAsync(appName);

            return(await Store.BlobStore.ListAsync(app.StoreId, path));
        }
Esempio n. 6
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var refType = (ModelReferenceType)args.GetInt32();
            var modelID = args.GetString();
            var oldName = args.GetString();
            var newName = args.GetString();

            return(await RefactoringService.RenameAsync(hub, refType,
                                                        ulong.Parse(modelID), oldName, newName));
        }
Esempio n. 7
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            string modelId  = args.GetString();
            string itemName = args.GetString();
            int    value    = args.GetInt32();
            string comment  = args.GetString();

            var node = hub.DesignTree.FindModelNode(ModelType.Enum, ulong.Parse(modelId));

            if (node == null)
            {
                throw new Exception("Can't find enum model node");
            }
            var model = (EnumModel)node.Model;

            if (!node.IsCheckoutByMe)
            {
                throw new Exception("Node has not checkout");
            }
            if (!CodeHelper.IsValidIdentifier(itemName))
            {
                throw new Exception("Name is invalid");
            }
            if (itemName == model.Name)
            {
                throw new Exception("Name can not same as Enum name");
            }
            if (model.Items.FirstOrDefault(t => t.Name == itemName) != null)
            {
                throw new Exception("Name has exists");
            }
            if (model.Items.FirstOrDefault(t => t.Value == value) != null)
            {
                throw new Exception("Value has exists");
            }

            var item = new EnumModelItem(itemName, value);

            if (!string.IsNullOrEmpty(comment))
            {
                item.Comment = comment;
            }
            model.Items.Add(item);

            // 保存到本地
            await node.SaveAsync(null);

            // 更新RoslynDocument
            await hub.TypeSystem.UpdateModelDocumentAsync(node);

            return(item);
        }
Esempio n. 8
0
        //todo:修改实现,获取Changes集合
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            int    type        = args.GetInt32();
            string targetID    = args.GetString();
            int    startLine   = args.GetInt32() - 1; //注意:前端传过来的值需要-1
            int    startColumn = args.GetInt32() - 1;
            int    endLine     = args.GetInt32() - 1;
            int    endColumn   = args.GetInt32() - 1;
            string newText     = args.GetString();

            Document document;

            if (type == 1) //服务代码变更
            {
                var modelNode = hub.DesignTree.FindModelNode(ModelType.Service, ulong.Parse(targetID));
                if (modelNode == null)
                {
                    throw new Exception($"Cannot find ServiceModel: {targetID}");
                }

                document = hub.TypeSystem.Workspace.CurrentSolution.GetDocument(modelNode.RoslynDocumentId);
            }
            else if (type == 2) //表达式代码变更
            {
                throw ExceptionHelper.NotImplemented();
                //document = hub.ExpressionDesignService.GetExpressionDocument(targetID);
            }
            else
            {
                throw ExceptionHelper.NotImplemented();
            }

            if (document == null)
            {
                throw new Exception("Can not find opened document: " + targetID);
            }

            var sourceText = await document.GetTextAsync();

            var startOffset = sourceText.Lines.GetPosition(new LinePosition(startLine, startColumn));
            var endOffset   = sourceText.Lines.GetPosition(new LinePosition(endLine, endColumn));

            sourceText = sourceText.WithChanges(new[] {
                new TextChange(new TextSpan(startOffset, endOffset - startOffset), newText)
            });

            hub.TypeSystem.Workspace.OnDocumentChanged(document.Id, sourceText);
            return(null);
        }
Esempio n. 9
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var nodeId   = args.GetString();
            var settings = args.GetString();

            if (!(hub.DesignTree.FindNode(DesignNodeType.DataStoreNode, nodeId) is DataStoreNode node))
            {
                throw new Exception("Can't find node: " + nodeId);
            }

            node.Model.Settings = settings;
            await node.SaveAsync();

            return(null);
        }
Esempio n. 10
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var sourceNodeType = (DesignNodeType)args.GetInt32();
            var sourceNodeID   = args.GetString();
            var targetNodeType = (DesignNodeType)args.GetInt32();
            var targetNodeID   = args.GetString();
            var position       = args.GetString(); //inner or before or after

            var sourceNode = hub.DesignTree.FindNode(sourceNodeType, sourceNodeID);
            var targetNode = hub.DesignTree.FindNode(targetNodeType, targetNodeID);

            if (sourceNode == null || targetNode == null)
            {
                throw new Exception("处理拖动时无法找到相应的节点");
            }

            //TODO: 再次验证是否允许操作,前端已验证过
            //TODO:完整实现以下逻辑,暂只支持Inside
            if (position == "inner")
            {
                switch (sourceNodeType)
                {
                case DesignNodeType.FolderNode:
                    throw new NotImplementedException();

                case DesignNodeType.EntityModelNode:
                case DesignNodeType.ServiceModelNode:
                case DesignNodeType.ViewModelNode:
                case DesignNodeType.EnumModelNode:
                case DesignNodeType.EventModelNode:
                case DesignNodeType.PermissionModelNode:
                case DesignNodeType.WorkflowModelNode:
                case DesignNodeType.ReportModelNode:
                    await DropModelNodeInside((ModelNode)sourceNode, targetNode);

                    break;

                default:
                    throw new NotSupportedException();
                }
            }
            else
            {
                throw new NotImplementedException($"暂未实现 position={position}");
            }

            return(null);
        }
Esempio n. 11
0
        public Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var nodeType = (DesignNodeType)args.GetInt32();
            var modelID  = args.GetString();

            //Log.Debug($"nodeType={nodeType} modelId={modelID}");

            if (nodeType == DesignNodeType.ServiceModelNode)
            {
                var modelNode = hub.DesignTree.FindModelNode(ModelType.Service, ulong.Parse(modelID));
                if (modelNode != null) //可能已被删除了,即由删除节点引发的关闭设计器
                {
                    var fileName = $"{modelNode.AppNode.Model.Name}.Services.{modelNode.Model.Name}.cs";
                    var document = hub.TypeSystem.Workspace.GetOpenedDocumentByName(fileName);
                    if (document != null)
                    {
                        hub.TypeSystem.Workspace.CloseDocument(document.Id);
                    }
                }
            }
            else if (nodeType == DesignNodeType.WorkflowModelNode)
            {
                throw ExceptionHelper.NotImplemented();
                //var sr = modelID.Split('.');
                //var modelNode = hub.DesignTree.FindModelNode(ModelType.Workflow, sr[0], sr[1]);
                //hub.WorkflowDesignService.CloseWorkflowModel(modelNode);
            }
            return(Task.FromResult <object>(null));
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var modelID = args.GetString(); // eg: sys.CustomerListView
            var sr      = modelID.Split('.');
            var app     = hub.DesignTree.FindApplicationNodeByName(sr[0]);
            var node    = hub.DesignTree.FindModelNodeByName(app.Model.Id, ModelType.View, sr[1]);

            if (node == null)
            {
                throw new Exception("Cannot found view node: " + modelID);
            }

            var modelNode = node as ModelNode;

            if (modelNode == null)
            {
                throw new Exception("Cannot found view model: " + modelID);
            }

            string runtimeCode = null;

            if (modelNode.IsCheckoutByMe)
            {
                runtimeCode = await StagedService.LoadViewRuntimeCode(modelNode.Model.Id);
            }
            if (string.IsNullOrEmpty(runtimeCode))
            {
                runtimeCode = await Store.ModelStore.LoadViewAssemblyAsync(modelID);
            }

            return(runtimeCode);
        }
Esempio n. 14
0
        public Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            string modelId = args.GetString();

            ModelNode[] modelNodes;
            if (string.IsNullOrEmpty(modelId)) //空表示所有模型用于初次加载
            {
                modelNodes = hub.DesignTree.FindNodesByType(ModelType.Entity);
            }
            else //指定标识用于更新
            {
                ulong id   = ulong.Parse(modelId);
                var   node = hub.DesignTree.FindModelNode(ModelType.Entity, id);
                modelNodes = new ModelNode[] { node };
            }

            List <TypeScriptDeclare> list = new List <TypeScriptDeclare>();

            foreach (var node in modelNodes)
            {
                list.Add(new TypeScriptDeclare
                {
                    Name    = $"{node.AppNode.Model.Name}.Entities.{node.Model.Name}",
                    Declare = BuildDeclare(node, hub)
                });
            }

            return(Task.FromResult <object>(list));
        }
Esempio n. 15
0
        public Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            string fileName = args.GetString();
            int    fileLen  = args.GetInt32();
            string appName  = args.GetString();

            if (string.IsNullOrEmpty(appName))
            {
                throw new ArgumentException("Must asign App");
            }

            //TODO:考虑检测系统所有内置组件是否存在相同名称的
            Log.Debug($"验证上传的第三方组件: {fileName} {fileLen}");

            return(Task.FromResult <object>(null));
        }
Esempio n. 16
0
        public Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            int    type    = args.GetInt32();
            string modelId = args.GetString();

            if (type == 1)
            {
                var modelNode = hub.DesignTree.FindModelNode(ModelType.Service, ulong.Parse(modelId));
                if (modelNode == null)
                {
                    throw new Exception($"Cannot find ServiceModel: {modelId}");
                }

                var quickFixes = new List <QuickFix>();

                var document      = hub.TypeSystem.Workspace.CurrentSolution.GetDocument(modelNode.RoslynDocumentId);
                var semanticModel = document.GetSemanticModelAsync().Result;
                IEnumerable <Diagnostic> diagnostics = semanticModel.GetDiagnostics();

                return(Task.FromResult <object>(diagnostics.Select(MakeQuickFix).ToArray()));
            }
            else
            {
                throw ExceptionHelper.NotImplemented();
            }
        }
Esempio n. 17
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            // 获取接收到的参数
            string appName = args.GetString();
            //string localizedName = args.GetObject() as string;

            var node = hub.DesignTree.FindApplicationNodeByName(appName);

            if (node != null)
            {
                throw new Exception("Application has existed.");
            }
            if (System.Text.Encoding.UTF8.GetByteCount(appName) > 8)
            {
                throw new Exception("Application name too long");
            }
            var appRootNode = hub.DesignTree.AppRootNode;
            var appModel    = new ApplicationModel("appbox", appName); //TODO:fix owner
            var appNode     = new ApplicationNode(hub.DesignTree, appModel);

            appRootNode.Nodes.Add(appNode);
            // 直接创建并保存
            await Store.ModelStore.CreateApplicationAsync(appModel);

            return(new NewNodeResult
            {
                ParentNodeType = (int)appRootNode.NodeType,
                ParentNodeID = appRootNode.ID,
                NewNode = appNode
            });
        }
Esempio n. 18
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var refType       = (ModelReferenceType)args.GetInt32();
            var modelIDString = args.GetString();
            var memberName    = args.GetString();
            var modelId       = ulong.Parse(modelIDString);

            ModelType modelType = IdUtil.GetModelTypeFromModelId(modelId);
            var       modelNode = hub.DesignTree.FindModelNode(modelType, modelId);

            if (modelNode == null)
            {
                throw new Exception("Can't find model");
            }

            return(await RefactoringService.FindUsagesAsync(hub, refType,
                                                            modelNode.AppNode.Model.Name, modelNode.Model.Name, memberName));
        }
Esempio n. 19
0
        public Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var modelID = args.GetString();
            var array   = args.GetObjectArray();
            var newDeps = array != null?array.Cast <string>().ToArray() : new string[0];

            var modelNode = hub.DesignTree.FindModelNode(ModelType.Service, ulong.Parse(modelID));

            if (modelNode == null)
            {
                throw new Exception("Can't find service model node");
            }

            var model   = (ServiceModel)modelNode.Model;
            var appName = modelNode.AppNode.Model.Name;

            //开始比对
            //bool hasChanged = false;
            if (model.HasReference)
            {
                //先处理移除的
                for (int i = model.References.Count - 1; i >= 0; i--)
                {
                    if (!newDeps.Contains(model.References[i]))
                    {
                        hub.TypeSystem.RemoveServiceReference(modelNode.ServiceProjectId, appName, model.References[i]);
                        model.References.RemoveAt(i);
                        //hasChanged = true;
                    }
                }
                //再处理新增的
                for (int i = 0; i < newDeps.Length; i++)
                {
                    if (!model.References.Contains(newDeps[i]))
                    {
                        hub.TypeSystem.AddServiceReference(modelNode.ServiceProjectId, appName, newDeps[i]);
                        model.References.Add(newDeps[i]);
                        //hasChanged = true;
                    }
                }
            }
            else if (newDeps.Length > 0)
            {
                for (int i = 0; i < newDeps.Length; i++)
                {
                    hub.TypeSystem.AddServiceReference(modelNode.ServiceProjectId, appName, newDeps[i]);
                    model.References.Add(newDeps[i]);
                }
                //hasChanged = true;
            }

            //if (hasChanged)
            //    await modelNode.SaveAsync(null);

            return(Task.FromResult((object)null));
        }
Esempio n. 20
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var nodeType = (DesignNodeType)args.GetInt32();
            var nodeID   = args.GetString();

            var node = hub.DesignTree.FindNode(nodeType, nodeID);

            if (node == null)
            {
                throw new Exception($"Can't find DesignNode: {nodeID}");
            }

            var modelNode = node as ModelNode;

            if (modelNode != null)
            {
                var  curVersion = modelNode.Model.Version;
                bool checkoutOk = await modelNode.Checkout();

                if (!checkoutOk)
                {
                    throw new Exception($"Can't checkout ModelNode: {nodeID}");
                }
                if (curVersion != modelNode.Model.Version)
                {
                    return(true); //返回True表示模型已变更,用于前端刷新
                }
            }
            else if (node.NodeType == DesignNodeType.ModelRootNode)
            {
                bool checkoutOk = await node.Checkout();

                if (!checkoutOk)
                {
                    throw new Exception("Can't checkout ModelRootNode");
                }
                return(true); //TODO:暂返回需要更新
            }
            else if (node.NodeType == DesignNodeType.DataStoreNode)
            {
                bool checkoutOk = await node.Checkout();

                if (!checkoutOk)
                {
                    throw new Exception("Can't checkout DataStoreNode");
                }
                return(false);
            }
            else
            {
                throw new Exception("无法签出此类型的节点");
            }

            return(false);
        }
Esempio n. 21
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var modelID = args.GetString();
            var line    = args.GetInt32() - 1;
            var column  = args.GetInt32() - 1;

            var modelNode = hub.DesignTree.FindModelNode(ModelType.Service, ulong.Parse(modelID));

            if (modelNode == null)
            {
                throw new Exception("Can't find service model node");
            }

            //定位服务入口方法
            var doc           = hub.TypeSystem.Workspace.CurrentSolution.GetDocument(modelNode.RoslynDocumentId);
            var semanticModel = await doc.GetSemanticModelAsync();

            var sourceText = await doc.GetTextAsync();

            var position = sourceText.Lines.GetPosition(new LinePosition(line, column));
            var symbol   = await SymbolFinder.FindSymbolAtPositionAsync(semanticModel, position, hub.TypeSystem.Workspace);

            if (symbol == null)
            {
                throw new Exception("Can't find service method");
            }
            if (symbol.Kind != SymbolKind.Method)
            {
                throw new Exception("Not a method");
            }
            if (symbol.ContainingType.ToString() != string.Format("{0}.ServiceLogic.{1}", modelNode.AppNode.ID, modelNode.Model.Name))
            {
                throw new Exception("Not a service method");
            }
            if (symbol.DeclaredAccessibility.ToString() != "Public")
            {
                throw new Exception("Not a service method");
            }

            IMethodSymbol method = symbol as IMethodSymbol;
            var           sb     = new StringBuilder("{\"Name\":\"");

            sb.Append(method.Name);
            sb.Append("\", \"Args\":[");
            for (int i = 0; i < method.Parameters.Length; i++)
            {
                sb.AppendFormat("{{\"Name\":\"{0}\",\"Type\":\"{1}\"}}", method.Parameters[i].Name, method.Parameters[i].Type);
                if (i != method.Parameters.Length - 1)
                {
                    sb.Append(",");
                }
            }
            sb.Append("]}");
            return(sb.ToString());
        }
Esempio n. 22
0
        public Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var    targetEntityModelID = args.GetString();
            var    refModels           = hub.DesignTree.FindEntityRefModels(ulong.Parse(targetEntityModelID));
            object res = refModels.Select(t => new
            {
                Path     = $"{hub.DesignTree.FindApplicationNode(t.Owner.AppId).Model.Name}.{t.Owner.Name}.{t.Name}",
                EntityID = t.Owner.Id.ToString(), //ulong转换为string
                MemberID = t.MemberId,
            }).ToArray();

            return(Task.FromResult(res));
        }
Esempio n. 23
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            // 获取接收到的参数
            string modelId          = args.GetString();
            string memberName       = args.GetString();
            int    entityMemberType = args.GetInt32();

            var node = hub.DesignTree.FindModelNode(ModelType.Entity, ulong.Parse(modelId));

            if (node == null)
            {
                throw new Exception("Can't find entity model node");
            }
            var model = (EntityModel)node.Model;

            if (!node.IsCheckoutByMe)
            {
                throw new Exception("Node has not checkout");
            }
            if (!CodeHelper.IsValidIdentifier(memberName))
            {
                throw new Exception("Name is invalid");
            }
            if (memberName == model.Name)
            {
                throw new Exception("Name can not same as Entity name");
            }
            if (model.Members.FindIndex(t => t.Name == memberName) >= 0) //if (model.ContainsMember(memberName))
            {
                throw new Exception("Name has exists");
            }
            EntityMemberModel res = entityMemberType switch
            {
                (int)EntityMemberType.DataField => NewDataField(model, memberName, ref args),
                (int)EntityMemberType.EntityRef => NewEntityRef(hub, model, memberName, ref args),
                (int)EntityMemberType.EntitySet => NewEntitySet(hub, model, memberName, ref args),
                _ => throw new NotImplementedException($"未实现的成员类型: {entityMemberType}"),
            };
Esempio n. 24
0
        public async ValueTask <AnyValue> InvokeAsync(ReadOnlyMemory <char> method, InvokeArgs args)
        {
            switch (method)
            {
            case ReadOnlyMemory <char> s when s.Span.SequenceEqual(nameof(LoadPermissionNodes)):
                return(AnyValue.From(await LoadPermissionNodes()));

            case ReadOnlyMemory <char> s when s.Span.SequenceEqual(nameof(SavePermission)):
                return(AnyValue.From(await SavePermission(args.GetString(), args.GetObjectArray())));

            default:
                throw new Exception($"Can't find method: {method}");
            }
        }
Esempio n. 25
0
        public Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var modelID   = args.GetString();
            var modelNode = hub.DesignTree.FindModelNode(ModelType.Enum, ulong.Parse(modelID));

            if (modelNode == null)
            {
                throw new Exception("Can't find EnumModel.");
            }

            var enumModel = (EnumModel)modelNode.Model;

            return(Task.FromResult <object>(enumModel.Items));
        }
Esempio n. 26
0
        public Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var fileName = args.GetString();
            var document = hub.TypeSystem.Workspace.GetOpenedDocumentByName(fileName);

            if (document == null)
            {
                throw new Exception(string.Format("Cannot find opened document: {0}", fileName));
            }

            var changes = FormattingWorker.GetFormattedTextChanges(document).Result;

            return(Task.FromResult <object>(changes.ToArray()));
        }
Esempio n. 27
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            string commitMessage = args.GetString();

            if (hub.PendingChanges == null || hub.PendingChanges.Length == 0)
            {
                return(null);
            }

            //将PendingChanges转为PublishPackage
            var package = new PublishPackage();

            for (int i = 0; i < hub.PendingChanges.Length; i++)
            {
                var change = hub.PendingChanges[i];
                switch (change)
                {
                case ModelBase model:
                    package.Models.Add(model); break;

                case ModelFolder folder:
                    package.Folders.Add(folder); break;

                case StagedItems.StagedSourceCode code:
                    package.SourceCodes.Add(code.ModelId, code.CodeData); break;

                case StagedItems.StagedViewRuntimeCode viewAsm:
                {
                    //先找到名称
                    var    viewModelNode = hub.DesignTree.FindModelNode(ModelType.View, viewAsm.ModelId);
                    string asmName       = $"{viewModelNode.AppNode.Model.Name}.{viewModelNode.Model.Name}";
                    package.ViewAssemblies.Add(asmName, viewAsm.CodeData);
                }
                break;

                default:
                    Log.Warn($"Unknow pending change: {change.GetType()}"); break;
                }
            }

            PublishService.ValidateModels(hub, package);
            await PublishService.CompileModelsAsync(hub, package);

            await PublishService.PublishAsync(hub, package, commitMessage);

            //最后清空临时用的PendingChanges
            hub.PendingChanges = null;

            return(null);
        }
Esempio n. 28
0
        public async ValueTask <AnyValue> InvokeAsync(ReadOnlyMemory <char> method, InvokeArgs args)
        {
            switch (method)
            {
            case ReadOnlyMemory <char> s when s.Span.SequenceEqual(nameof(GetGauges)):
                return(AnyValue.From(await GetGauges()));

            case ReadOnlyMemory <char> s when s.Span.SequenceEqual(nameof(GetNodes)):
                return(AnyValue.From(await GetNodes()));

            case ReadOnlyMemory <char> s when s.Span.SequenceEqual(nameof(GetParts)):
                return(AnyValue.From(await GetParts()));

            case ReadOnlyMemory <char> s when s.Span.SequenceEqual(nameof(SetAsMeta)):
                return(AnyValue.From(await SetAsMeta(args.GetString(), args.GetString(), args.GetInt32())));

            case ReadOnlyMemory <char> s when s.Span.SequenceEqual(nameof(PromoteReplFactor)):
                return(AnyValue.From(await PromoteReplFactor()));

            default:
                throw new Exception($"Can't find method: {method}");
            }
        }
Esempio n. 29
0
        public Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var modelID      = args.GetString();
            var memeberName  = args.GetString();
            var propertyName = args.GetString();

            var modelNode = hub.DesignTree.FindModelNode(ModelType.Enum, ulong.Parse(modelID));

            if (modelNode == null)
            {
                throw new Exception("Can't find Enum node");
            }
            var model = (EnumModel)modelNode.Model;

            var item = model.Items.FirstOrDefault(t => t.Name == memeberName);

            if (item == null)
            {
                throw new Exception($"Can't find Enum item: {memeberName}");
            }
            if (propertyName == "Comment")
            {
                var propertyValue = args.GetString();
                item.Comment = propertyValue;
            }
            else if (propertyName == "Value")
            {
                var v = args.GetInt32();
                if (model.Items.FirstOrDefault(t => t.Value == v && t.Name != memeberName) != null)
                {
                    throw new Exception("Value has exists");
                }
                item.Value = v;
                //TODO:***签出所有此成员的引用项,如服务模型需要重新编译发布
            }
            return(Task.FromResult <object>(true));
        }
Esempio n. 30
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            // 获取接收到的参数
            string modelId  = args.GetString();
            string itemName = args.GetString();

            var modelNode = hub.DesignTree.FindModelNode(ModelType.Enum, ulong.Parse(modelId));

            if (modelNode == null)
            {
                throw new Exception("Can't find Enum node");
            }
            var model = (EnumModel)modelNode.Model;

            //查找成员引用
            var refs = await RefactoringService.FindUsagesAsync(hub,
                                                                ModelReferenceType.EnumModelItemName, modelNode.AppNode.Model.Name, model.Name, itemName);

            if (refs != null && refs.Count > 0) //有引用项不做删除操作
            {
                return(refs);                   //TODO:直接报错,不返回引用项
            }
            var item = model.Items.FirstOrDefault(t => t.Name == itemName);

            if (item != null)
            {
                model.Items.Remove(item);
            }
            // 保存到本地
            await modelNode.SaveAsync(null);

            // 更新RoslynDocument
            await hub.TypeSystem.UpdateModelDocumentAsync(modelNode);

            return(null);
        }