/// <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);
		}
		private void ValidateServiceMultiplicity (DslValidation::ValidationContext context)
		{
			if (this.ServiceContract == null)
			{
				context.LogViolation(DslValidation::ViolationType.Error,
					string.Format(global::System.Globalization.CultureInfo.CurrentCulture, 
						Microsoft.Practices.ServiceFactory.ServiceContracts.ServiceContractDslDomainModel.SingletonResourceManager.GetString("MinimumMultiplicityMissingLink"), 
						"Service", this.Name, "ServiceContract"),
						"DSL0001", this);
			}
		} // ValidateServiceMultiplicity
Пример #3
0
		private void ValidateAggregateStateMultiplicity (DslValidation::ValidationContext context)
		{
			if (this.BoundedContext == null)
			{
				context.LogViolation(DslValidation::ViolationType.Error,
					string.Format(global::System.Globalization.CultureInfo.CurrentCulture, 
						FourDeep.Dizzle.DizzleDomainModel.SingletonResourceManager.GetString("MinimumMultiplicityMissingLink"), 
						"AggregateState", this.Name, "BoundedContext"),
						"DSL0001", this);
			}
		} // ValidateAggregateStateMultiplicity
		private void ValidateCustomizableElementSchemaBaseMultiplicity (DslValidation::ValidationContext context)
		{
			if (this.Policy == null)
			{
				context.LogViolation(DslValidation::ViolationType.Error,
					string.Format(global::System.Globalization.CultureInfo.CurrentCulture, 
						NuPattern.Runtime.Schema.PatternModelDomainModel.SingletonResourceManager.GetString("MinimumMultiplicityMissingLink"), 
						"CustomizableElementSchema", this.Name, "Policy"),
						"DSL0001", this);
			}
		} // ValidateCustomizableElementSchemaBaseMultiplicity
		private void ValidatePatternSchemaMultiplicity (DslValidation::ValidationContext context)
		{
			if (this.Views.Count == 0)
			{
				context.LogViolation(DslValidation::ViolationType.Error,
					string.Format(global::System.Globalization.CultureInfo.CurrentCulture, 
						NuPattern.Runtime.Schema.PatternModelDomainModel.SingletonResourceManager.GetString("MinimumMultiplicityMissingLink"), 
						"PatternSchema", this.Name, "Views"),
						"DSL0001", this);
			}
		} // ValidatePatternSchemaMultiplicity
		private void ValidateExampleModelMultiplicity (DslValidation::ValidationContext context)
		{
			if (this.Processes.Count == 0)
			{
				context.LogViolation(DslValidation::ViolationType.Error,
					string.Format(global::System.Globalization.CultureInfo.CurrentCulture, 
						DmitriNesteruk.AsyncDsl.AsyncDslDomainModel.SingletonResourceManager.GetString("MinimumMultiplicityMissingLink"), 
						"ExampleModel", "", "Processes"),
						"DSL0001", this);
			}
		} // ValidateExampleModelMultiplicity
Пример #7
0
		public virtual HostDesignerModel LoadModel(DslModeling::SerializationResult serializationResult, DslModeling::Partition partition, string fileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator)
		{
			#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(HostDesignerDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
			}
			
			HostDesignerModel modelRoot = null;
			DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(partition.Store);
			DslModeling::DomainClassXmlSerializer modelRootSerializer = directory.GetSerializer(HostDesignerModel.DomainClassId);
			global::System.Diagnostics.Debug.Assert(modelRootSerializer != null, "Cannot find serializer for HostDesignerModel!");
			if (modelRootSerializer != null)
			{
				using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(fileName))
				{
		
					using (DslModeling::Transaction postT = partition.Store.TransactionManager.BeginTransaction("PostLoad Model", true))
					{		
						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);
						using (DslModeling::Transaction 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 = HostDesignerSerializationHelper.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 HostDesignerModel;
										if (modelRoot != null && !serializationResult.Failed)
										{
											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);
							}
							if (t.IsActive)
								t.Commit();
						} // End Inner Tx
		
						// Fire PostLoad customization code whether load has succeeded or not
						// Provide a method in a partial class with the following signature:
						
						///// <summary>
						///// Customize Model Loading.
						///// </summary>
						///// <param name="serializationResult">Stores serialization result from the load operation.</param>
						///// <param name="partition">Partition in which the new HostDesignerModel instance will be created.</param>
						///// <param name="fileName">Name of the file from which the HostDesignerModel instance will be deserialized.</param>
						///// <param name="modelRoot">The root of the file that was loaded.</param>
						// private void OnPostLoadModel(DslModeling::SerializationResult serializationResult, DslModeling::Partition partition, string fileName, HostDesignerModel modelRoot )
	
						this.OnPostLoadModel(serializationResult, partition, fileName, modelRoot);
						if (serializationResult.Failed)
						{	// Serialization error encountered, rollback the middle transaction.
							modelRoot = null;
							postT.Rollback();
						}
						if (postT.IsActive)
							postT.Commit();
					} // End PostLoad Tx
	
					// 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);
						}
					}
	
				}
			}
			return modelRoot;
		}
