Beispiel #1
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
            });
        }
Beispiel #2
0
        private static async Task ImportApp(DesignHub ctx, AppPackage pkg)
        {
            //TODO:暂重用更新逻辑简单实现
            //先创建应用,必须添加到设计树内,因保存实体模型时获取表名需要用到
            var appRootNode = ctx.DesignTree.AppRootNode;
            var appNode     = new ApplicationNode(ctx.DesignTree, pkg.Application);

            appRootNode.Nodes.Add(appNode);
            await ModelStore.CreateApplicationAsync(pkg.Application);

            await UpdateApp(ctx, pkg, pkg.Application);
        }
Beispiel #3
0
        /// <summary>
        /// 仅用于单元测试
        /// </summary>
        internal async Task LoadForTest(List <ApplicationModel> apps, List <ModelBase> models)
        {
            if (Interlocked.CompareExchange(ref _loadingFlag, 1, 0) != 0)
            {
                throw new Exception("DesignTree has loaded or loading.");
            }

            StoreRootNode = new DataStoreRootNode(this);
            Nodes.Add(StoreRootNode);
            AppRootNode = new ApplicationRootNode(this);
            Nodes.Add(AppRootNode);

            _checkouts = new Dictionary <string, CheckoutInfo>();

            //加入AppModels节点
            for (int i = 0; i < apps.Count; i++)
            {
                var appNode = new ApplicationNode(this, apps[i]);
                AppRootNode.Nodes.Add(appNode);
            }
            //加入Models
            var allModelNodes = new ModelNode[models.Count];

            for (int i = 0; i < models.Count; i++)
            {
                allModelNodes[i] = FindModelRootNode(models[i].AppId, models[i].ModelType).AddModel(models[i]);
            }
            //创建RoslynDocument
            for (int i = 0; i < models.Count; i++)
            {
                await DesignHub.TypeSystem.CreateModelDocumentAsync(allModelNodes[i]);
            }

            Interlocked.Exchange(ref _loadingFlag, 0);

            DesignHub.TypeSystem.DumpProjectErrors(DesignHub.TypeSystem.ModelProjectId);
            //DesignHub.TypeSystem.DumpProjectErrors(DesignHub.TypeSystem.SyncSysServiceProjectId);
            DesignHub.TypeSystem.DumpProjectErrors(DesignHub.TypeSystem.ServiceBaseProjectId);
        }
Beispiel #4
0
        private static async Task DeleteApplicationNode(DesignHub hub, ApplicationNode appNode)
        {
            //TODO:*****暂简单实现,待实现: 签出所有子节点,判断有无其他应用的引用
            //TODO:考虑删除整个应用前自动导出备份

            //先组包用现有PublishService发布(删除)
            var pkg        = new PublishPackage();
            var modelNodes = appNode.GetAllModelNodes();

            foreach (var modelNode in modelNodes)
            {
                if (modelNode.Model.PersistentState != PersistentState.Detached)
                {
                    modelNode.Model.MarkDeleted();
                    pkg.Models.Add(modelNode.Model);
                    //不用加入需要删除的相关代码及组件
                }

                //删除所有Roslyn相关
                RemoveRoslynFromModelNode(hub, modelNode);
            }
            //加入待删除的根级文件夹
            var rootFolders = appNode.GetAllRootFolders();

            foreach (var rootFolder in rootFolders)
            {
                rootFolder.IsDeleted = true;
                pkg.Folders.Add(rootFolder);
            }
            //TODO:暂使用PublishService.PublishAsync,且与删除ApplicationModel非事务
            await PublishService.PublishAsync(hub, pkg, $"Delete Application: {appNode.Model.Name}");

            //删除ApplicationModel
            await Store.ModelStore.DeleteApplicationAsync(appNode.Model);

            //TODO:清理Staged(只清理当前删除的App相关的)
            //最后从设计树移除ApplicationNode
            hub.DesignTree.AppRootNode.Nodes.Remove(appNode);
        }