protected override void ReadXmlSerializable(global::System.Xml.XmlReader reader) { if ((this.DetermineSchemaSerializationMode(reader) == global::System.Data.SchemaSerializationMode.IncludeSchema)) { this.Reset(); global::System.Data.DataSet ds = new global::System.Data.DataSet(); ds.ReadXml(reader); this.DataSetName = ds.DataSetName; this.Prefix = ds.Prefix; this.Namespace = ds.Namespace; this.Locale = ds.Locale; this.CaseSensitive = ds.CaseSensitive; this.EnforceConstraints = ds.EnforceConstraints; this.Merge(ds, false, global::System.Data.MissingSchemaAction.Add); this.InitVars(); } else { this.ReadXml(reader); this.InitVars(); } }
/// <summary> /// This method creates an instance of DesignerDiagram based on the tag currently pointed by the reader. The reader is guaranteed (by the caller) /// to be pointed at a serialized instance of DesignerDiagram. /// </summary> /// <remarks> /// The caller will guarantee that the reader is positioned at open XML tag of the ModelRoot instance being read. This method should /// not move the reader; the reader should remain at the same position when this method returns. /// </remarks> /// <param name="serializationContext">Serialization context.</param> /// <param name="reader">XmlReader to read serialized data from.</param> /// <param name="partition">Partition in which new DesignerDiagram instance should be created.</param> /// <returns>Created DesignerDiagram instance.</returns> protected override DslModeling::ModelElement CreateInstance(DslModeling::SerializationContext serializationContext, global::System.Xml.XmlReader reader, DslModeling::Partition partition) { string idStr = reader.GetAttribute("Id"); try { global::System.Guid id; if (string.IsNullOrEmpty(idStr)) { // Create a default Id. id = global::System.Guid.NewGuid(); StateMachineLanguageSerializationBehaviorSerializationMessages.MissingId(serializationContext, reader, id); } else { id = new global::System.Guid(idStr); } return(new DesignerDiagram(partition, new DslModeling::PropertyAssignment(DslModeling::ElementFactory.IdPropertyAssignment, id))); } catch (global::System.ArgumentNullException /* anEx */) { StateMachineLanguageSerializationBehaviorSerializationMessages.InvalidPropertyValue(serializationContext, reader, "Id", typeof(global::System.Guid), idStr); } catch (global::System.FormatException /* fEx */) { StateMachineLanguageSerializationBehaviorSerializationMessages.InvalidPropertyValue(serializationContext, reader, "Id", typeof(global::System.Guid), idStr); } catch (global::System.OverflowException /* ofEx */) { StateMachineLanguageSerializationBehaviorSerializationMessages.InvalidPropertyValue(serializationContext, reader, "Id", typeof(global::System.Guid), idStr); } return(null); }
private void CustomReadPropertiesFromAttributes(SerializationContext serializationContext, ModelElement element, global::System.Xml.XmlReader reader) { DefaultReadPropertiesFromAttributes(serializationContext, element, reader); }
/// <summary> /// Loads the diagram. /// </summary> /// <typeparam name="TModel">The type of the model.</typeparam> /// <typeparam name="TDiagram">The type of the diagram.</typeparam> /// <param name="serializationResult">The serialization result.</param> /// <param name="modelRoot">The model root.</param> /// <param name="diagramFileName">Name of the diagram file.</param> /// <param name="schemaResolver">The schema resolver.</param> /// <param name="diagramDomainId">The diagram domain id.</param> /// <param name="callback">The callback.</param> public void LoadDiagram <TModel, TDiagram>(DslModeling::SerializationResult serializationResult, TModel modelRoot, string diagramFileName, DslModeling::ISchemaResolver schemaResolver, System.Guid diagramDomainId, CreateDiagramHandler callback) where TModel : ModelElement where TDiagram : ComponentModelDiagram { Partition diagramPartition = modelRoot.Store.DefaultPartition; // 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(global::DSLFactory.Candle.SystemModel.CandleDomainModel.SingletonResourceManager.GetString("MissingTransaction")); } ComponentModelDiagram diagram = null; DslModeling::DomainClassXmlSerializer diagramSerializer = this.Directory.GetSerializer(diagramDomainId); global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for SystemModelDiagram"); if (diagramSerializer != null) { if (!global::System.IO.File.Exists(diagramFileName)) { // missing diagram file indicates we should create a new diagram. diagram = callback(diagramPartition); } else { using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(diagramFileName)) { DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, fileStream.Name, serializationResult); using (DslModeling::Transaction t = diagramPartition.Store.TransactionManager.BeginTransaction("LoadDiagram", true)) { // 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 (fileStream.Length > 5) { global::System.Xml.XmlReaderSettings settings = new global::System.Xml.XmlReaderSettings(); try { using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings)) { reader.MoveToContent(); diagram = diagramSerializer.TryCreateInstance(serializationContext, reader, diagramPartition) as ComponentModelDiagram; if (diagram != null) { // Note: the actual instance we get back from TryCreateInstance() can be of a derived type of SystemModelDiagram, // so we need to find the correct serializer instance to deserialize the element properly. DslModeling::DomainClassXmlSerializer instanceSerializer = this.Directory.GetSerializer(diagram.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(instanceSerializer != null, "Cannot find serializer for " + diagram.GetDomainClass().Name + "!"); instanceSerializer.ReadRootElement(serializationContext, 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 = CreateDiagramHelper(diagramPartition, modelRoot); } if (t.IsActive) { t.Commit(); } } // End inner Tx } } if (diagram != null) { diagram.ModelElement = modelRoot; } } }
/// <summary> /// This methods deserializes nested XML elements inside the passed-in element. /// </summary> /// <remarks> /// The caller will guarantee that the current element does have nested XML elements, and the call will position the /// reader at the open tag of the first child XML element. /// This method will read as many child XML elements as it can. It returns under three circumstances: /// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the open /// tag of the unknown element. This implies that if the first child XML element is unknown, this method should return /// immediately and do nothing. /// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element. /// 3) EOF. /// </remarks> /// <param name="serializationContext">Serialization context.</param> /// <param name="element">In-memory MetaModelLibrary instance that will get the deserialized data.</param> /// <param name="reader">XmlReader to read serialized data from.</param> protected override void ReadElements(SerializationContext serializationContext, ModelElement element, global::System.Xml.XmlReader reader) { base.ReadElements(serializationContext, element, reader); MetaModelLibrary instanceOfMetaModelLibrary = element as MetaModelLibrary; global::System.Diagnostics.Debug.Assert(instanceOfMetaModelLibrary != null, "Expecting an instance of MetaModelLibrary!"); if (!String.IsNullOrEmpty(instanceOfMetaModelLibrary.FilePath) && !String.IsNullOrWhiteSpace(instanceOfMetaModelLibrary.FilePath)) { instanceOfMetaModelLibrary.LoadLibrary(serializationContext); } }
private bool HandleUnrecognizedElement(string elementName, global::System.Xml.XmlReader reader) { throw new global::System.NotImplementedException(); }
/// <summary> /// Read an element from the root of XML. /// </summary> /// <param name="serializationContext">Serialization context.</param> /// <param name="rootElement">In-memory element instance that will get the deserialized data.</param> /// <param name="reader">XmlReader to read serialized data from.</param> /// <param name="schemaResolver">An ISchemaResolver that allows the serializer to do schema validation on the root element (and everything inside it).</param> protected override void ReadRootElement(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement rootElement, global::System.Xml.XmlReader reader, DslModeling::ISchemaResolver schemaResolver) { #region Check Parameters global::System.Diagnostics.Debug.Assert(serializationContext != null); if (serializationContext == null) { throw new global::System.ArgumentNullException("serializationContext"); } global::System.Diagnostics.Debug.Assert(rootElement != null); if (rootElement == null) { throw new global::System.ArgumentNullException("rootElement"); } global::System.Diagnostics.Debug.Assert(reader != null); if (reader == null) { throw new global::System.ArgumentNullException("reader"); } #endregion DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(rootElement.Store); DslModeling::DomainClassXmlSerializer rootSerializer = null; if (rootElement is DslDiagrams::Diagram) { rootSerializer = directory.GetSerializer(PatternModelSchemaDiagram.DomainClassId); } else { rootSerializer = directory.GetSerializer(rootElement.GetDomainClass().Id); } global::System.Diagnostics.Debug.Assert(rootSerializer != null, @"Cannot find serializer for " + rootElement.GetDomainClass().Name + @"!"); // Version check. this.CheckVersion(serializationContext, reader); if (!serializationContext.Result.Failed) { // Use a validating reader if possible using (reader = TryCreateValidatingReader(schemaResolver, reader, serializationContext)) { rootSerializer.Read(serializationContext, rootElement, reader); } } }
public MetaModel LoadModel(DslModeling::SerializationResult serializationResult, DslModeling::Partition partition, string fileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator, bool bStartT, bool bIsTopMost) { #region Model #region Check Parameters if (serializationResult == null) throw new global::System.ArgumentNullException("serializationResult"); if (partition == null) throw new global::System.ArgumentNullException("partition"); if (string.IsNullOrEmpty(fileName)) throw new global::System.ArgumentNullException("fileName"); #endregion // Ensure there is a transaction for this model to Load in. if (!partition.Store.TransactionActive) { throw new global::System.InvalidOperationException(LanguageDSLDomainModel.SingletonResourceManager.GetString("MissingTransaction")); } MetaModel modelRoot = null; DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(partition.Store); DslModeling::DomainClassXmlSerializer modelRootSerializer = directory.GetSerializer(MetaModel.DomainClassId); global::System.Diagnostics.Debug.Assert(modelRootSerializer != null, "Cannot find serializer for MetaModel!"); if (modelRootSerializer != null) { using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(fileName)) { DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileStream.Name, serializationResult); this.InitializeSerializationContext(partition, serializationContext, true); DslModeling::TransactionContext transactionContext = new DslModeling::TransactionContext(); transactionContext.Add(DslModeling::SerializationContext.TransactionContextKey, serializationContext); DslModeling::Transaction t = null; if (bStartT) { t = partition.Store.TransactionManager.BeginTransaction("Load Model from " + fileName, 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 root element to be created and returned. if (fileStream.Length > 5) { try { global::System.Xml.XmlReaderSettings settings = LanguageDSLSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false); using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings)) { // Attempt to read the encoding. reader.Read(); // Move to the first node - will be the XmlDeclaration if there is one. global::System.Text.Encoding encoding; if (this.TryGetEncoding(reader, out encoding)) { serializationResult.Encoding = encoding; } // Load any additional domain models that are required DslModeling::SerializationUtilities.ResolveDomainModels(reader, serializerLocator, partition.Store); reader.MoveToContent(); modelRoot = modelRootSerializer.TryCreateInstance(serializationContext, reader, partition) as MetaModel; if (modelRoot != null && !serializationResult.Failed) { modelRoot.BaseDirectory = MetaModelLibraryBase.GetBaseDirectory(fileName); modelRoot.FilePath = fileName; this.ReadRootElement(serializationContext, modelRoot, reader, schemaResolver); } } } catch (global::System.Xml.XmlException xEx) { DslModeling::SerializationUtilities.AddMessage( serializationContext, DslModeling::SerializationMessageKind.Error, xEx ); } } if (modelRoot == null && !serializationResult.Failed) { // create model root if it doesn't exist. modelRoot = this.CreateModelHelper(partition); modelRoot.BaseDirectory = MetaModelLibraryBase.GetBaseDirectory(fileName); modelRoot.FilePath = fileName; } if (bStartT) if (t.IsActive) t.Commit(); // Do load-time validation if a ValidationController is provided. if (!serializationResult.Failed && validationController != null) { using (new SerializationValidationObserver(serializationResult, validationController)) { validationController.Validate(partition, DslValidation::ValidationCategories.Load); } } } } #endregion MetaModel model = modelRoot; if (bIsTopMost) model.IsTopMost = true; #region Diagrams 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; View view = null; if (System.IO.File.Exists(fileNameDiagram)) { //DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(partition.Store); DslModeling::DomainClassXmlSerializer viewSerializer = directory.GetSerializer(View.DomainClassId); global::System.Diagnostics.Debug.Assert(viewSerializer != null, "Cannot find serializer for View!"); if (viewSerializer != null) { using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(fileNameDiagram)) { DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileStream.Name, serializationResult); this.InitializeSerializationContext(partition, serializationContext, true); DslModeling::TransactionContext transactionContext = new DslModeling::TransactionContext(); transactionContext.Add(DslModeling::SerializationContext.TransactionContextKey, serializationContext); DslModeling::Transaction t = null; if (bStartT) t = partition.Store.TransactionManager.BeginTransaction("Load Model from " + fileNameDiagram, 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 root element to be created and returned. if (fileStream.Length > 5) { try { global::System.Xml.XmlReaderSettings settings = LanguageDSLSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false); using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings)) { // Attempt to read the encoding. reader.Read(); // Move to the first node - will be the XmlDeclaration if there is one. global::System.Text.Encoding encoding; if (this.TryGetEncoding(reader, out encoding)) { serializationResult.Encoding = encoding; } reader.MoveToContent(); view = viewSerializer.TryCreateInstance(serializationContext, reader, partition) as View; if (view != null && !serializationResult.Failed) { // Use a validating reader if possible viewSerializer.Read(serializationContext, view, reader); model.View = view; } } } catch (global::System.Xml.XmlException xEx) { DslModeling::SerializationUtilities.AddMessage( serializationContext, DslModeling::SerializationMessageKind.Error, xEx ); } } if (bStartT) if (t.IsActive) t.Commit(); } } } #endregion //if( bIsTopMost ) SerializationPostProcessor.PostProcessModelLoad(model); return model; }
/// <summary> /// This methods deserializes nested XML elements inside the passed-in element. /// </summary> /// <remarks> /// The caller will guarantee that the current element does have nested XML elements, and the call will position the /// reader at the open tag of the first child XML element. /// This method will read as many child XML elements as it can. It returns under three circumstances: /// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the open /// tag of the unknown element. This implies that if the first child XML element is unknown, this method should return /// immediately and do nothing. /// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element. /// 3) EOF. /// </remarks> /// <param name="serializationContext">Serialization context.</param> /// <param name="element">In-memory Diagram instance that will get the deserialized data.</param> /// <param name="reader">XmlReader to read serialized data from.</param> protected override void ReadElements(SerializationContext serializationContext, ModelElement element, global::System.Xml.XmlReader reader) { // Always call the base class so any extensions are deserialized base.ReadElements(serializationContext, element, reader); Diagram instanceOfDiagram = element as Diagram; foreach (Diagram d in instanceOfDiagram.IncludedDiagrams) { instanceOfDiagram.AddIncludedDiagram(d); } bool bRet = false; using (Transaction tShape = element.Store.TransactionManager.BeginTransaction("Correct children", true)) { bRet = instanceOfDiagram.CorrectChildren(); tShape.Commit(); } // post process element shapes and their positions if (bRet) { // delete link shapes with FromShape or ToShape set to null for (int i = instanceOfDiagram.LinkShapes.Count - 1; i >= 0; i--) { if (instanceOfDiagram.LinkShapes[i].ToShape == null || instanceOfDiagram.LinkShapes[i].FromShape == null) { instanceOfDiagram.LinkShapes[i].Delete(); } } // fixup shapes using (Transaction tShape = element.Store.TransactionManager.BeginTransaction("Fixup missing shapes", true)) { foreach (NodeShape shape in instanceOfDiagram.Children) { shape.FixUpMissingShapes(); } tShape.Commit(); } // fixup link shapes using (Transaction tShape = element.Store.TransactionManager.BeginTransaction("Fixup link shapes shape", true)) { foreach (NodeShape shape in instanceOfDiagram.Children) { shape.FixUpMissingLinkShapes(); } tShape.Commit(); } } // post process link shapes and anchor locations foreach (LinkShape shape in instanceOfDiagram.LinkShapes) { if (shape.EdgePoints.Count > 1) { if (shape.SourceAnchor.AbsoluteLocation == PointD.Empty) { shape.SourceAnchor.AbsoluteLocation = shape.EdgePoints[0].Point; } if (shape.TargetAnchor.AbsoluteLocation == PointD.Empty) { shape.TargetAnchor.AbsoluteLocation = shape.EdgePoints[shape.EdgePoints.Count - 1].Point; } } } }
private DslModeling::Moniker CustomCreateMonikerInstance(DslModeling::SerializationContext serializationContext, global::System.Xml.XmlReader reader, DslModeling::ModelElement sourceRolePlayer, global::System.Guid relDomainClassId, DslModeling::Partition partition) { return(DefaultCreateMonikerInstance(serializationContext, reader, sourceRolePlayer, relDomainClassId, partition)); }
private DslModeling::ModelElement CustomCreateInstance(DslModeling::SerializationContext serializationContext, global::System.Xml.XmlReader reader, DslModeling::Partition partition) { return(DefaultCreateInstance(serializationContext, reader, partition)); }
private static void CustomReadElements(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlReader reader) { DefaultReadElements(serializationContext, element, reader); }
private void CustomRead(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlReader reader) { DefaultRead(serializationContext, element, reader); ConfigurationSectionModel model = (ConfigurationSectionModel)element; // Make sure there's always a Validators instance in the model if (model.PropertyValidators == null) { model.PropertyValidators = new PropertyValidators(model.Store); } }