Пример #8
0
		private void ValidateMonikerAmbiguity(DslValidation::ValidationContext context)
		{
			// Don't run this rule when deserializing - any ambiguous monikers will 
			// already have stopped the file from loading.
			if (this.Store.InSerializationTransaction)
			{
				return;
			}
		
			global::System.Collections.Generic.IDictionary<global::System.Guid, DslModeling::IMonikerResolver> monikerResolvers = HostDesignerSerializationHelper.Instance.GetMonikerResolvers(this.Store);
			foreach (DslModeling::ModelElement element in this.Store.ElementDirectory.AllElements)
			{
				global::System.Guid domainModelId = element.GetDomainClass().DomainModel.Id;
				DslModeling::IMonikerResolver monikerResolver = null;
				if (monikerResolvers.TryGetValue(domainModelId, out monikerResolver) && monikerResolver != null)
				{
					DslModeling::SimpleMonikerResolver simpleMonikerResolver = monikerResolver as DslModeling::SimpleMonikerResolver;
					if (simpleMonikerResolver != null)
					{
						try
						{
							simpleMonikerResolver.ProcessAddedElement(element);
						}
						catch (DslModeling::AmbiguousMonikerException amEx)
						{	// Ambiguous moniker detected.
							context.LogError(
								string.Format(
									global::System.Globalization.CultureInfo.CurrentCulture,
									HostDesignerDomainModel.SingletonResourceManager.GetString("AmbiguousMoniker"),
									amEx.Moniker,
									DslModeling::SerializationUtilities.GetElementName(element),
									DslModeling::SerializationUtilities.GetElementName(amEx.Element)
								),
								"AmbiguousMoniker", 
								this,
								amEx.Element
							);
						}
					}
				}
			}
			// Clean up the created moniker resolvers after the check.
			foreach (DslModeling::IMonikerResolver monikerResolver in monikerResolvers.Values)
			{
				DslModeling::SimpleMonikerResolver simpleMonikerResolver = monikerResolver as DslModeling::SimpleMonikerResolver;
				if (simpleMonikerResolver != null)
					simpleMonikerResolver.Reset();
			}
			monikerResolvers.Clear();
		}
