public async Task <object> Handle(DesignHub hub, InvokeArgs args) { var staged = await StagedService.LoadStagedAsync(onlyModelsAndFolders : false); //TODO:暂重新加载 hub.PendingChanges = staged.Items; if (hub.PendingChanges == null || hub.PendingChanges.Length == 0) { return(null); } var res = new List <ChangedInfo>(); for (int i = 0; i < hub.PendingChanges.Length; i++) { //TODO:其他类型处理 if (hub.PendingChanges[i] is ModelBase model) { res.Add(new ChangedInfo { ModelType = model.ModelType.ToString(), ModelID = model.Name }); } else if (hub.PendingChanges[i] is ModelFolder folder) { res.Add(new ChangedInfo { ModelType = ModelType.Folder.ToString(), ModelID = folder.TargetModelType.ToString() }); } } return(res); }
internal async Task LoadNodesAsync() { if (Interlocked.CompareExchange(ref _loadingFlag, 1, 0) != 0) { throw new Exception("DesignTree are loading."); } //先判断是否已经加载过,是则清空准备重新加载 if (Nodes.Count > 0) { DesignHub.ResetTypeSystem(); Nodes.Clear(); } //开始加载 StoreRootNode = new DataStoreRootNode(this); Nodes.Add(StoreRootNode); AppRootNode = new ApplicationRootNode(this); Nodes.Add(AppRootNode); //先加载签出信息及StagedModels _checkouts = await CheckoutService.LoadAllAsync(); Staged = await StagedService.LoadStagedAsync(onlyModelsAndFolders : true); var amodels = await Store.ModelStore.LoadAllApplicationAsync(); var applicationModels = new List <ApplicationModel>(amodels); applicationModels.Sort((a, b) => a.Name.CompareTo(b.Name)); var mfolders = await Store.ModelStore.LoadAllFolderAsync(); var folders = new List <ModelFolder>(mfolders); //从staged中添加新建的并更新修改的文件夹 Staged.UpdateFolders(folders); var mmodels = await Store.ModelStore.LoadAllModelAsync(); var models = new List <ModelBase>(mmodels); #if !FUTURE //加载默认存储模型 var defaultStoreType = Store.SqlStore.Default.GetType(); var defaultStoreModel = new DataStoreModel(DataStoreKind.Sql, $"{defaultStoreType.Assembly.GetName().Name};{defaultStoreType.Name}", "Default"); defaultStoreModel.NameRules = DataStoreNameRules.AppPrefixForTable; //defaultStoreModel.Settings = ""; //TODO:fix settings defaultStoreModel.AcceptChanges(); models.Add(defaultStoreModel); #endif //加载staged中新建的模型,可能包含DataStoreModel models.AddRange(Staged.FindNewModels()); //加入AppModels节点 foreach (var app in applicationModels) { AppRootNode.Nodes.Add(new ApplicationNode(this, app)); } //加入Folders foreach (var f in folders) { FindModelRootNode(f.AppId, f.TargetModelType).AddFolder(f); } //加入Models Staged.RemoveDeletedModels(models); //先移除已删除的 var allModelNodes = new List <ModelNode>(models.Count); foreach (var m in models) { if (m.ModelType == ModelType.DataStore) { var dsModel = (DataStoreModel)m; var dsNode = StoreRootNode.AddModel(dsModel, DesignHub); DesignHub.TypeSystem.CreateStoreDocument(dsNode); } else { allModelNodes.Add(FindModelRootNode(m.AppId, m.ModelType).AddModel(m)); } } //在所有节点加载完后创建模型对应的RoslynDocument foreach (var n in allModelNodes) { await DesignHub.TypeSystem.CreateModelDocumentAsync(n); } Interlocked.Exchange(ref _loadingFlag, 0); //清空Staged Staged = null; #if DEBUG ThreadPool.QueueUserWorkItem(s => { DesignHub.TypeSystem.DumpProjectErrors(DesignHub.TypeSystem.ModelProjectId); //DesignHub.TypeSystem.DumpProjectErrors(DesignHub.TypeSystem.SyncSysServiceProjectId); DesignHub.TypeSystem.DumpProjectErrors(DesignHub.TypeSystem.ServiceBaseProjectId); }); #endif }