Example #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);
        }
        public async Task GenServiceCodeTest()
        {
            var mockRuntimeCtx = new Core.Tests.MockRuntimeContext();

            mockRuntimeCtx.AddModel(Core.Tests.TestHelper.CityModel);
            mockRuntimeCtx.AddModel(Core.Tests.TestHelper.CustomerModel);
            mockRuntimeCtx.AddModel(Core.Tests.TestHelper.OrderModel);
            RuntimeContext.Init(mockRuntimeCtx, 10410);

            var session = new MockDeveloperSession();
            var ctx     = new DesignHub(session);
            var apps    = new List <ApplicationModel>()
            {
                Core.Tests.TestHelper.SysAppModel
            };
            var models = new List <ModelBase>
            {
                Core.Tests.TestHelper.EmploeeModel,
                Core.Tests.TestHelper.VehicleStateModel,
                Core.Tests.TestHelper.OrgUnitModel,
                Core.Tests.TestHelper.CityModel,
                Core.Tests.TestHelper.CustomerModel,
                Core.Tests.TestHelper.OrderModel,
                Core.Tests.TestHelper.AdminPermissionModel,
                Core.Tests.TestHelper.DeveloperPermissionModel
            };
            await ctx.DesignTree.LoadForTest(apps, models);

            //模拟添加存储模型,参照NewDataStore Handler
            var storeNode = ctx.DesignTree.StoreRootNode.AddModel(Core.Tests.TestHelper.SqlStoreModel, ctx);

            ctx.TypeSystem.CreateStoreDocument(storeNode);

            //模拟添加服务模型, 参照NewServiceModel Handler
            var serviceRootNode = ctx.DesignTree.FindModelRootNode(Consts.SYS_APP_ID, ModelType.Service);
            var parentNode      = serviceRootNode;

            //测试被调用的服务
            var modelId = (ulong)Consts.SYS_APP_ID << 32;

            modelId |= (ulong)ModelType.Service << 24;
            modelId |= (ulong)1 << 3;
            modelId |= (ulong)ModelLayer.DEV << 1;
            var model = new ServiceModel(modelId, "TestService");
            var node  = new ModelNode(model, ctx);

            parentNode.Nodes.Add(node);
            serviceRootNode.AddModelIndex(node);
            node.CheckoutInfo = new CheckoutInfo(node.NodeType, node.CheckoutInfoTargetID, model.Version,
                                                 ctx.Session.Name, ctx.Session.LeafOrgUnitID);
            var souceCode = Resources.LoadStringResource("Resources.Code.TestService.cs");
            await ctx.TypeSystem.CreateModelDocumentAsync(node, souceCode);

            //测试生成用的服务
            var modelId1 = (ulong)Consts.SYS_APP_ID << 32;

            modelId1 |= (ulong)ModelType.Service << 24;
            modelId1 |= (ulong)1 << 5;
            modelId1 |= (ulong)ModelLayer.DEV << 1;
            var model1 = new ServiceModel(modelId1, "HelloService");
            var node1  = new ModelNode(model1, ctx);

            parentNode.Nodes.Add(node1);
            serviceRootNode.AddModelIndex(node1);
            node1.CheckoutInfo = new CheckoutInfo(node1.NodeType, node1.CheckoutInfoTargetID, model1.Version,
                                                  ctx.Session.Name, ctx.Session.LeafOrgUnitID);
            var souceCode1 = Resources.LoadStringResource("Resources.Code.HelloService.cs");
            await ctx.TypeSystem.CreateModelDocumentAsync(node1, souceCode1);

            //生成服务代码
            var data = await PublishService.CompileServiceAsync(ctx, model1);

            Assert.NotNull(data);
        }