Пример #9
0
		/// <summary>
		/// Add ValidationExtensionRegistrar to the ValidationController and handle related MEF Initialization operations
		/// </summary>
		/// <param name="validationController"></param>
		partial void SetValidationExtensionRegistrar(DslValidation::ValidationController validationController);
		public virtual ExampleModel LoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Partition modelPartition, string modelFileName, DslModeling::Partition diagramPartition, string diagramFileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController)
		{
			#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
	
			ExampleModel modelRoot;
	
			// 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(AsyncDslDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
			}
	
			modelRoot = this.LoadModel(serializationResult, modelPartition, modelFileName, schemaResolver, validationController);
	
			if (serializationResult.Failed)
			{
				// don't try to deserialize diagram data if model load failed.
				return modelRoot;
			}
	
			AsyncDslDiagram diagram = null;
			DslModeling::DomainClassXmlSerializer diagramSerializer = this.Directory.GetSerializer(AsyncDslDiagram.DomainClassId);
			global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for AsyncDslDiagram");
			if (diagramSerializer != null)
			{
				if(!global::System.IO.File.Exists(diagramFileName))
				{
					// missing diagram file indicates we should create a new diagram.
					diagram = this.CreateDiagramHelper(diagramPartition, modelRoot);
				}
				else
				{
					using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(diagramFileName))
					{
						DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, fileStream.Name, serializationResult);
						// Set up MonikerResolver for AsyncDsl.
						this.SetupMonikerResolver(serializationContext, diagramPartition.Store);
						
						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 AsyncDslDiagram;
										if (diagram != null)
										{
											// Note: the actual instance we get back from TryCreateInstance() can be of a derived type of AsyncDslDiagram,
											// 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 = this.CreateDiagramHelper(diagramPartition, modelRoot);
							}
							
							if (t.IsActive)
								t.Commit();
						} // End inner Tx
	
						// 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 = modelRoot;
						diagram.PostDeserialization(true);
						this.CheckForOrphanedShapes(diagram, serializationResult);
					}
					else
					{	// Failed.
						diagram.PostDeserialization(false);
					}
				}
			}
			return modelRoot;
		}
		/// <summary>
		/// Loads a ExampleModel instance.
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the load operation.</param>
		/// <param name="partition">Partition in which the new ExampleModel instance will be created.</param>
		/// <param name="fileName">Name of the file from which the ExampleModel 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 ExampleModel instance.</returns>
		public virtual ExampleModel LoadModel(DslModeling::SerializationResult serializationResult, DslModeling::Partition partition, string fileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController)
		{
			#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(AsyncDslDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
			}
			
			ExampleModel modelRoot = null;
			DslModeling::DomainClassXmlSerializer modelRootSerializer = this.Directory.GetSerializer(ExampleModel.DomainClassId);
			global::System.Diagnostics.Debug.Assert(modelRootSerializer != null, "Cannot find serializer for ExampleModel!");
			if (modelRootSerializer != null)
			{
				using (global::System.IO.FileStream fileStream = global::System.IO.File.OpenRead(fileName))
				{
					using (DslModeling::Transaction t = partition.Store.TransactionManager.BeginTransaction("Load Model from " + fileName, true))
					{
						DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(this.Directory, fileStream.Name, serializationResult);
						// Set up MonikerResolver for AsyncDsl.
						this.SetupMonikerResolver(serializationContext, partition.Store);
						// 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)
						{
							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();
									modelRoot = modelRootSerializer.TryCreateInstance(serializationContext, reader, partition) as ExampleModel;
									if (modelRoot != null && !serializationResult.Failed)
									{
										// Note: the actual instance we get back from TryCreateInstance() can be of a derived type of ExampleModel,
										// so we need to find the correct serializer instance to deserialize the element properly.
										DslModeling::DomainClassXmlSerializer instanceSerializer = this.Directory.GetSerializer(modelRoot.GetDomainClass().Id);
										global::System.Diagnostics.Debug.Assert(instanceSerializer != null, "Cannot find serializer for " + modelRoot.GetDomainClass().Name + "!");
										instanceSerializer.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);
						}
						if (t.IsActive)
							t.Commit();
					} // End Inner Tx
	
					// 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);
						}
					}
				}
			}
			return modelRoot;
		}
		/// <summary>
		/// Loads a ExampleModel instance into the default partition of the given store, and ignore serialization result.
		/// </summary>
		/// <param name="store">The new ExampleModel instance will be created into the default partition of this store.</param>
		/// <param name="fileName">Name of the file from which the ExampleModel 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 ExampleModel instance.</returns>
		public virtual ExampleModel LoadModel(DslModeling::Store store, string fileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController)
		{
			#region Check Parameters
			if (store == null) 
				throw new global::System.ArgumentNullException("store");
			#endregion
			
			return this.LoadModel(new DslModeling::SerializationResult(), store.DefaultPartition, fileName, schemaResolver, validationController);
		}
 public MetaModel LoadModel(DslModeling::SerializationResult serializationResult, DslModeling::Partition partition, string fileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator, bool bStartT)
 {
     return LoadModel(serializationResult, partition, fileName, schemaResolver, validationController, serializerLocator, true, false);
 }
			/// <summary>
			/// Called with validation messages are added.
			/// </summary>
			protected override void OnValidationMessageAdded(DslValidation::ValidationMessage addedMessage)
			{
				#region Check Parameters
				global::System.Diagnostics.Debug.Assert(addedMessage != null);
				#endregion
	
				if (addedMessage != null && this.serializationResult != null)
				{	// Record the validation message as a serialization message.
					DslModeling::SerializationUtilities.AddValidationMessage(this.serializationResult, addedMessage);
				}
				base.OnValidationMessageAdded(addedMessage);
			}
