Пример #1
0
        public async Task <object> Handle(DesignHub hub, InvokeArgs args)
        {
            var modelId    = args.GetString();
            var changeType = args.GetString();

            var node = hub.DesignTree.FindNode(DesignNodeType.EntityModelNode, modelId);

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

            if (!modelNode.IsCheckoutByMe)
            {
                throw new Exception("Node has not checkout");
            }

            //注意某些操作需要更新RoslynDocument
            switch (changeType)
            {
            case "PrimaryKeys":
                if (model.PersistentState != PersistentState.Detached)
                {
                    //TODO:如果是修改则必须查找服务方法内的引用,签出节点并修改
                    //1. new XXXX(pks)改为new XXX(/*fix pk changed*/)
                    //2. Entities.XXX.LoadAsync(pks)同上
                    throw new NotImplementedException("改变主键尚未实现");
                }
                ChangePrimaryKeys(model, args.GetString());
                await hub.TypeSystem.UpdateModelDocumentAsync(modelNode);

                //TODO:同时返回签出列表
                break;

            case "PartitionKeys":
                ChangePartitionKeys(model, args.GetString());
                if (model.SysStoreOptions != null)     //仅SysStore需要更新RoslynDocument
                {
                    await hub.TypeSystem.UpdateModelDocumentAsync(modelNode);
                }
                break;

            case "ClusteringColumns":
                ChangeClusteringColumns(model, args.GetString());
                break;

            case "AddIndex":
                var res = AddIndex(model, args.GetString());
                await hub.TypeSystem.UpdateModelDocumentAsync(modelNode);

                return(res);

            case "RemoveIndex":
                await RemoveIndex(hub, modelNode.AppNode.Model.Name, model, args.GetByte());

                await hub.TypeSystem.UpdateModelDocumentAsync(modelNode);

                break;

            default:
                throw new NotSupportedException(changeType);
            }

            return(null);
        }