/// <summary> /// Loads the domain model from a specified file. /// </summary> /// <param name="fileName">Filename to load the domain model from.</param> /// <param name="isReload"></param> protected override void LoadDocument(string fileName, bool isReload) { this.rootModelElement = null; serializationResult = new DslEditorModeling::SerializationResult(); DslModeling::SerializationResult result = new DslModeling.SerializationResult(); global::Tum.FamilyTreeDSL.FamilyTreeModel modelRoot = null; // reset post process info FamilyTreeDSLSerializationPostProcessor.Instance.Reset(); DslModeling::Transaction transaction = this.ModelData.Store.TransactionManager.BeginTransaction("Load model", true); try { modelRoot = global::Tum.FamilyTreeDSL.FamilyTreeDSLSerializationHelper.Instance.LoadModelFamilyTreeModel(result, this.ModelData.GetModelPartition(), fileName, null, null, null); // post process if( modelRoot != null && !serializationResult.Failed) { FamilyTreeDSLSerializationPostProcessor.Instance.DoPostProcess(new System.Collections.Generic.List<string>(), result, modelRoot.Store); } if( !serializationResult.Failed ) // start validation because UseLoad=true ValidateAll(); // load diagramsModel string diagramsFileName = GetDiagramsFileName(fileName); if(System.IO.File.Exists(diagramsFileName) ) diagramsModel = FamilyTreeDSLDiagramsDSLSerializationHelper.Instance.LoadModel(result, this.ModelData.GetModelPartition(), GetDiagramsFileName(fileName), null, null, null); if( diagramsModel == null ) diagramsModel = new DslEditorDiagrams::DiagramsModel(this.ModelData.Store); if( !diagramsModel.ContainsDiagram("DesignerDiagram") ) { DesignerDiagram diagramDesignerDiagram = new DesignerDiagram(this.ModelData.Store); diagramDesignerDiagram.Name = "DesignerDiagram"; diagramsModel.Diagrams.Add(diagramDesignerDiagram); } diagramsModel.GetDiagram("DesignerDiagram").Initialize(); OnPropertyChanged("DesignerDiagram"); if( result.Failed ) transaction.Rollback(); else transaction.Commit(); } catch (System.Exception ex) { serializationResult.AddMessage(new DslEditorModeling::SerializationMessage( FamilyTreeDSLValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error, ex.Message, fileName, 0, 0)); transaction.Rollback(); } // copy messages bool bHasMessages = false; foreach (DslModeling::SerializationMessage m in result) { bHasMessages = true; DslEditorModeling.ModelValidationViolationType kind = DslEditorModeling.ModelValidationViolationType.Error; if( m.Kind == DslModeling.SerializationMessageKind.Info ) kind = DslEditorModeling.ModelValidationViolationType.Message; else if( m.Kind == DslModeling.SerializationMessageKind.Warning ) kind = DslEditorModeling.ModelValidationViolationType.Warning; DslEditorModeling::SerializationMessage message = new DslEditorModeling.SerializationMessage( FamilyTreeDSLValidationMessageIds.SerializationMessageId, kind, m.Message, m.Location, m.Line, m.Column); serializationResult.AddMessage(message); } serializationResult.Failed = result.Failed; if (serializationResult.Failed) { // Load failed, can't open the file. serializationResult.AddMessage(new DslEditorModeling::SerializationMessage(FamilyTreeDSLValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error, FamilyTreeDSLDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"), fileName, 0, 0)); } else { this.rootModelElement = modelRoot; } if( !serializationResult.Failed && !bHasMessages ) // start validation because UseOpen=true ValidateAll(); }
/// <summary> /// Loads the domain model from a specified file. /// </summary> /// <param name="fileName">Filename to load the domain model from.</param> /// <param name="isReload"></param> protected override void LoadDocument(string fileName, bool isReload) { this.rootModelElement = null; serializationResult = new DslEditorModeling::SerializationResult(); DslModeling::SerializationResult result = new DslModeling.SerializationResult(); global::Tum.FamilyTreeDSL.FamilyTreeModel modelRoot = null; // reset post process info FamilyTreeDSLSerializationPostProcessor.Instance.Reset(); DslModeling::Transaction transaction = this.ModelData.Store.TransactionManager.BeginTransaction("Load model", true); try { modelRoot = global::Tum.FamilyTreeDSL.FamilyTreeDSLSerializationHelper.Instance.LoadModelFamilyTreeModel(result, this.ModelData.GetModelPartition(), fileName, null, null, null); // post process if (modelRoot != null && !serializationResult.Failed) { FamilyTreeDSLSerializationPostProcessor.Instance.DoPostProcess(new System.Collections.Generic.List <string>(), result, modelRoot.Store); } if (!serializationResult.Failed) { // start validation because UseLoad=true ValidateAll(); } // load diagramsModel string diagramsFileName = GetDiagramsFileName(fileName); if (System.IO.File.Exists(diagramsFileName)) { diagramsModel = FamilyTreeDSLDiagramsDSLSerializationHelper.Instance.LoadModel(result, this.ModelData.GetModelPartition(), GetDiagramsFileName(fileName), null, null, null); } if (diagramsModel == null) { diagramsModel = new DslEditorDiagrams::DiagramsModel(this.ModelData.Store); } if (!diagramsModel.ContainsDiagram("DesignerDiagram")) { DesignerDiagram diagramDesignerDiagram = new DesignerDiagram(this.ModelData.Store); diagramDesignerDiagram.Name = "DesignerDiagram"; diagramsModel.Diagrams.Add(diagramDesignerDiagram); } diagramsModel.GetDiagram("DesignerDiagram").Initialize(); OnPropertyChanged("DesignerDiagram"); if (result.Failed) { transaction.Rollback(); } else { transaction.Commit(); } } catch (System.Exception ex) { serializationResult.AddMessage(new DslEditorModeling::SerializationMessage( FamilyTreeDSLValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error, ex.Message, fileName, 0, 0)); transaction.Rollback(); } // copy messages bool bHasMessages = false; foreach (DslModeling::SerializationMessage m in result) { bHasMessages = true; DslEditorModeling.ModelValidationViolationType kind = DslEditorModeling.ModelValidationViolationType.Error; if (m.Kind == DslModeling.SerializationMessageKind.Info) { kind = DslEditorModeling.ModelValidationViolationType.Message; } else if (m.Kind == DslModeling.SerializationMessageKind.Warning) { kind = DslEditorModeling.ModelValidationViolationType.Warning; } DslEditorModeling::SerializationMessage message = new DslEditorModeling.SerializationMessage( FamilyTreeDSLValidationMessageIds.SerializationMessageId, kind, m.Message, m.Location, m.Line, m.Column); serializationResult.AddMessage(message); } serializationResult.Failed = result.Failed; if (serializationResult.Failed) { // Load failed, can't open the file. serializationResult.AddMessage(new DslEditorModeling::SerializationMessage(FamilyTreeDSLValidationMessageIds.SerializationLoadErrorId, DslEditorModeling::ModelValidationViolationType.Error, FamilyTreeDSLDomainModel.SingletonResourceManager.GetString("CannotOpenDocument"), fileName, 0, 0)); } else { this.rootModelElement = modelRoot; } if (!serializationResult.Failed && !bHasMessages) { // start validation because UseOpen=true ValidateAll(); } }