/// <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); }
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 }