/// <summary> /// Loads the given file. /// </summary> protected void LoadVModell(string fileName, bool isReload) { SerializationResult serializationResult = new SerializationResult(); global::Tum.PDE.LanguageDSL.MetaModel modelRoot = null; ISchemaResolver schemaResolver = new ModelingSchemaResolver(this.ServiceProvider); //clear the current root element this.SetRootElement(null); modelRoot = global::Tum.PDE.LanguageDSL.LanguageDSLSerializationHelper.Instance.LoadModel(serializationResult, this.GetModelPartition(), fileName, schemaResolver, null /* no load-time validation */, this.SerializerLocator, true, true); // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Load failed, can't open the file. throw new global::System.InvalidOperationException(global::Tum.PDE.LanguageDSL.LanguageDSLDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } else { this.SetRootElement(modelRoot); // Attempt to set the encoding if (serializationResult.Encoding != null) { this.ModelingDocStore.SetEncoding(serializationResult.Encoding); global::Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(this.SetDocDataDirty(0)); // Setting the encoding will mark the document as dirty, so clear the dirty flag. } } }
protected override void Load(string fileName, bool reload) { Guard.NotNullOrEmpty(() => fileName, fileName); var serializationResult = new SerializationResult(); PatternModelSchema modelRoot = null; var schemaResolver = new ModelingSchemaResolver(this.ServiceProvider); PatternModelDomainModel.EnableDiagramRules(this.Store); this.Store.RuleManager.DisableRule(typeof(FixUpDiagram)); this.Store.RuleManager.EnableRule(typeof(FixUpMultipleDiagram)); var diagramFileNames = Directory.GetFiles( Path.GetDirectoryName(fileName), string.Concat("*", DesignerConstants.ModelExtension, DesignerConstants.DiagramFileExtension)); // Run migration rules this.ExecuteUpgradeRules(fileName, diagramFileNames); // Load models modelRoot = PatternModelSerializationHelper.Instance.LoadModelAndDiagrams( serializationResult, this.GetModelPartition(), fileName, this.GetDiagramPartition(), diagramFileNames, schemaResolver, null /* no load-time validation */, this.SerializerLocator); this.SuspendErrorListRefresh(); try { foreach (SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { throw new InvalidOperationException(PatternModelDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } else { this.SetRootElement(modelRoot); // Attempt to set the encoding if (serializationResult.Encoding != null) { this.ModelingDocStore.SetEncoding(serializationResult.Encoding); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(this.SetDocDataDirty(0)); // Setting the encoding will mark the document as dirty, so clear the dirty flag. } } this.RehydrateModel(); }