src/Misc/EFTools/EntityDesignEntityDesigner/GeneratedCode/SerializationHelper.cs
/// <summary>
/// Loads a EntityDesignerViewModel instance and its associated diagram file.
/// </summary>
/// <param name="serializationResult">Stores serialization result from the load operation.</param>
/// <param name="modelPartition">Partition in which the new EntityDesignerViewModel instance will be created.</param>
/// <param name="modelFileName">Name of the file from which the EntityDesignerViewModel instance will be deserialized.</param>
/// <param name="diagramPartition">Partition in which the new EntityDesignerDiagram instance will be created.</param>
/// <param name="diagramFileName">Name of the file from which the EntityDesignerDiagram 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>
/// <returns>The loaded EntityDesignerViewModel instance.</returns>
Loads a EntityDesignerViewModel instance and its associated diagram file.
Loads a EntityDesignerViewModel instance and its associated diagram file .
internal virtual global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityDesignerViewModel LoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramPartition, string diagramFileName, 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 (diagramPartition == null)
				throw new global::System.ArgumentNullException("diagramPartition");
			if (string.IsNullOrEmpty(diagramFileName))
				throw new global::System.ArgumentNullException("diagramFileName");
			#endregion
			global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityDesignerViewModel modelRoot;
			if (!diagramPartition.Store.TransactionActive)
			{
				throw new global::System.InvalidOperationException(MicrosoftDataEntityDesignDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
			}
			modelRoot = this.LoadModel(serializationResult, modelPartition, modelFileName, schemaResolver, validationController, serializerLocator);
			if (serializationResult.Failed)
			{
				return modelRoot;
			}
			global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityDesignerDiagram diagram = null;
			DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(diagramPartition.Store);
			DslModeling::DomainClassXmlSerializer diagramSerializer = directory.GetSerializer(global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityDesignerDiagram.DomainClassId);
			global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for EntityDesignerDiagram");
			if (diagramSerializer != null)
			{
				if(!global::System.IO.File.Exists(diagramFileName))
				{
					diagram = this.CreateDiagramHelper(diagramPartition, modelRoot);
				}
				else
				{
					using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(diagramFileName))
					{
						DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileStream.Name, serializationResult);
						this.InitializeSerializationContext(diagramPartition, serializationContext, true);
						DslModeling::TransactionContext transactionContext = new DslModeling::TransactionContext();
						transactionContext.Add(DslModeling::SerializationContext.TransactionContextKey, serializationContext);
						using (DslModeling::Transaction t = diagramPartition.Store.TransactionManager.BeginTransaction("LoadDiagram", true, transactionContext))
						{
							if (fileStream.Length > 5)
							{
								global::System.Xml.XmlReaderSettings settings = MicrosoftDataEntityDesignSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false);
								try
								{
									using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings))
									{
										reader.MoveToContent();
										diagram = diagramSerializer.TryCreateInstance(serializationContext, reader, diagramPartition) as global::Microsoft.Data.Entity.Design.EntityDesigner.View.EntityDesignerDiagram;
										if (diagram != null)
										{
											this.ReadRootElement(serializationContext, diagram, reader, schemaResolver);
										}
									}
								}
								catch (global::System.Xml.XmlException xEx)
								{
									DslModeling::SerializationUtilities.AddMessage(
										serializationContext,
										DslModeling::SerializationMessageKind.Error,
										xEx
									);
								}
								if (serializationResult.Failed)
								{	
									diagram = null;
									t.Rollback();
								}
							}
							if(diagram == null && !serializationResult.Failed)
							{
								diagram = this.CreateDiagramHelper(diagramPartition, modelRoot);
							}
							if (t.IsActive)
								t.Commit();
						} 
						if (!serializationResult.Failed && validationController != null)
						{
							using (new SerializationValidationObserver(serializationResult, validationController))
							{
								validationController.Validate(diagramPartition, DslValidation::ValidationCategories.Load);
							}
						}
					}
				}
				if (diagram != null)
				{
					if (!serializationResult.Failed)
					{	
						diagram.ModelElement = modelRoot;
						diagram.PostDeserialization(true);
						this.CheckForOrphanedShapes(diagram, serializationResult);
					}
					else
					{	
						diagram.PostDeserialization(false);
					}
				}
			}
			return modelRoot;
		}