Пример #15
0
		public virtual HostDesignerModel 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
	
			HostDesignerModel modelRoot;
	
			// 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(HostDesignerDomainModel.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;
			}
	
			HostDesignerDiagram diagram = null;
			DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(diagramPartition.Store);
			DslModeling::DomainClassXmlSerializer diagramSerializer = directory.GetSerializer(HostDesignerDiagram.DomainClassId);
			global::System.Diagnostics.Debug.Assert(diagramSerializer != null, "Cannot find serializer for HostDesignerDiagram");
			if (diagramSerializer != null)
			{
				if(!global::System.IO.File.Exists(diagramFileName))
				{
					// missing diagram file indicates we should create a new diagram.
					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 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 (fileStream.Length > 5)
								{
									global::System.Xml.XmlReaderSettings settings = HostDesignerSerializationHelper.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 HostDesignerDiagram;
											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)
									{	
										// 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, HostDesignerModel modelRoot, HostDesignerDiagram diagram)
	
							this.OnPostLoadModelAndDiagram(serializationResult, modelPartition, modelFileName, diagramPartition, diagramFileName, modelRoot, 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 = modelRoot;
						diagram.PostDeserialization(true);
						this.CheckForOrphanedShapes(diagram, serializationResult);
					}
					else
					{	// Failed.
						diagram.PostDeserialization(false);
					}
				}
			}
			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 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;
        }
Пример #18
0
		/// <summary>
		/// Loads a HostDesignerModel instance and its associated diagram file into the default partition of the given store, and ignore serialization result.
		/// </summary>
		/// <param name="store">The new HostDesignerModel instance will be created into the default partition of this store.</param>
		/// <param name="modelFileName">Name of the file from which the HostDesignerModel instance will be deserialized.</param>
		/// <param name="diagramFileName">Name of the file from which the HostDesignerDiagram 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 HostDesignerModel instance.</returns>
		public virtual HostDesignerModel LoadModelAndDiagram(DslModeling::Store store, string modelFileName, string diagramFileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator)
		{
			return this.LoadModelAndDiagram(new DslModeling::SerializationResult(), store, modelFileName, diagramFileName, schemaResolver, validationController, serializerLocator);
		}
		/// <summary>
		/// Loads a EntityDesignerViewModel instance and its associated diagram file into the default partition of the given store, and ignore serialization result.
		/// </summary>
		/// <param name="store">The new EntityDesignerViewModel instance will be created into the default partition of this store.</param>
		/// <param name="modelFileName">Name of the file from which the EntityDesignerViewModel instance will be deserialized.</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>
        internal virtual global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityDesignerViewModel LoadModelAndDiagram(DslModeling::Store store, string modelFileName, string diagramFileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator)
		{
			return this.LoadModelAndDiagram(new DslModeling::SerializationResult(), store, modelFileName, diagramFileName, schemaResolver, validationController, serializerLocator);
		}
