/// <summary> /// Saves the given file. /// </summary> protected override void Save(string fileName) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::Tum.PDE.LanguageDSL.MetaModel modelRoot = (global::Tum.PDE.LanguageDSL.MetaModel) this.RootElement; global::Tum.PDE.LanguageDSL.LanguageDSLSerializationHelper.Instance.SaveModel(serializationResult, modelRoot, fileName, this.Encoding, true); // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Save failed. throw new global::System.InvalidOperationException(global::Tum.PDE.LanguageDSL.LanguageDSLDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } }
private MemoryStream InternalSaveModel2(DslModeling::SerializationResult serializationResult, PatternModelSchema modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue) { #region Check Parameters global::System.Diagnostics.Debug.Assert(serializationResult != null); global::System.Diagnostics.Debug.Assert(modelRoot != null); global::System.Diagnostics.Debug.Assert(!serializationResult.Failed); #endregion serializationResult.Encoding = encoding; DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(modelRoot.Store); global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream(); DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileName, serializationResult); this.InitializeSerializationContext(modelRoot.Partition, serializationContext, false); // MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here. serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue; global::System.Xml.XmlWriterSettings settings = PatternModelSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding); using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings)) { this.WriteRootElement(serializationContext, modelRoot, writer); } return(newFileContent); }
public override void SaveModel(DslModeling::SerializationResult serializationResult, MetaModel modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue) { base.SaveModel(serializationResult, modelRoot, fileName, encoding, writeOptionalPropertiesWithDefaultValue); System.IO.FileInfo info = new System.IO.FileInfo(fileName); string fileNameDiagram = info.DirectoryName + "\\" + info.Name.Remove(info.Name.Length - info.Extension.Length, info.Extension.Length) + DiagramExtension; // save view information using (global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream()) { DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(modelRoot.Store); DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileName, serializationResult); this.InitializeSerializationContext(modelRoot.Partition, serializationContext, false); // MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here. serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue; global::System.Xml.XmlWriterSettings settings = LanguageDSLSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding); using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings)) { ViewSerializer serializer = directory.GetSerializer(View.DomainClassId) as ViewSerializer; serializer.Write(serializationContext, modelRoot.View, writer); } if (!serializationResult.Failed && newFileContent != null) { // Only write the content if there's no error encountered during serialization. using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(fileNameDiagram, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None)) { using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding)) { writer.Write(newFileContent.ToArray()); } } } } }
private global::System.IO.MemoryStream InternalSaveDiagram(DslModeling::SerializationResult serializationResult, DslDiagrams::Diagram diagram, string diagramFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue) { #region Check Parameters global::System.Diagnostics.Debug.Assert(serializationResult != null); global::System.Diagnostics.Debug.Assert(diagram != null); global::System.Diagnostics.Debug.Assert(!serializationResult.Failed); #endregion global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream(); var directory = this.GetDirectory(diagram.Store); DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, diagramFileName, serializationResult); this.InitializeSerializationContext(diagram.Partition, serializationContext, false); // MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here. serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue; global::System.Xml.XmlWriterSettings settings = EFModelSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, true, encoding); var diagramSerializer = GetSerializer(diagram); using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings)) { //this.WriteRootElement(serializationContext, diagram, writer); // Carry out the normal serialization. this.WriteRootElement(serializationContext, diagramSerializer, diagram, writer); } return(newFileContent); }
/// <summary> /// Saves the given file. /// </summary> protected override void Save(string fileName) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::DSLFactory.Candle.SystemModel.CandleModel modelRoot = (global::DSLFactory.Candle.SystemModel.CandleModel) this.RootElement; global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(this.RootElement); if (diagrams.Count > 0) { global::DSLFactory.Candle.SystemModel.ComponentModelDiagram diagram = diagrams[0] as global::DSLFactory.Candle.SystemModel.ComponentModelDiagram; if (diagram != null) { string diagramFileName = fileName + this.DiagramExtension; try { this.SuspendFileChangeNotification(diagramFileName); global::DSLFactory.Candle.SystemModel.CandleSerializationHelper.Instance.SaveModelAndDiagram(serializationResult, modelRoot, fileName, diagram, diagramFileName, this.Encoding, false); if (!serializationResult.Failed) { // fileName != this.FileName is false in the case of Save As. Allow OnFileNameChanged() below to handle this case. if (global::System.StringComparer.OrdinalIgnoreCase.Compare(fileName, this.FileName) == 0 && global::System.IO.File.Exists(diagramFileName)) { DslShell::SubordinateFileHelper.EnsureChildProjectItem(this.Hierarchy, this.ItemId, diagramFileName); } } } finally { this.ResumeFileChangeNotification(diagramFileName); } } } if (!serializationResult.Failed) { global::DSLFactory.Candle.SystemModel.CandleSerializationHelper.Instance.SaveModel(serializationResult, modelRoot, fileName, this.Encoding, false); } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Save failed. throw new global::System.InvalidOperationException(global::DSLFactory.Candle.SystemModel.CandleDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } }
/// <summary> /// Saves the given file. /// </summary> protected override void Save(string fileName) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::UPM_IPS.RAARMAPMCWeberMDD.WebERMDD modelRoot = (global::UPM_IPS.RAARMAPMCWeberMDD.WebERMDD) this.RootElement; // Only save the diagrams if // a) There are any to save // b) This is NOT a SaveAs operation. SaveAs should allow the subordinate document to control the save of its data as it is writing a new file. // Except DO save the diagram on SaveAs if there isn't currently a diagram as there won't be a subordinate document yet to save it. bool saveAs = global::System.StringComparer.OrdinalIgnoreCase.Compare(fileName, this.FileName) != 0; global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(this.RootElement); if (diagrams.Count > 0 && (!saveAs || this.diagramDocumentLockHolder == null)) { global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDDiagram diagram = diagrams[0] as global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDDiagram; if (diagram != null) { string diagramFileName = fileName + this.DiagramExtension; try { this.SuspendFileChangeNotification(diagramFileName); global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDSerializationHelper.Instance.SaveModelAndDiagram(serializationResult, modelRoot, fileName, diagram, diagramFileName, this.Encoding, false); } finally { this.ResumeFileChangeNotification(diagramFileName); } } } else { global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDSerializationHelper.Instance.SaveModel(serializationResult, modelRoot, fileName, this.Encoding, false); } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Save failed. throw new global::System.InvalidOperationException(global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } }
public virtual ModelRoot LoadModelAndDiagrams(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramsPartition, string diagramsFileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator) { #region Check Parameters if (serializationResult == null) { throw new global::System.ArgumentNullException("serializationResult"); } if (modelPartition == null) { throw new global::System.ArgumentNullException("modelPartition"); } if (diagramsPartition == null) { throw new global::System.ArgumentNullException("diagramsPartition"); } if (string.IsNullOrEmpty(diagramsFileName)) { throw new global::System.ArgumentNullException("diagramsFileName"); } #endregion ModelRoot modelRoot; // Ensure there is an outer transaction spanning both model and diagram load, so moniker resolution works properly. if (!diagramsPartition.Store.TransactionActive) { throw new global::System.InvalidOperationException(EFModelDomainModel.SingletonResourceManager.GetString("MissingTransaction")); } modelRoot = this.LoadModel(serializationResult, modelPartition, modelFileName, schemaResolver, validationController, serializerLocator); if (serializationResult.Failed) { // don't try to deserialize diagram data if model load failed. return(modelRoot); } if (IsValid(diagramsFileName)) { using (var pkgOutputDoc = global::System.IO.Packaging.Package.Open(diagramsFileName, global::System.IO.FileMode.Open, global::System.IO.FileAccess.Read)) { foreach (var packagePart in pkgOutputDoc.GetParts()) { this.LoadDiagram(serializationResult, modelPartition, modelFileName, diagramsFileName, modelRoot, diagramsPartition, packagePart.GetStream(global::System.IO.FileMode.Open, global::System.IO.FileAccess.Read), schemaResolver, validationController, serializerLocator); } } } else { // missing diagram file indicates we should create a new diagram. this.LoadDiagram(serializationResult, modelPartition, modelFileName, diagramsFileName, modelRoot, diagramsPartition, global::System.IO.Stream.Null, schemaResolver, validationController, serializerLocator); } return(modelRoot); }
/// <summary> /// Save the given document that is subordinate to this document. /// </summary> /// <param name="subordinateDocument"></param> /// <param name="fileName"></param> protected override void SaveSubordinateFile(DslShell::DocData subordinateDocument, string fileName) { // In this case, the only subordinate is the diagram. DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(this.RootElement); if (diagrams.Count > 0) { global::pelsoft.FWK_Dsl.ClassDiagram diagram = diagrams[0] as global::pelsoft.FWK_Dsl.ClassDiagram; if (diagram != null) { try { this.SuspendFileChangeNotification(fileName); global::pelsoft.FWK_Dsl.FWK_DslSerializationHelper.Instance.SaveDiagram(serializationResult, diagram, fileName, this.Encoding, false); } finally { this.ResumeFileChangeNotification(fileName); } } } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (!serializationResult.Failed) { // Notify the Running Document Table that the subordinate has been saved if (this.ServiceProvider != null) { VSShellInterop::IVsRunningDocumentTable rdt = (VSShellInterop.IVsRunningDocumentTable) this.ServiceProvider.GetService(typeof(VSShellInterop::IVsRunningDocumentTable)); if (rdt != null && this.diagramDocumentLockHolder != null && this.diagramDocumentLockHolder.SubordinateDocData != null) { global::Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(rdt.NotifyOnAfterSave(this.diagramDocumentLockHolder.SubordinateDocData.Cookie)); } } } else { // Save failed. throw new global::System.InvalidOperationException(global::pelsoft.FWK_Dsl.FWK_DslDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } }
/// <summary> /// Loads the given file. /// </summary> protected override void Load(string fileName, bool isReload) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::pelsoft.FWK_Dsl.ModelRoot modelRoot = null; DslModeling::ISchemaResolver schemaResolver = new DslShell::ModelingSchemaResolver(this.ServiceProvider); // Enable diagram fixup rules in our store, because we will load diagram data. global::pelsoft.FWK_Dsl.FWK_DslDomainModel.EnableDiagramRules(this.Store); string diagramFileName = fileName + this.DiagramExtension; modelRoot = global::pelsoft.FWK_Dsl.FWK_DslSerializationHelper.Instance.LoadModelAndDiagram(serializationResult, this.Store, fileName, diagramFileName, schemaResolver, null /* no load-time validation */); // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Load failed, can't open the file. throw new global::System.InvalidOperationException(global::pelsoft.FWK_Dsl.FWK_DslDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } else { this.SetRootElement(modelRoot); if (this.Hierarchy != null && global::System.IO.File.Exists(diagramFileName)) { // Add a lock to the subordinate diagram file. if (this.diagramDocumentLockHolder == null) { uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, this.DiagramExtension); if (itemId != global::Microsoft.VisualStudio.VSConstants.VSITEMID_NIL) { this.diagramDocumentLockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument(this.ServiceProvider, this, diagramFileName, itemId); if (this.diagramDocumentLockHolder == null) { throw new global::System.InvalidOperationException(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, global::pelsoft.FWK_Dsl.FWK_DslDomainModel.SingletonResourceManager.GetString("CannotCloseExistingDiagramDocument"), diagramFileName)); } } } } } }
/// <summary> /// Saves the given file. /// </summary> protected override void Save(string fileName) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::Sawczyn.EFDesigner.EFModel.ModelRoot modelRoot = (global::Sawczyn.EFDesigner.EFModel.ModelRoot) this.RootElement; // Only save the diagrams if // a) There are any to save // b) This is NOT a SaveAs operation. SaveAs should allow the subordinate document to control the save of its data as it is writing a new file. // Except DO save the diagram on SaveAs if there isn't currently a diagram as there won't be a subordinate document yet to save it. bool saveAs = global::System.StringComparer.OrdinalIgnoreCase.Compare(fileName, this.FileName) != 0; var diagrams = this.GetDiagrams().ToArray(); if (diagrams.Length > 0 && (!saveAs || this.diagramDocumentLockHolder == null)) { string diagramFileName = fileName + this.DiagramExtension; try { this.SuspendFileChangeNotification(diagramFileName); global::Sawczyn.EFDesigner.EFModel.EFModelSerializationHelper.Instance.SaveModelAndDiagrams(serializationResult, modelRoot, fileName, diagrams, diagramFileName, this.Encoding, false); } finally { this.ResumeFileChangeNotification(diagramFileName); } } else { global::Sawczyn.EFDesigner.EFModel.EFModelSerializationHelper.Instance.SaveModel(serializationResult, modelRoot, fileName, this.Encoding, false); } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Save failed. throw new global::System.InvalidOperationException(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } CleanupOldDiagramFiles(); }
/// <summary> /// Loads a MetaModel instance into the default partition of the given store. /// </summary> /// <param name="serializationResult">Stores serialization result from the load operation.</param> /// <param name="store">The new MetaModel instance will be created into the default partition of this store.</param> /// <param name="fileName">Name of the file from which the MetaModel instance will be deserialized.</param> /// <param name="schemaResolver"> /// An ISchemaResolver that allows the serializer to do schema validation on the root element (and everything inside it). /// If null is passed, schema validation will not be performed. /// </param> /// <param name="validationController"> /// A ValidationController that will be used to do load-time validation (validations with validation category "Load"). If null /// is passed, load-time validation will not be performed. /// </param> /// <param name="serializerLocator"> /// An ISerializerLocator that will be used to locate any additional domain model types required to load the model. Can be null. /// </param> /// <returns>The loaded MetaModel instance.</returns> public virtual global::Tum.FamilyTreeDSL.FamilyTreeModel LoadModel(DslModeling::SerializationResult serializationResult, DslModeling::Store store, string fileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator) { #region Check Parameters if (store == null) { throw new global::System.ArgumentNullException("store"); } #endregion return(this.LoadModelFamilyTreeModel(serializationResult, store.DefaultPartition, fileName, schemaResolver, validationController, serializerLocator)); }
public virtual ModelRoot LoadModelAndDiagrams(DslModeling::SerializationResult serializationResult, DslModeling::Store store, string modelFileName, string diagramsFileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator) { #region Check Parameters if (store == null) { throw new global::System.ArgumentNullException("store"); } #endregion DslModeling::Partition diagramsPartition = new DslModeling::Partition(store); return(this.LoadModelAndDiagrams(serializationResult, store.DefaultPartition, modelFileName, diagramsPartition, diagramsFileName, schemaResolver, validationController, serializerLocator)); }
/// <summary> /// Saves the diagram. /// </summary> /// <typeparam name="TModel">The type of the model.</typeparam> /// <param name="serializationResult">The serialization result.</param> /// <param name="modelRoot">The model root.</param> /// <param name="modelFileName">Name of the model file.</param> /// <param name="diagram">The diagram.</param> /// <param name="diagramFileName">Name of the diagram file.</param> /// <param name="encoding">The encoding.</param> /// <param name="writeOptionalPropertiesWithDefaultValue">if set to <c>true</c> [write optional properties with default value].</param> public void SaveDiagram <TModel>(DslModeling::SerializationResult serializationResult, TModel modelRoot, string modelFileName, ComponentModelDiagram diagram, string diagramFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue) where TModel : ModelElement { if (serializationResult.Failed) { return; } // MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here. using (global::System.IO.MemoryStream diagramFileContent = new global::System.IO.MemoryStream()) { DslModeling::DomainClassXmlSerializer diagramSerializer = this.Directory.GetSerializer(diagram.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for " + diagram.GetDomainClass().Name + "!"); if (diagramSerializer != null) { DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, diagramFileName, serializationResult); serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue; global::System.Xml.XmlWriterSettings settings = new global::System.Xml.XmlWriterSettings(); settings.Indent = true; settings.Encoding = encoding; using (global::System.IO.StreamWriter streamWriter = new global::System.IO.StreamWriter(diagramFileContent, encoding)) { using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(streamWriter, settings)) { diagramSerializer.WriteRootElement(serializationContext, diagram, writer); } } } if (!serializationResult.Failed) { // Only write the contents if there's no error encountered during serialization. if (diagramFileContent != null) { IVsQueryEditQuerySave2 scc = ServiceLocator.Instance.GetService <IVsQueryEditQuerySave2>(typeof(SVsQueryEditQuerySave)); if (scc != null) { uint result; if (scc.QuerySaveFile(diagramFileName, 0, null, out result) != (int)tagVSQuerySaveResult.QSR_SaveOK) { return; } } using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(diagramFileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None)) { using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding)) { writer.Write(diagramFileContent.ToArray()); } } } } } }
/// <summary> /// Save the given document that is subordinate to this document. /// </summary> /// <param name="subordinateDocument"></param> /// <param name="fileName"></param> protected override void SaveSubordinateFile(DslShell::DocData subordinateDocument, string fileName) { // In this case, the only subordinate is the diagram. DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(this.RootElement); if (diagrams.Count > 0) { global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDDiagram diagram = diagrams[0] as global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDDiagram; if (diagram != null) { try { this.SuspendFileChangeNotification(fileName); global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDSerializationHelper.Instance.SaveDiagram(serializationResult, diagram, fileName, this.Encoding, false); } finally { this.ResumeFileChangeNotification(fileName); } } } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (!serializationResult.Failed) { this.NotifySubordinateDocumentSaved(subordinateDocument.FileName, fileName); } else { // Save failed. throw new global::System.InvalidOperationException(global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } }
/// <summary> /// Save the given document that is subordinate to this document. /// </summary> /// <param name="subordinateDocument"></param> /// <param name="fileName"></param> protected override void SaveSubordinateFile(DslShell::DocData subordinateDocument, string fileName) { // In this case, the only subordinate is the diagram. DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); var diagrams = this.GetDiagrams().ToArray(); if (diagrams.Length > 0) { try { this.SuspendFileChangeNotification(fileName); global::Sawczyn.EFDesigner.EFModel.EFModelSerializationHelper.Instance.SaveDiagrams(serializationResult, diagrams, fileName, this.Encoding, false); } finally { this.ResumeFileChangeNotification(fileName); } } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (!serializationResult.Failed) { this.NotifySubordinateDocumentSaved(subordinateDocument.FileName, fileName); } else { // Save failed. throw new global::System.InvalidOperationException(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } CleanupOldDiagramFiles(); }
/// <summary> /// Loads the given file. /// </summary> protected override void Load(string fileName, bool isReload) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::Tum.PDE.LanguageDSL.MetaModel modelRoot = null; DslModeling::ISchemaResolver schemaResolver = new DslShell::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); // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::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. } } }
internal virtual void SaveDiagrams(DslModeling::SerializationResult serializationResult, DslDiagrams::Diagram[] diagrams, string diagramsFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue) { #region Check Parameters if (serializationResult == null) { throw new global::System.ArgumentNullException("serializationResult"); } if (diagrams == null) { throw new global::System.ArgumentNullException("diagrams"); } if (string.IsNullOrEmpty(diagramsFileName)) { throw new global::System.ArgumentNullException("diagramsFileName"); } #endregion if (serializationResult.Failed) { return; } var memoryStreamDictionary = new Dictionary <global::System.IO.MemoryStream, string>(); foreach (var diagram in diagrams) { // HACK : Add validation rule on Diagram Name (!string.IsNullOrEmpty && Unique ) if (string.IsNullOrEmpty(diagram.Name)) { throw new ArgumentException("Each diagram must have a name", "diagrams"); } memoryStreamDictionary.Add(this.InternalSaveDiagram(serializationResult, diagram, diagramsFileName, encoding, writeOptionalPropertiesWithDefaultValue), diagram.Name); if (serializationResult.Failed) { memoryStreamDictionary.Keys.ToList <global::System.IO.MemoryStream>().ForEach(memoryStream => memoryStream.Close()); return; } } WriteDiagramFile(diagramsFileName, memoryStreamDictionary); }
public override nHydrateModel LoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramPartition, string diagramFileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator) { var modelRoot = base.LoadModelAndDiagram(serializationResult, modelPartition, modelFileName, diagramPartition, diagramFileName, schemaResolver, validationController, serializerLocator); _model = modelRoot; //Verify that we can open the model var thisAssem = System.Reflection.Assembly.GetExecutingAssembly(); var thisAssemName = thisAssem.GetName(); var toolVersion = thisAssemName.Version; var modelVersion = new Version(0, 0); var dslVersion = new Version(0, 0); if (!string.IsNullOrEmpty(modelRoot.ModelVersion)) { modelVersion = new Version(modelRoot.ModelVersion); } if (toolVersion < modelVersion) { throw new Exception("This model was created with newer version of the modeler. Please install version '" + modelVersion.ToString() + "' or higher."); } try { var document = new XmlDocument(); document.LoadXml(File.ReadAllText(modelFileName)); var attr = document.DocumentElement.Attributes["dslVersion"]; if (attr != null) { dslVersion = new Version(attr.Value); } } catch { } //When saved the new version will be this tool version modelRoot.ModelVersion = LAST_MODEL_MODEL_COMPATIBLE; modelRoot.ModelFileName = modelFileName; modelRoot.IsDirty = false; var mainInfo = new FileInfo(modelFileName); nHydrate.Dsl.Custom.SQLFileManagement.LoadFromDisk(modelRoot, mainInfo.DirectoryName, modelRoot.Partition.Store, mainInfo.Name); modelRoot.IsDirty = false; #region Load Indexes //For now load the indexes into the REAL indexes collection //This should only happens the first time using (var transaction = modelRoot.Store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString())) { LoadInitialIndexes(modelRoot); transaction.Commit(); } #endregion return(modelRoot); }
public override nHydrateModel LoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramPartition, string diagramFileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator) { var modelRoot = base.LoadModelAndDiagram(serializationResult, modelPartition, modelFileName, diagramPartition, diagramFileName, schemaResolver, validationController, serializerLocator); _model = modelRoot; //Verify that we can open the model var thisAssem = System.Reflection.Assembly.GetExecutingAssembly(); var thisAssemName = thisAssem.GetName(); var toolVersion = thisAssemName.Version; var modelVersion = new Version(0, 0); var dslVersion = new Version(0, 0); if (!string.IsNullOrEmpty(modelRoot.ModelVersion)) { modelVersion = new Version(modelRoot.ModelVersion); } if (toolVersion < modelVersion) { throw new Exception("This model was created with newer version of the modeler. Please install version '" + modelVersion.ToString() + "' or higher."); } try { var document = new XmlDocument(); document.LoadXml(File.ReadAllText(modelFileName)); var attr = document.DocumentElement.Attributes["dslVersion"]; if (attr != null) { dslVersion = new Version(attr.Value); } } catch { } //When saved the new version will be this tool version modelRoot.ModelVersion = LAST_MODEL_MODEL_COMPATIBLE; modelRoot.ModelFileName = modelFileName; modelRoot.IsDirty = false; var mainInfo = new FileInfo(modelFileName); var modelName = mainInfo.Name.Replace(".nhydrate", ".model"); if (modelRoot.ModelToDisk) { //Load from disk store nHydrate.Dsl.Custom.SQLFileManagement.LoadFromDisk(modelRoot, mainInfo.DirectoryName, modelRoot.Partition.Store, modelName); #region Watch Folder //var modelFolder = nHydrate.Dsl.Custom.SQLFileManagement.GetModelFolder(mainInfo.DirectoryName, modelName); //_watchFolder.Path = modelFolder; //_watchFolder.IncludeSubdirectories = true; //_watchFolder.NotifyFilter = System.IO.NotifyFilters.FileName | // NotifyFilters.LastWrite | // NotifyFilters.Size | // NotifyFilters.CreationTime | // NotifyFilters.DirectoryName; //_watchFolder.Changed += new FileSystemEventHandler(FolderChangedEvent); //_watchFolder.Created += new FileSystemEventHandler(FolderChangedEvent); //_watchFolder.Deleted += new FileSystemEventHandler(FolderChangedEvent); //_watchFolder.Renamed += new System.IO.RenamedEventHandler(FolderFileRenamedEvent); //try //{ // _watchFolder.EnableRaisingEvents = true; //} //catch (ArgumentException) //{ // //Do Nothing //} #endregion } else { try { var f = nHydrate.Dsl.Custom.SQLFileManagement.GetModelFolder(mainInfo.DirectoryName, modelName); if (Directory.Exists(f)) { Directory.Delete(f, true); } } catch { } } modelRoot.IsDirty = false; //SyncServer //var syncServerFile = modelFileName + ".syncserver"; //modelRoot.SyncServerURL = nHydrate.SyncServer.Client.SyncDomain.LoadSyncServerConfig(syncServerFile); //Alphabetized columns if need be //foreach (var entity in modelRoot.Entities) //{ // entity.Fields.Sort((x, y) => x.Name.CompareTo(y.Name)); //} #region Load Indexes //For now load the indexes into the REAL indexes collection //This should only happens the first time using (var transaction = modelRoot.Store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString())) { LoadInitialIndexes(modelRoot); transaction.Commit(); } #endregion #region Handle the Precedence if (modelRoot.StoredProcedures.Count > 0) { modelRoot.MaxPrecedenceOrder = Math.Max(modelRoot.StoredProcedures.Max(x => x.PrecedenceOrder), modelRoot.MaxPrecedenceOrder); } if (modelRoot.Views.Count > 0) { modelRoot.MaxPrecedenceOrder = Math.Max(modelRoot.Views.Max(x => x.PrecedenceOrder), modelRoot.MaxPrecedenceOrder); } if (modelRoot.Functions.Count > 0) { modelRoot.MaxPrecedenceOrder = Math.Max(modelRoot.Functions.Max(x => x.PrecedenceOrder), modelRoot.MaxPrecedenceOrder); } modelRoot.StoredProcedures.Where(x => x.PrecedenceOrder == 0).ToList().ForEach(x => x.PrecedenceOrder = ++modelRoot.MaxPrecedenceOrder); modelRoot.Views.Where(x => x.PrecedenceOrder == 0).ToList().ForEach(x => x.PrecedenceOrder = ++modelRoot.MaxPrecedenceOrder); modelRoot.Functions.Where(x => x.PrecedenceOrder == 0).ToList().ForEach(x => x.PrecedenceOrder = ++modelRoot.MaxPrecedenceOrder); #endregion #region Load the refactorizations if (File.Exists(modelFileName)) { var fi = new FileInfo(modelFileName); if (fi.Length > 5) { var document = new XmlDocument(); document.Load(modelFileName); if (document.DocumentElement != null) { var refactorList = document.DocumentElement.SelectSingleNode("refactorizations"); if (refactorList != null) { foreach (XmlNode n in refactorList.ChildNodes) { //if (XmlHelper.GetAttributeValue(n, "type", string.Empty) == "guidtoid") //{ // modelRoot.Refactorizations.Add(new RefactorChangeGuidToID((XmlElement)n)); //} //else if (XmlHelper.GetAttributeValue(n, "type", string.Empty) == "guidtoididtoguid") //{ // modelRoot.Refactorizations.Add(new RefactorChangeIDToGuid((XmlElement)n)); //} if (XmlHelper.GetAttributeValue(n, "type", string.Empty) == "splittable") { modelRoot.Refactorizations.Add(new RefactorTableSplit((XmlElement)n)); } else if (XmlHelper.GetAttributeValue(n, "type", string.Empty) == "combinetable") { modelRoot.Refactorizations.Add(new RefactorTableCombine((XmlElement)n)); } } } } } } #endregion //If using modules from a previous model version then perform this one time action of //assigning the indexes to all modules so user will not be confronted with a a huge action to perform after upgrade if (dslVersion <= new Version(5, 1, 2, 118) && modelRoot.UseModules) { using (var transaction = modelRoot.Store.TransactionManager.BeginTransaction(Guid.NewGuid().ToString())) { foreach (var module in modelRoot.Modules) { var contained = module.GetEntities().ToList(); foreach (var index in modelRoot.Entities.Where(x => contained.Contains(x)).SelectMany(x => x.IndexList)) { _model.IndexModules.Add(new IndexModule(_model.Partition) { IndexID = index.Id, ModuleId = module.Id }); } } transaction.Commit(); } } return(modelRoot); }
public virtual ModelRoot LoadModelAndDiagrams(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramsPartition, string diagramsFileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator) { #region Check Parameters if (serializationResult == null) { throw new global::System.ArgumentNullException("serializationResult"); } if (modelPartition == null) { throw new global::System.ArgumentNullException("modelPartition"); } if (diagramsPartition == null) { throw new global::System.ArgumentNullException("diagramsPartition"); } if (string.IsNullOrEmpty(diagramsFileName)) { throw new global::System.ArgumentNullException("diagramsFileName"); } #endregion ModelRoot modelRoot; // Ensure there is an outer transaction spanning both model and diagram load, so moniker resolution works properly. if (!diagramsPartition.Store.TransactionActive) { throw new global::System.InvalidOperationException(EFModelDomainModel.SingletonResourceManager.GetString("MissingTransaction")); } modelRoot = this.LoadModel(serializationResult, modelPartition, modelFileName, schemaResolver, validationController, serializerLocator); ModelDiagramData data = null; if (serializationResult.Failed) { // don't try to deserialize diagram data if model load failed. return(modelRoot); } if (IsValid(diagramsFileName)) { using (var pkgOutputDoc = global::System.IO.Packaging.Package.Open(diagramsFileName, global::System.IO.FileMode.Open, global::System.IO.FileAccess.Read)) { foreach (var packagePart in pkgOutputDoc.GetParts()) { EFModelDiagram diagram = this.LoadDiagram(serializationResult , modelPartition , modelFileName , diagramsFileName , modelRoot , diagramsPartition , packagePart.GetStream(global::System.IO.FileMode.Open, global::System.IO.FileAccess.Read) , schemaResolver , validationController , serializerLocator) as EFModelDiagram; if (diagram != null) { data = FixupDiagramData(diagram); } if (diagram.Name == Path.GetFileNameWithoutExtension(diagramsFileName).Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries).First()) { data.SetLocks(Locks.All); } } } } else { // missing diagram file indicates we should create a new diagram. EFModelDiagram diagram = this.LoadDiagram(serializationResult , modelPartition , modelFileName , diagramsFileName , modelRoot , diagramsPartition , global::System.IO.Stream.Null , schemaResolver , validationController , serializerLocator) as EFModelDiagram; if (diagram != null) { data = FixupDiagramData(diagram); } if (diagram.Name == Path.GetFileNameWithoutExtension(diagramsFileName)) { data.SetLocks(Locks.All); } } modelRoot.Store .GetAll <ModelDiagramData>() .Where(d => d.GetDiagram() == null) .ToList() .ForEach(d => modelRoot.Diagrams.Remove(d)); return(modelRoot); ModelDiagramData FixupDiagramData(EFModelDiagram diagram) { ModelDiagramData diagramData = modelRoot.Store .GetAll <ModelDiagramData>() .FirstOrDefault(d => d.Name == diagram.Name); if (diagramData == null) { modelRoot.Diagrams.Add(diagramData = new ModelDiagramData(modelRoot.Store.DefaultPartition , new DslModeling.PropertyAssignment(ModelDiagramData.NameDomainPropertyId, diagram.Name))); } diagramData.SetDiagram(diagram); return(diagramData); } }
/// <summary> /// Constructor /// </summary> internal SerializationValidationObserver(DslModeling::SerializationResult serializationResult, DslValidation::ValidationController validationController) { #region Check Parameters global::System.Diagnostics.Debug.Assert(serializationResult != null); global::System.Diagnostics.Debug.Assert(validationController != null); #endregion this.serializationResult = serializationResult; this.validationController = validationController; // Subscribe to validation messages. this.validationController.AddObserver(this); }
/// <summary> /// Return the model in XML format /// </summary> /// <param name="modelRoot">Root instance to be saved.</param> /// <param name="encoding">Encoding to use when saving the root instance.</param> /// <returns>Model in XML form</returns> public virtual string GetSerializedModelString(global::Microsoft.Practices.ServiceFactory.HostDesigner.HostDesignerModel modelRoot, global::System.Text.Encoding encoding) { string result = string.Empty; if (modelRoot == null) { return result; } DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); using (global::System.IO.MemoryStream modelFileContent = this.InternalSaveModel(serializationResult, modelRoot, string.Empty, encoding, false)) { if (!serializationResult.Failed && modelFileContent != null) { char[] chars = encoding.GetChars(modelFileContent.GetBuffer()); // search the open angle bracket and trim off the Byte Of Mark. result = new string( chars); int indexPos = result.IndexOf('<'); if (indexPos > 0) { // strip off the leading Byte Of Mark. result = result.Substring(indexPos); } // trim off trailing 0s. result = result.TrimEnd( '\0'); } } return result; }
/// <summary> /// Loads the given file. /// </summary> protected override void Load(string fileName, bool isReload) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::Microsoft.Practices.ServiceFactory.DataContracts.DataContractModel modelRoot = null; DslModeling::ISchemaResolver schemaResolver = new DslShell::ModelingSchemaResolver(this.ServiceProvider); //clear the current root element this.SetRootElement(null); // Enable diagram fixup rules in our store, because we will load diagram data. global::Microsoft.Practices.ServiceFactory.DataContracts.DataContractDslDomainModel.EnableDiagramRules(this.Store); string diagramFileName = fileName + this.DiagramExtension; modelRoot = global::Microsoft.Practices.ServiceFactory.DataContracts.DataContractDslSerializationHelper.Instance.LoadModelAndDiagram(serializationResult, this.GetModelPartition(), fileName, this.GetDiagramPartition(), diagramFileName, schemaResolver, null /* no load-time validation */, this.SerializerLocator); // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Load failed, can't open the file. throw new global::System.InvalidOperationException(global::Microsoft.Practices.ServiceFactory.DataContracts.DataContractDslDomainModel.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. } if (this.Hierarchy != null && global::System.IO.File.Exists(diagramFileName)) { // Add a lock to the subordinate diagram file. if (this.diagramDocumentLockHolder == null) { uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, this.DiagramExtension); if (itemId != global::Microsoft.VisualStudio.VSConstants.VSITEMID_NIL) { this.diagramDocumentLockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument(this.ServiceProvider, this, diagramFileName, itemId); if (this.diagramDocumentLockHolder == null) { throw new global::System.InvalidOperationException(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, global::Microsoft.Practices.ServiceFactory.DataContracts.DataContractDslDomainModel.SingletonResourceManager.GetString("CannotCloseExistingDiagramDocument"), diagramFileName)); } } } } } }
private void LoadDiagram <TModel, TDiagram>(string fileName, string diagramExtension, System.Guid diagramDomainId, CreateDiagramHandler callback) where TModel : Microsoft.VisualStudio.Modeling.ModelElement where TDiagram : ComponentModelDiagram { ReadOnlyCollection <TModel> modelsLayerList = this.Store.ElementDirectory.FindElements <TModel>(); if (modelsLayerList.Count == 0) { return; } DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); DslModeling::ISchemaResolver schemaResolver = new DslShell::ModelingSchemaResolver(this.ServiceProvider); // Enable diagram fixup rules in our store, because we will load diagram data. global::DSLFactory.Candle.SystemModel.CandleDomainModel.EnableDiagramRules(this.Store); string diagramFileName = fileName + diagramExtension; // Ensure that subordinate diagram file is named properly; handles the case where a rename occurs while the designer was closed. if (this.Hierarchy != null) { uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, DataLayerDiagramExtension); if (itemId != global::Microsoft.VisualStudio.VSConstants.VSITEMID_NIL) { DslShell::SubordinateFileHelper.EnsureChildFileName(this.ServiceProvider, this.Hierarchy, itemId, diagramFileName); // Found the diagram file, lock it in the running documents table. //this.diagramDocument2LockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument( this.ServiceProvider, this, diagramFileName, itemId ); //if( this.diagramDocument2LockHolder == null ) //{ // throw new global::System.InvalidOperationException( global::DSLFactory.Candle.SystemModel.SystemModelDomainModel.SingletonResourceManager.GetString( "CannotOpenDocument" ) ); //} } } try { global::DSLFactory.Candle.SystemModel.CandleSerializationHelper.Instance.LoadDiagram <TModel, TDiagram>(serializationResult, modelsLayerList[0], diagramFileName, schemaResolver, diagramDomainId, callback); } catch { ServiceLocator.Instance.IDEHelper.ShowMessage(String.Concat("Error when opening diagram file ", diagramFileName)); } finally { //if( this.diagramDocument2LockHolder != null && (serializationResult.Failed ) ) //{ // // Load failed, release the document lock if we added one above. // this.diagramDocument2LockHolder.UnregisterSubordinateDocument(); // this.diagramDocument2LockHolder = null; //} } // Report serialization messages. this.SuspendErrorListRefresh(); try { // Report serialization messages. foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Load failed, can't open the file. throw new global::System.InvalidOperationException(global::DSLFactory.Candle.SystemModel.CandleDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } else { if (this.Hierarchy != null && global::System.IO.File.Exists(diagramFileName)) { DslShell::SubordinateFileHelper.EnsureChildProjectItem(this.Hierarchy, this.ItemId, diagramFileName); } } }
/// <summary> /// Save the given document that is subordinate to this document. /// </summary> /// <param name="subordinateDocument"></param> /// <param name="fileName"></param> protected override void SaveSubordinateFile(DslShell::DocData subordinateDocument, string fileName) { // In this case, the only subordinate is the diagram. DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::System.Collections.Generic.IList<DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(this.RootElement); if (diagrams.Count > 0) { global::LinqToRdf.Design.ClassDiagram diagram = diagrams[0] as global::LinqToRdf.Design.ClassDiagram; if (diagram != null) { try { this.SuspendFileChangeNotification(fileName); global::LinqToRdf.Design.LinqToRdfSerializationHelper.Instance.SaveDiagram(serializationResult, diagram, fileName, this.Encoding, false); } finally { this.ResumeFileChangeNotification(fileName); } } } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (!serializationResult.Failed) { // Notify the Running Document Table that the subordinate has been saved if (this.ServiceProvider != null) { VSShellInterop::IVsRunningDocumentTable rdt = (VSShellInterop.IVsRunningDocumentTable)this.ServiceProvider.GetService(typeof(VSShellInterop::IVsRunningDocumentTable)); if (rdt != null && this.diagramDocumentLockHolder != null && this.diagramDocumentLockHolder.SubordinateDocData != null) { global::Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(rdt.NotifyOnAfterSave(this.diagramDocumentLockHolder.SubordinateDocData.Cookie)); } } } else { // Save failed. throw new global::System.InvalidOperationException(global::LinqToRdf.Design.LinqToRdfDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } }
public virtual void SaveModelAndDiagrams(DslModeling::SerializationResult serializationResult, ModelRoot modelRoot, string modelFileName, DslDiagrams::Diagram[] diagrams, string diagramsFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue) { #region Check Parameters if (serializationResult == null) { throw new global::System.ArgumentNullException("serializationResult"); } if (string.IsNullOrEmpty(modelFileName)) { throw new global::System.ArgumentNullException("modelFileName"); } if (diagrams == null) { throw new global::System.ArgumentNullException("diagrams"); } if (string.IsNullOrEmpty(diagramsFileName)) { throw new global::System.ArgumentNullException("diagramsFileName"); } #endregion if (serializationResult.Failed) { return; } // Save the model file first var modelFileContent = this.InternalSaveModel(serializationResult, modelRoot, modelFileName, encoding, writeOptionalPropertiesWithDefaultValue); if (serializationResult.Failed) { modelFileContent.Close(); return; } var memoryStreamDictionary = new Dictionary <global::System.IO.MemoryStream, string>(); foreach (var diagram in diagrams) { if (string.IsNullOrEmpty(diagram.Name)) { throw new ArgumentException("Each diagram must have a name", "diagrams"); } memoryStreamDictionary.Add(this.InternalSaveDiagram(serializationResult, diagram, diagramsFileName, encoding, writeOptionalPropertiesWithDefaultValue), diagram.Name); if (serializationResult.Failed) { modelFileContent.Close(); memoryStreamDictionary.Keys.ToList <global::System.IO.MemoryStream>().ForEach(memoryStream => memoryStream.Close()); return; } } // Only write the contents if there's no error encountered during serialization. if (modelFileContent != null) { using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(modelFileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None)) { using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding)) { writer.Write(modelFileContent.ToArray()); } } } WriteDiagramFile(diagramsFileName, memoryStreamDictionary); }
public virtual void SaveModelAndDiagrams(DslModeling::SerializationResult serializationResult, ModelRoot modelRoot, string modelFileName, DslDiagrams::Diagram[] diagrams, string diagramsFileName, bool writeOptionalPropertiesWithDefaultValue) { this.SaveModelAndDiagrams(serializationResult, modelRoot, modelFileName, diagrams, diagramsFileName, global::System.Text.Encoding.UTF8, writeOptionalPropertiesWithDefaultValue); }
public virtual void SaveModelAndDiagrams(DslModeling::SerializationResult serializationResult, ModelRoot modelRoot, string modelFileName, DslDiagrams::Diagram[] diagrams, string diagramsFileName) { this.SaveModelAndDiagrams(serializationResult, modelRoot, modelFileName, diagrams, diagramsFileName, global::System.Text.Encoding.UTF8, false); }
/// <summary> /// Saves the given file. /// </summary> protected override void Save(string fileName) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::Tum.PDE.LanguageDSL.MetaModel modelRoot = (global::Tum.PDE.LanguageDSL.MetaModel)this.RootElement; global::Tum.PDE.LanguageDSL.LanguageDSLSerializationHelper.Instance.SaveModel(serializationResult, modelRoot, fileName, this.Encoding, true); // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Save failed. throw new global::System.InvalidOperationException(global::Tum.PDE.LanguageDSL.LanguageDSLDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } }
private void OnPostLoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramPartition, string diagramFileName, nHydrateModel modelRoot, nHydrateDiagram diagram) { }
/// <summary> /// Loads the given file. /// </summary> protected override void Load(string fileName, bool isReload) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::UPM_IPS.RAARMAPMCWeberMDD.WebERMDD modelRoot = null; DslModeling::ISchemaResolver schemaResolver = new DslShell::ModelingSchemaResolver(this.ServiceProvider); //clear the current root element this.SetRootElement(null); // Enable diagram fixup rules in our store, because we will load diagram data. global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDDomainModel.EnableDiagramRules(this.Store); string diagramFileName = fileName + this.DiagramExtension; modelRoot = global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDSerializationHelper.Instance.LoadModelAndDiagram(serializationResult, this.GetModelPartition(), fileName, this.GetDiagramPartition(), diagramFileName, schemaResolver, null /* no load-time validation */, this.SerializerLocator); // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Load failed, can't open the file. throw new global::System.InvalidOperationException(global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDDomainModel.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. } if (this.Hierarchy != null && global::System.IO.File.Exists(diagramFileName)) { // Add a lock to the subordinate diagram file. if (this.diagramDocumentLockHolder == null) { uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, this.DiagramExtension); if (itemId != global::Microsoft.VisualStudio.VSConstants.VSITEMID_NIL) { this.diagramDocumentLockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument(this.ServiceProvider, this, diagramFileName, itemId); if (this.diagramDocumentLockHolder == null) { throw new global::System.InvalidOperationException(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, global::UPM_IPS.RAARMAPMCWeberMDD.RAARMAPMCWeberMDDDomainModel.SingletonResourceManager.GetString("CannotCloseExistingDiagramDocument"), diagramFileName)); } } } } } }
/// <summary> /// Save the given document that is subordinate to this document. /// </summary> /// <param name="subordinateDocument"></param> /// <param name="fileName"></param> protected override void SaveSubordinateFile(DslShell::DocData subordinateDocument, string fileName) { // In this case, the only subordinate is the diagram. DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::System.Collections.Generic.IList<DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(this.RootElement); if (diagrams.Count > 0) { global::Microsoft.Practices.ServiceFactory.DataContracts.DataContractDiagram diagram = diagrams[0] as global::Microsoft.Practices.ServiceFactory.DataContracts.DataContractDiagram; if (diagram != null) { try { this.SuspendFileChangeNotification(fileName); global::Microsoft.Practices.ServiceFactory.DataContracts.DataContractDslSerializationHelper.Instance.SaveDiagram(serializationResult, diagram, fileName, this.Encoding, false); } finally { this.ResumeFileChangeNotification(fileName); } } } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (!serializationResult.Failed) { this.NotifySubordinateDocumentSaved(subordinateDocument.FileName, fileName); } else { // Save failed. throw new global::System.InvalidOperationException(global::Microsoft.Practices.ServiceFactory.DataContracts.DataContractDslDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } }
private void OnPostLoadModel(DslModeling::SerializationResult serializationResult, DslModeling::Partition partition, string fileName, nHydrateModel modelRoot) { }
/// <summary> /// Return the model in XML format /// </summary> /// <param name="modelRoot">Root instance to be saved.</param> /// <param name="encoding">Encoding to use when saving the root instance.</param> /// <param name="serializationMode">Serialization Mode.</param> /// <returns>Model in XML form</returns> public virtual string GetSerializedModelStringVarianten(global::Tum.VModellXT.Varianten modelRoot, global::System.Text.Encoding encoding, DslEditorModeling.SerializationMode serializationMode) { string result = string.Empty; if (modelRoot == null) { return result; } //DslEditorModeling::DomainModelStore dStore = (DslEditorModeling::DomainModelStore)modelRoot.Store; //if( dStore == null) // throw new global::System.ArgumentNullException("dStore"); //dStore.WaitForWritingLockRelease(); DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); using (global::System.IO.MemoryStream modelFileContent = this.InternalSaveModelVarianten(serializationResult, modelRoot, string.Empty, encoding, false, serializationMode)) { if (!serializationResult.Failed && modelFileContent != null) { char[] chars = encoding.GetChars(modelFileContent.GetBuffer()); // search the open angle bracket and trim off the Byte Of Mark. result = new string( chars); int indexPos = result.IndexOf('<'); if (indexPos > 0) { // strip off the leading Byte Of Mark. result = result.Substring(indexPos); } // trim off trailing 0s. result = result.TrimEnd( '\0'); } } return result; }
/// <summary> /// Loads the given file. /// </summary> protected override void Load(string fileName, bool isReload) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::DSLFactory.Candle.SystemModel.CandleModel modelRoot = null; DslModeling::ISchemaResolver schemaResolver = new DslShell::ModelingSchemaResolver(this.ServiceProvider); // Enable diagram fixup rules in our store, because we will load diagram data. global::DSLFactory.Candle.SystemModel.CandleDomainModel.EnableDiagramRules(this.Store); string diagramFileName = fileName + this.DiagramExtension; // Ensure that subordinate diagram file is named properly; handles the case where a rename occurs while the designer was closed. if (this.Hierarchy != null) { uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, this.DiagramExtension); if (itemId != global::Microsoft.VisualStudio.VSConstants.VSITEMID_NIL) { global::System.Diagnostics.Debug.Assert(!this.IsLoaded); // Make sure the name is right before we lock the item in the RDT. DslShell::SubordinateFileHelper.EnsureChildFileName(this.ServiceProvider, this.Hierarchy, itemId, diagramFileName); // Found the diagram file, lock it in the running documents table. this.diagramDocumentLockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument(this.ServiceProvider, this, diagramFileName, itemId); if (this.diagramDocumentLockHolder == null) { throw new global::System.InvalidOperationException(global::DSLFactory.Candle.SystemModel.CandleDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } } } try { modelRoot = global::DSLFactory.Candle.SystemModel.CandleSerializationHelper.Instance.LoadModelAndDiagram(serializationResult, this.Store, fileName, diagramFileName, schemaResolver, null /* no load-time validation */); } finally { if (this.diagramDocumentLockHolder != null && (modelRoot == null || serializationResult.Failed)) { // Load failed, release the document lock if we added one above. this.diagramDocumentLockHolder.UnregisterSubordinateDocument(); this.diagramDocumentLockHolder = null; } } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Load failed, can't open the file. throw new global::System.InvalidOperationException(global::DSLFactory.Candle.SystemModel.CandleDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } else { this.SetRootElement(modelRoot); if (this.Hierarchy != null && global::System.IO.File.Exists(diagramFileName)) { DslShell::SubordinateFileHelper.EnsureChildProjectItem(this.Hierarchy, this.ItemId, diagramFileName); // Should have a subordinate diagram file now. If we didn't add a lock above, add one now. if (this.diagramDocumentLockHolder == null) { uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, this.DiagramExtension); this.diagramDocumentLockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument(this.ServiceProvider, this, diagramFileName, itemId); if (this.diagramDocumentLockHolder == null) { throw new global::System.InvalidOperationException(global::DSLFactory.Candle.SystemModel.CandleDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } } // Connect to events on the RDT in order to allow delayed rename handling. this.eventsCookie = DslShell::SubordinateFileHelper.AdviseRunningDocumentTableEvents(this.ServiceProvider, this); } } }
/// <summary> /// Unregister the observer on dispose. /// </summary> private void Dispose(bool disposing) { global::System.Diagnostics.Debug.Assert(disposing, "SerializationValidationObserver finalized without being disposed!"); if (disposing && this.validationController != null) { this.validationController.RemoveObserver(this); this.validationController = null; } this.serializationResult = null; }
// private void OnPostLoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramPartition, string diagramFileName, ModelRoot modelRoot, EFModelDiagram diagram) // private DslDiagrams::Diagram LoadDiagram(DslModeling::SerializationResult serializationResult, DslModeling::ModelElement modelRoot, DslModeling::Partition diagramPartition, global::System.IO.Stream diagramStream, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator) private DslDiagrams::Diagram LoadDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, string diagramFileName, DslModeling::ModelElement modelRoot, DslModeling::Partition diagramPartition, global::System.IO.Stream diagramStream, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator) { #region Check Parameters if (serializationResult == null) { throw new global::System.ArgumentNullException("serializationResult"); } if (modelRoot == null) { throw new global::System.ArgumentNullException("modelRoot"); } if (diagramPartition == null) { throw new global::System.ArgumentNullException("diagramPartition"); } #endregion DslDiagrams::Diagram diagram = null; var diagramName = string.Empty; // Ensure there is an outer transaction spanning both model and diagram load, so moniker resolution works properly. if (!diagramPartition.Store.TransactionActive) { throw new global::System.InvalidOperationException(EFModelDomainModel.SingletonResourceManager.GetString("MissingTransaction")); } if (diagramStream == null || diagramStream == global::System.IO.Stream.Null || !diagramStream.CanRead || diagramStream.Length < 6) { // missing diagram file indicates we should create a new diagram. diagram = this.CreateDiagramHelper(diagramPartition, modelRoot); } else { var directory = this.GetDirectory(diagramPartition.Store); var localName = string.Empty; var localSettings = EFModelSerializationHelper.Instance.CreateXmlReaderSettings(null, false); try { using (var reader = global::System.Xml.XmlReader.Create(diagramStream, localSettings)) { reader.MoveToContent(); localName = reader.LocalName; global::System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(reader.GetAttribute("name")), "One of diagram streams is not well-formed"); diagramName = reader.GetAttribute("name"); } diagramStream.Seek(0, global::System.IO.SeekOrigin.Begin); } catch (global::System.Xml.XmlException xEx) { DslModeling::SerializationUtilities.AddMessage( new DslModeling::SerializationContext(directory), DslModeling::SerializationMessageKind.Error, xEx ); } var diagramSerializer = directory.GetSerializer(EFModelDiagram.DomainClassId) ?? this.GetSerializer(diagramPartition.Store, localName); global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for " + diagramName); if (diagramSerializer != null) { DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, diagramName, serializationResult); this.InitializeSerializationContext(diagramPartition, serializationContext, true); DslModeling::TransactionContext transactionContext = new DslModeling::TransactionContext(); transactionContext.Add(DslModeling::SerializationContext.TransactionContextKey, serializationContext); using (DslModeling::Transaction postT = diagramPartition.Store.TransactionManager.BeginTransaction("PostLoad Model and Diagram", true, transactionContext)) { using (DslModeling::Transaction t = diagramPartition.Store.TransactionManager.BeginTransaction("LoadDiagram", true, transactionContext)) { // Ensure there is some content in the file. Blank (or almost blank, to account for encoding header bytes, etc.) // files will cause a new diagram to be created and returned if (diagramStream.Length > 5) { global::System.Xml.XmlReaderSettings settings = EFModelSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false); try { using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(diagramStream, settings)) { reader.MoveToContent(); diagram = diagramSerializer.TryCreateInstance(serializationContext, reader, diagramPartition) as DslDiagrams::Diagram; if (diagram != null) { this.ReadRootElement(serializationContext, diagramSerializer, diagram, reader, schemaResolver); } } } catch (global::System.Xml.XmlException xEx) { DslModeling::SerializationUtilities.AddMessage( serializationContext, DslModeling::SerializationMessageKind.Error, xEx ); } if (serializationResult.Failed) { // Serialization error encountered, rollback the transaction. diagram = null; t.Rollback(); } } if (diagram == null && !serializationResult.Failed) { // Create diagram if it doesn't exist diagram = this.CreateDiagramHelper(diagramPartition, modelRoot); } if (t.IsActive) { t.Commit(); } } // End inner Tx // Fire PostLoad customization code whether Load succeeded or not // Provide a method in a partial class with the following signature: ///// <summary> ///// Customize Model and Diagram Loading. ///// </summary> ///// <param name="serializationResult">Stores serialization result from the load operation.</param> ///// <param name="modelPartition">Partition in which the new DslLibrary instance will be created.</param> ///// <param name="modelFileName">Name of the file from which the DslLibrary instance will be deserialized.</param> ///// <param name="diagramPartition">Partition in which the new DslDesignerDiagram instance will be created.</param> ///// <param name="diagramFileName">Name of the file from which the DslDesignerDiagram instance will be deserialized.</param> ///// <param name="modelRoot">The root of the file that was loaded.</param> ///// <param name="diagram">The diagram matching the modelRoot.</param> // private void OnPostLoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramPartition, string diagramFileName, ModelRoot modelRoot, EFModelDiagram diagram) this.OnPostLoadModelAndDiagram(serializationResult, modelPartition, modelFileName, diagramPartition, diagramFileName, (ModelRoot)modelRoot, (EFModelDiagram)diagram); if (serializationResult.Failed) { // Serialization error encountered, rollback the middle transaction. modelRoot = null; postT.Rollback(); } if (postT.IsActive) { postT.Commit(); } } // End MiddleTx // Do load-time validation if a ValidationController is provided. if (!serializationResult.Failed && validationController != null) { using (new SerializationValidationObserver(serializationResult, validationController)) { validationController.Validate(diagramPartition, DslValidation::ValidationCategories.Load); } } } } if (diagram != null) { if (!serializationResult.Failed) { // Succeeded. diagram.ModelElement = diagram.ModelElement ?? modelRoot; diagram.PostDeserialization(true); this.CheckForOrphanedShapes(diagram, serializationResult); } else { // Failed. diagram.PostDeserialization(false); } } return(diagram); }
/// <summary> /// Loads the given file. /// </summary> protected override void Load(string fileName, bool isReload) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::Altinoren.ActiveWriter.Model modelRoot = null; DslModeling::ISchemaResolver schemaResolver = new DslShell::ModelingSchemaResolver(this.ServiceProvider); // Enable diagram fixup rules in our store, because we will load diagram data. global::Altinoren.ActiveWriter.ActiveWriterDomainModel.EnableDiagramRules(this.Store); string diagramFileName = fileName + this.DiagramExtension; // Ensure that subordinate diagram file is named properly; handles the case where a rename occurs while the designer was closed. if(this.Hierarchy != null) { uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, this.DiagramExtension); if(itemId != global::Microsoft.VisualStudio.VSConstants.VSITEMID_NIL) { global::System.Diagnostics.Debug.Assert(!this.IsLoaded); // Make sure the name is right before we lock the item in the RDT. DslShell::SubordinateFileHelper.EnsureChildFileName(this.ServiceProvider, this.Hierarchy, itemId, diagramFileName); // Found the diagram file, lock it in the running documents table. this.diagramDocumentLockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument(this.ServiceProvider, this, diagramFileName, itemId); if (this.diagramDocumentLockHolder == null) { throw new global::System.InvalidOperationException(global::Altinoren.ActiveWriter.ActiveWriterDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } } } try { modelRoot = global::Altinoren.ActiveWriter.ActiveWriterSerializationHelper.Instance.LoadModelAndDiagram(serializationResult, this.Store, fileName, diagramFileName, schemaResolver, null /* no load-time validation */); } finally { if (this.diagramDocumentLockHolder != null && (modelRoot == null || serializationResult.Failed)) { // Load failed, release the document lock if we added one above. this.diagramDocumentLockHolder.UnregisterSubordinateDocument(); this.diagramDocumentLockHolder = null; } } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Load failed, can't open the file. throw new global::System.InvalidOperationException(global::Altinoren.ActiveWriter.ActiveWriterDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } else { this.SetRootElement(modelRoot); if (this.Hierarchy != null && global::System.IO.File.Exists(diagramFileName)) { DslShell::SubordinateFileHelper.EnsureChildProjectItem(this.Hierarchy, this.ItemId, diagramFileName); // Should have a subordinate diagram file now. If we didn't add a lock above, add one now. if (this.diagramDocumentLockHolder == null) { uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, this.DiagramExtension); this.diagramDocumentLockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument(this.ServiceProvider, this, diagramFileName, itemId); if (this.diagramDocumentLockHolder == null) { throw new global::System.InvalidOperationException(global::Altinoren.ActiveWriter.ActiveWriterDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } } // Connect to events on the RDT in order to allow delayed rename handling. this.eventsCookie = DslShell::SubordinateFileHelper.AdviseRunningDocumentTableEvents(this.ServiceProvider, this); } } }
/// <summary> /// Saves the given file. /// </summary> protected override void Save(string fileName) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::Altinoren.ActiveWriter.Model modelRoot = (global::Altinoren.ActiveWriter.Model)this.RootElement; global::System.Collections.Generic.IList<DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(this.RootElement); if (diagrams.Count > 0) { global::Altinoren.ActiveWriter.ActiveRecordMapping diagram = diagrams[0] as global::Altinoren.ActiveWriter.ActiveRecordMapping; if (diagram != null) { string diagramFileName = fileName + this.DiagramExtension; try { this.SuspendFileChangeNotification(diagramFileName); global::Altinoren.ActiveWriter.ActiveWriterSerializationHelper.Instance.SaveModelAndDiagram(serializationResult, modelRoot, fileName, diagram, diagramFileName, this.Encoding, false); if (!serializationResult.Failed) { // fileName != this.FileName is false in the case of Save As. Allow OnFileNameChanged() below to handle this case. if (global::System.StringComparer.OrdinalIgnoreCase.Compare(fileName, this.FileName) == 0 && global::System.IO.File.Exists(diagramFileName)) { DslShell::SubordinateFileHelper.EnsureChildProjectItem(this.Hierarchy, this.ItemId, diagramFileName); } } } finally { this.ResumeFileChangeNotification(diagramFileName); } } } if (!serializationResult.Failed) { global::Altinoren.ActiveWriter.ActiveWriterSerializationHelper.Instance.SaveModel(serializationResult, modelRoot, fileName, this.Encoding, false); } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Save failed. throw new global::System.InvalidOperationException(global::Altinoren.ActiveWriter.ActiveWriterDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } }
/// <summary> /// Saves the given file. /// </summary> protected override void Save(string fileName) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::LinqToRdf.Design.ModelRoot modelRoot = (global::LinqToRdf.Design.ModelRoot)this.RootElement; // Only save the diagrams if // a) There are any to save // b) This is NOT a SaveAs operation. SaveAs should allow the subordinate document to control the save of its data as it is writing a new file. // Except DO save the diagram on SaveAs if there isn't currently a diagram as there won't be a subordinate document yet to save it. bool saveAs = global::System.StringComparer.OrdinalIgnoreCase.Compare(fileName, this.FileName) != 0; global::System.Collections.Generic.IList<DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(this.RootElement); if (diagrams.Count > 0 && (!saveAs || this.diagramDocumentLockHolder == null)) { global::LinqToRdf.Design.ClassDiagram diagram = diagrams[0] as global::LinqToRdf.Design.ClassDiagram; if (diagram != null) { string diagramFileName = fileName + this.DiagramExtension; try { this.SuspendFileChangeNotification(diagramFileName); global::LinqToRdf.Design.LinqToRdfSerializationHelper.Instance.SaveModelAndDiagram(serializationResult, modelRoot, fileName, diagram, diagramFileName, this.Encoding, false); } finally { this.ResumeFileChangeNotification(diagramFileName); } } } else { global::LinqToRdf.Design.LinqToRdfSerializationHelper.Instance.SaveModel(serializationResult, modelRoot, fileName, this.Encoding, false); } // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Save failed. throw new global::System.InvalidOperationException(global::LinqToRdf.Design.LinqToRdfDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } }
private void SaveDocData <TModel, TDiagram>(string fileName, string diagramExtension) where TModel : Microsoft.VisualStudio.Modeling.ModelElement where TDiagram : ComponentModelDiagram { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); IList <TModel> list = this.Store.ElementDirectory.FindElements <TModel>(); string diagramFileName = fileName + diagramExtension; // Utils.UnsetReadOnly(diagramFileName); if (list.Count == 0) { if (File.Exists(diagramFileName)) { File.Delete(diagramFileName); } return; } TModel modelRoot = list[0]; global::System.Collections.Generic.IList <DslDiagrams::PresentationElement> diagrams = DslDiagrams::PresentationViewsSubject.GetPresentation(modelRoot); foreach (PresentationElement presentationElement in diagrams) { TDiagram diagram = presentationElement as TDiagram; if (diagram != null) { try { this.SuspendFileChangeNotification(diagramFileName); global::DSLFactory.Candle.SystemModel.CandleSerializationHelper.Instance.SaveDiagram <TModel>(serializationResult, modelRoot, fileName, diagram, diagramFileName, this.Encoding, false); if (!serializationResult.Failed) { // fileName != this.FileName is false in the case of Save As. Allow OnFileNameChanged() below to handle this case. if (global::System.StringComparer.OrdinalIgnoreCase.Compare(fileName, this.FileName) == 0 && global::System.IO.File.Exists(diagramFileName)) { //DslShell::SubordinateFileHelper.EnsureChildProjectItem( this.Hierarchy, this.ItemId, diagramFileName ); ServiceLocator.Instance.ShellHelper.AddFileToSolution(diagramFileName); } } } finally { this.ResumeFileChangeNotification(diagramFileName); } } } // Report serialization messages. foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } if (serializationResult.Failed) { // Save failed. throw new global::System.InvalidOperationException(global::DSLFactory.Candle.SystemModel.CandleDomainModel.SingletonResourceManager.GetString("CannotSaveDocument")); } }
/// <summary> /// Loads the given file. /// </summary> protected override void Load(string fileName, bool isReload) { DslModeling::SerializationResult serializationResult = new DslModeling::SerializationResult(); global::LinqToRdf.Design.ModelRoot modelRoot = null; DslModeling::ISchemaResolver schemaResolver = new DslShell::ModelingSchemaResolver(this.ServiceProvider); // Enable diagram fixup rules in our store, because we will load diagram data. global::LinqToRdf.Design.LinqToRdfDomainModel.EnableDiagramRules(this.Store); string diagramFileName = fileName + this.DiagramExtension; modelRoot = global::LinqToRdf.Design.LinqToRdfSerializationHelper.Instance.LoadModelAndDiagram(serializationResult, this.Store, fileName, diagramFileName, schemaResolver, null /* no load-time validation */); // Report serialization messages. this.SuspendErrorListRefresh(); try { foreach (DslModeling::SerializationMessage serializationMessage in serializationResult) { this.AddErrorListItem(new DslShell::SerializationErrorListItem(this.ServiceProvider, serializationMessage)); } } finally { this.ResumeErrorListRefresh(); } if (serializationResult.Failed) { // Load failed, can't open the file. throw new global::System.InvalidOperationException(global::LinqToRdf.Design.LinqToRdfDomainModel.SingletonResourceManager.GetString("CannotOpenDocument")); } else { this.SetRootElement(modelRoot); if (this.Hierarchy != null && global::System.IO.File.Exists(diagramFileName)) { // Add a lock to the subordinate diagram file. if (this.diagramDocumentLockHolder == null) { uint itemId = DslShell::SubordinateFileHelper.GetChildProjectItemId(this.Hierarchy, this.ItemId, this.DiagramExtension); if (itemId != global::Microsoft.VisualStudio.VSConstants.VSITEMID_NIL) { this.diagramDocumentLockHolder = DslShell::SubordinateFileHelper.LockSubordinateDocument(this.ServiceProvider, this, diagramFileName, itemId); if (this.diagramDocumentLockHolder == null) { throw new global::System.InvalidOperationException(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, global::LinqToRdf.Design.LinqToRdfDomainModel.SingletonResourceManager.GetString("CannotCloseExistingDiagramDocument"), diagramFileName)); } } } } } }