/// <summary> /// This method loads the DSL view model with the items in the artifact's C-Model. /// </summary> internal void ReloadModel(EntityDesignerViewModel viewModel) { var diagram = viewModel.GetDiagram(); if (diagram == null) { // empty DSL diagram return; } // get our artifact var artifact = EditingContextManager.GetArtifact(viewModel.EditingContext) as EntityDesignArtifact; Debug.Assert(artifact != null); var serializationResult = new SerializationResult(); var serializationContext = new SerializationContext(GetDirectory(viewModel.Store), artifact.Uri.LocalPath, serializationResult); var transactionContext = new TransactionContext(); transactionContext.Add(SerializationContext.TransactionContextKey, serializationContext); var workaroundFixSerializationTransactionValue = false; if (viewModel.Store.PropertyBag.ContainsKey("WorkaroundFixSerializationTransaction")) { workaroundFixSerializationTransactionValue = (bool)viewModel.Store.PropertyBag["WorkaroundFixSerializationTransaction"]; } try { // To fix performance issue during reload, we turn-off layout during "serialization". viewModel.Store.PropertyBag["WorkaroundFixSerializationTransaction"] = true; using (var t = viewModel.Store.TransactionManager.BeginTransaction("ReloadModel", true, transactionContext)) { if (artifact.ConceptualModel() == null) { return; } DesignerModel.Diagram diagramModel = null; // If DiagramId is not string empty, try to get the diagram from the artifact. // There is a situation where we could not find the diagram given an ID (for example: EDMX Model's Diagram that is created by VS before SQL 11; // In that case, we assign temporary ID to the diagram and a new ID will be generated every time the model is reloaded.) // We could safely choose the first diagram since multiple diagrams feature didn't exist in VS prior to SQL11 release. if (!string.IsNullOrEmpty(diagram.DiagramId)) { diagramModel = artifact.DesignerInfo.Diagrams.GetDiagram(diagram.DiagramId); } if (diagramModel == null) { diagramModel = artifact.DesignerInfo.Diagrams.FirstDiagram; } if (diagramModel != null) { // Re-establish the xref between Escher conceptual model and DSL root model. // and between Escher Diagram model and DSL diagram model. Debug.Assert(viewModel.ModelXRef != null, "Why ModelXRef is null?"); if (viewModel.ModelXRef != null) { viewModel.ModelXRef.Add(artifact.ConceptualModel(), viewModel, viewModel.EditingContext); viewModel.ModelXRef.Add(diagramModel, diagram, viewModel.EditingContext); ModelTranslatorContextItem.GetEntityModelTranslator(viewModel.EditingContext) .TranslateModelToDslModel(diagramModel, viewModel.Partition); } } if (t.IsActive) { t.Commit(); } } } finally { viewModel.Store.PropertyBag["WorkaroundFixSerializationTransaction"] = workaroundFixSerializationTransactionValue; } }
static void UpdateScriptReferences() { var defaultScriptReferences = CreateInstance <DefaultScriptReferences>(); var prefabsRoot = new GameObject(Path.GetFileNameWithoutExtension(k_Path)); prefabsRoot.SetActive(false); Action <ICollection> create = types => { foreach (Type t in types) { if (t.IsNested || !typeof(MonoBehaviour).IsAssignableFrom(t)) { continue; } if (t.GetCustomAttributes(true).OfType <EditorOnlyWorkspaceAttribute>().Any()) { continue; } var mb = (MonoBehaviour)EditorXRUtils.CreateGameObjectWithComponent(t, prefabsRoot.transform, runInEditMode: false); if (mb) { mb.gameObject.hideFlags = HideFlags.None; mb.enabled = false; mb.transform.parent = prefabsRoot.transform; } } }; var defaultReferenceTypes = new List <Type>(); typeof(IProxy).GetImplementationsOfInterface(defaultReferenceTypes); typeof(ITool).GetImplementationsOfInterface(defaultReferenceTypes); typeof(IMainMenu).GetImplementationsOfInterface(defaultReferenceTypes); typeof(IToolsMenu).GetImplementationsOfInterface(defaultReferenceTypes); typeof(IAlternateMenu).GetImplementationsOfInterface(defaultReferenceTypes); typeof(IAction).GetImplementationsOfInterface(defaultReferenceTypes); typeof(IWorkspace).GetImplementationsOfInterface(defaultReferenceTypes); typeof(IScriptReference).GetImplementationsOfInterface(defaultReferenceTypes); create(defaultReferenceTypes); var directory = Path.GetDirectoryName(k_Path); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } defaultScriptReferences.m_ScriptPrefab = PrefabUtility.SaveAsPrefabAsset(prefabsRoot, Path.ChangeExtension(k_Path, "prefab")); defaultScriptReferences.m_EditingContexts = EditingContextManager.GetEditingContextAssets().ConvertAll(ec => (ScriptableObject)ec); AssetDatabase.CreateAsset(defaultScriptReferences, k_Path); DestroyImmediate(prefabsRoot); if (!Application.isBatchMode) { AssetDatabase.SaveAssets(); } }