Пример #20
0
		/// <summary>
		/// Loads a HostDesignerModel instance and its associated diagram file 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 HostDesignerModel instance will be created into the default partition of this store.</param>
		/// <param name="modelFileName">Name of the file from which the HostDesignerModel instance will be deserialized.</param>
		/// <param name="diagramFileName">Name of the file from which the HostDesignerDiagram 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 HostDesignerModel instance.</returns>
		public virtual HostDesignerModel LoadModelAndDiagram(DslModeling::SerializationResult serializationResult, DslModeling::Store store, string modelFileName, string diagramFileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator)
		{
			#region Check Parameters
			if (store == null)
				throw new global::System.ArgumentNullException("store");
			#endregion
			
			DslModeling::Partition diagramPartition = new DslModeling::Partition(store);
			return this.LoadModelAndDiagram(serializationResult, store.DefaultPartition, modelFileName, diagramPartition, diagramFileName, schemaResolver, validationController, serializerLocator);
		}
 public override MetaModel LoadModel(SerializationResult serializationResult, Store store, string fileName, ISchemaResolver schemaResolver, DslValidation.ValidationController validationController, ISerializerLocator serializerLocator)
 {
     return LoadModel(serializationResult, store.DefaultPartition, fileName, schemaResolver, validationController, serializerLocator, true, true);
 }
			/// <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);
			}
		private void ValidateMonikerAmbiguity(DslValidation::ValidationContext context)
		{
			global::System.Collections.Generic.IDictionary<global::System.Guid, DslModeling::IMonikerResolver> monikerResolvers = AsyncDslSerializationHelper.Instance.GetMonikerResolvers(this.Store);
			foreach (DslModeling::ModelElement element in this.Store.ElementDirectory.AllElements)
			{
				global::System.Guid domainModelId = element.GetDomainClass().DomainModel.Id;
				DslModeling::IMonikerResolver monikerResolver = null;
				if (monikerResolvers.TryGetValue(domainModelId, out monikerResolver) && monikerResolver != null)
				{
					DslModeling::SimpleMonikerResolver simpleMonikerResolver = monikerResolver as DslModeling::SimpleMonikerResolver;
					if (simpleMonikerResolver != null)
					{
						try
						{
							simpleMonikerResolver.ProcessAddedElement(element);
						}
						catch (DslModeling::AmbiguousMonikerException amEx)
						{	// Ambiguous moniker detected.
							context.LogError(
								string.Format(
									global::System.Globalization.CultureInfo.CurrentCulture,
									AsyncDslDomainModel.SingletonResourceManager.GetString("AmbiguousMoniker"),
									amEx.Moniker,
									DslModeling::SerializationUtilities.GetElementName(element),
									DslModeling::SerializationUtilities.GetElementName(amEx.Element)
								),
								"AmbiguousMoniker", 
								this,
								amEx.Element
							);
						}
					}
				}
			}
			// Clean up the created moniker resolvers after the check.
			foreach (DslModeling::IMonikerResolver monikerResolver in monikerResolvers.Values)
			{
				DslModeling::SimpleMonikerResolver simpleMonikerResolver = monikerResolvers as DslModeling::SimpleMonikerResolver;
				if (simpleMonikerResolver != null)
					simpleMonikerResolver.Dispose();
			}
			monikerResolvers.Clear();
		}
        public virtual global::Tum.VModellXT.VModell LoadModelVModell(DslModeling::SerializationResult serializationResult, DslModeling::Partition partition, string fileName, DslModeling::ISchemaResolver schemaResolver, DslValidation::ValidationController validationController, DslModeling::ISerializerLocator serializerLocator)
        {
            #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

            DslEditorModeling::DomainModelStore dStore = (DslEditorModeling::DomainModelStore)partition.Store;
            if( dStore == null)
                throw new global::System.ArgumentNullException("dStore");
			//dStore.WaitForWritingLockRelease();

            // Ensure there is a transaction for this model to Load in.
            if (!partition.Store.TransactionActive)
            {
                throw new global::System.InvalidOperationException(VModellXTDomainModel.SingletonResourceManager.GetString("MissingTransaction"));
            }
			
			global::Tum.VModellXT.VModell modelRoot = null;
			DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(partition.Store);
			DslModeling::DomainClassXmlSerializer modelRootSerializer = directory.GetSerializer(global::Tum.VModellXT.VModell.DomainClassId);
			global::System.Diagnostics.Debug.Assert(modelRootSerializer != null, "Cannot find serializer for VModell!");
			if (modelRootSerializer != null)
			{
				global::System.IO.FileStream fileStream = null;
			
				try
				{
					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);
					
					//using (DslModeling::Transaction 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)
						{
							global::System.Xml.XmlReaderSettings settings = VModellXTSerializationHelper.Instance.CreateXmlReaderSettings(serializationContext, false);
							using (global::System.Xml.XmlReader reader = global::System.Xml.XmlReader.Create(fileStream, settings))
							{
								try
								{	
									// 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 global::Tum.VModellXT.VModell;
									if (modelRoot != null && !serializationResult.Failed)
									{
										modelRoot.DomainFilePath = fileName;
										this.ReadRootElementVModell(serializationContext, modelRoot, reader, schemaResolver);
									}
									
                                    fileStream.Dispose();
								}
								catch (global::System.Xml.XmlException xEx)
								{
									DslModeling::SerializationUtilities.AddMessage(
										serializationContext,
										DslModeling::SerializationMessageKind.Error,
										xEx
									);
								}
								finally
								{
									fileStream = null;
								}	
							}							
						}
				
						if(modelRoot == null && !serializationResult.Failed)
						{
							// create model root if it doesn't exist.
							modelRoot = this.CreateModelHelperVModell(partition);
							modelRoot.DomainFilePath = fileName;
						}
						//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);
						}
					}
				}
				finally
				{
					if( fileStream != null )
						fileStream.Dispose();
				}
			}
			return modelRoot;
        }
		/// <summary>
		/// Loads a EntityDesignerViewModel 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 EntityDesignerViewModel instance will be created into the default partition of this store.</param>
		/// <param name="fileName">Name of the file from which the EntityDesignerViewModel 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>
		internal virtual global::Microsoft.Data.Entity.Design.EntityDesigner.ViewModel.EntityDesignerViewModel 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.LoadModel(serializationResult, store.DefaultPartition, fileName, schemaResolver, validationController, serializerLocator);
		}