internal virtual global :: Microsoft . Data . Entity . Design . EntityDesigner . ViewModel . EntityDesignerViewModel LoadModelAndDiagram ( DslModeling :: SerializationResult serializationResult , DslModeling :: Partition modelPartition , string modelFileName , DslModeling :: Partition diagramPartition , string diagramFileName , DslModeling :: ISchemaResolver schemaResolver , DslValidation :: ValidationController validationController , DslModeling :: ISerializerLocator serializerLocator ) { region  Check Parameters if ( serializationResult == null ) throw new global :: System . ArgumentNullException ( " " ) ; if ( modelPartition == null ) throw new global :: System . ArgumentNullException ( " " ) ; if ( diagramPartition == null ) throw new global :: System . ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( diagramFileName ) ) throw new global :: System . ArgumentNullException ( " " ) ; endregion global :: Microsoft . Data . Entity . Design . EntityDesigner . ViewModel . EntityDesignerViewModel modelRoot ; if ( ! diagramPartition . Store . TransactionActive ) { throw new global :: System . InvalidOperationException ( MicrosoftDataEntityDesignDomainModel . SingletonResourceManager . GetString ( " " ) ) ; } modelRoot = this . LoadModel ( serializationResult , modelPartition , modelFileName , schemaResolver , validationController , serializerLocator ) ; if ( serializationResult . Failed ) { return modelRoot ; } global :: Microsoft . Data . Entity . Design . EntityDesigner . View . EntityDesignerDiagram diagram = null ; DslModeling :: DomainXmlSerializerDirectory directory = this . GetDirectory ( diagramPartition . Store ) ; DslModeling :: DomainClassXmlSerializer diagramSerializer = directory . GetSerializer ( global :: Microsoft . Data . Entity . Design . EntityDesigner . View . EntityDesignerDiagram . DomainClassId ) ; global :: System . Diagnostics . Debug . Assert ( diagramSerializer != null , " " ) ; if ( diagramSerializer != null ) { if ( ! global :: System . IO . File . Exists ( diagramFileName ) ) { diagram = this . CreateDiagramHelper ( diagramPartition , modelRoot ) ; } else { using ( global :: System . IO . FileStream fileStream = global :: System . IO . File . OpenRead ( diagramFileName ) ) { DslModeling :: SerializationContext serializationContext = new DslModeling :: SerializationContext ( directory , fileStream . Name , serializationResult ) ; this . InitializeSerializationContext ( diagramPartition , serializationContext , true ) ; DslModeling :: TransactionContext transactionContext = new DslModeling :: TransactionContext ( ) ; transactionContext . Add ( DslModeling :: SerializationContext . TransactionContextKey , serializationContext ) ; using ( DslModeling :: Transaction t = diagramPartition . Store . TransactionManager . BeginTransaction ( " " , true , transactionContext ) ) { if ( fileStream . Length > 5 ) { global :: System . Xml . XmlReaderSettings settings = MicrosoftDataEntityDesignSerializationHelper . Instance . CreateXmlReaderSettings ( serializationContext , false ) ; try { using ( global :: System . Xml . XmlReader reader = global :: System . Xml . XmlReader . Create ( fileStream , settings ) ) { reader . MoveToContent ( ) ; diagram = diagramSerializer . TryCreateInstance ( serializationContext , reader , diagramPartition ) as global :: Microsoft . Data . Entity . Design . EntityDesigner . View . EntityDesignerDiagram ; if ( diagram != null ) { this . ReadRootElement ( serializationContext , diagram , reader , schemaResolver ) ; } } } catch ( global :: System . Xml . XmlException xEx ) { DslModeling :: SerializationUtilities . AddMessage ( serializationContext , DslModeling :: SerializationMessageKind . Error , xEx ) ; } if ( serializationResult . Failed ) { diagram = null ; t . Rollback ( ) ; } } if ( diagram == null && ! serializationResult . Failed ) { diagram = this . CreateDiagramHelper ( diagramPartition , modelRoot ) ; } if ( t . IsActive ) t . Commit ( ) ; } if ( ! serializationResult . Failed && validationController != null ) { using ( new SerializationValidationObserver ( serializationResult , validationController ) ) { validationController . Validate ( diagramPartition , DslValidation :: ValidationCategories . Load ) ; } } } } if ( diagram != null ) { if ( ! serializationResult . Failed ) { diagram . ModelElement = modelRoot ; diagram . PostDeserialization ( true ) ; this . CheckForOrphanedShapes ( diagram , serializationResult ) ; } else { diagram . PostDeserialization ( false ) ; } } } return modelRoot ; }
Loads a EntityDesignerViewModel instance and its associated diagram file.
Loads a EntityDesignerViewModel instance and its associated diagram file .
// Ensure there is an outer transaction spanning both model and diagram load, so moniker resolution works properly. // don't try to deserialize diagram data if model load failed. // missing diagram file indicates we should create a new diagram. // 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  // Serialization error encountered, rollback the transaction. // Create diagram if it doesn't exist // End inner Tx // Do load-time validation if a ValidationController is provided. // Succeeded. // Failed.
The loaded EntityDesignerViewModel instance.
The loaded EntityDesignerViewModel instance .
serializationResult
DslModeling::SerializationResult
Stores serialization result from the load operation.
Stores serialization result from the load operation .
modelPartition
DslModeling::Partition
Partition in which the new EntityDesignerViewModel instance will be created.
Partition in which the new EntityDesignerViewModel instance will be created .
modelFileName
string
Name of the file from which the EntityDesignerViewModel instance will be deserialized.
Name of the file from which the EntityDesignerViewModel instance will be deserialized .
diagramPartition
DslModeling::Partition
Partition in which the new EntityDesignerDiagram instance will be created.
Partition in which the new EntityDesignerDiagram instance will be created .
diagramFileName
string
Name of the file from which the EntityDesignerDiagram instance will be deserialized.
Name of the file from which the EntityDesignerDiagram instance will be deserialized .
schemaResolver
DslModeling::ISchemaResolver
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.
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 .
validationController
DslValidation::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.
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 .
serializerLocator
DslModeling::ISerializerLocator