Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private static async Task UpdateApp(DesignHub ctx, AppPackage from, ApplicationModel localAppModel)
        {
            //TODO:考虑删除本地已签出的所有变更
            //TODO:1.签出本地对应App的所有节点,包括模型根节点

            var local = new AppPackage();
            await ModelStore.LoadToAppPackage(localAppModel.Id, localAppModel.Name, local);

            var publish = new PublishPackage();
            //----比对文件夹----
            var folderComparer = new FolderComparer();
            var newFolders     = from.Folders.Except(local.Folders, folderComparer);

            foreach (var newFolder in newFolders)
            {
                newFolder.Import();
                publish.Folders.Add(newFolder);
            }
            //var removedFolders = local.Folders.Except(from.Folders, folderComparer);
            //foreach (var removedFolder in removedFolders)
            //{
            //    removedFolder.Remove();
            //    publish.Folders.Add(removedFolder);
            //}
            var otherFolders = local.Folders.Intersect(from.Folders, folderComparer);

            foreach (var folder in otherFolders)
            {
                if (folder.UpdateFrom(from.Folders.Single(t => t.TargetModelType == folder.TargetModelType && t.Id == folder.Id)))
                {
                    publish.Folders.Add(folder);
                }
            }

            //----比对模型----
            var modelComparer = new ModelComparer();
            var newModels     = from.Models.Except(local.Models, modelComparer);

            foreach (var newModel in newModels)
            {
                newModel.Import();
                publish.Models.Add(newModel);
                //导入相关代码及Assembly
                if (newModel.ModelType == ModelType.Service)
                {
                    publish.SourceCodes.Add(newModel.Id, from.SourceCodes[newModel.Id]);
                    var key = $"{from.Application.Name}.{newModel.Name}";
                    publish.ServiceAssemblies.Add(key, from.ServiceAssemblies[key]);
                }
                else if (newModel.ModelType == ModelType.View)
                {
                    publish.SourceCodes.Add(newModel.Id, from.SourceCodes[newModel.Id]);
                    var key = $"{from.Application.Name}.{newModel.Name}";
                    publish.ViewAssemblies.Add(key, from.ViewAssemblies[key]);
                }
            }
            //if (localAppModel.ID != SysGlobal.SysString) //注意:系统应用包不移除仅本地有的模型
            //{
            var removedModles = local.Models.Except(from.Models, modelComparer);

            foreach (var removedModel in removedModles)
            {
                removedModel.MarkDeleted();
                publish.Models.Add(removedModel);
                //删除模型的相关代码组件等由PublishService处理,不用再加入
            }
            //}
            var otherModels = local.Models.Intersect(from.Models, modelComparer);

            foreach (var model in otherModels)
            {
                if (model.UpdateFrom(from.Models.Single(t => t.ModelType == model.ModelType && t.Id == model.Id)))
                {
                    publish.Models.Add(model);
                }
                if (model.ModelType == ModelType.Service)
                {
                    publish.SourceCodes.Add(model.Id, from.SourceCodes[model.Id]);
                    var key = $"{from.Application.Name}.{model.Name}";
                    publish.ServiceAssemblies.Add(key, from.ServiceAssemblies[key]);
                }
                else if (model.ModelType == ModelType.View)
                {
                    publish.SourceCodes.Add(model.Id, from.SourceCodes[model.Id]);
                    var key = $"{from.Application.Name}.{model.Name}";
                    publish.ViewAssemblies.Add(key, from.ViewAssemblies[key]);
                }
            }

            //发布变更的包
            await PublishService.PublishAsync(ctx, publish, "Import");
        }