Generate xml from assembly level attributes. This is useful if we need to have type-less configuration, such as imports, named queries, etc.
コード例 #1
0
		private static void AddXmlToNHibernateCfg(ISessionFactoryHolder holder, ActiveRecordModelCollection models)
		{
			XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor();
			AssemblyXmlGenerator assemblyXmlGenerator = new AssemblyXmlGenerator();
			ISet assembliesGeneratedXmlFor = new HashedSet();
			foreach(ActiveRecordModel model in models)
			{
				Configuration config = holder.GetConfiguration(holder.GetRootType(model.Type));

				if (config == null)
				{
					throw new ActiveRecordException(
						string.Format(
							"Could not find configuration for {0} or its root type {1} this is usually an indication that the configuration has not been setup correctly.",
							model.Type, holder.GetRootType(model.Type)));
				}

				if (!model.IsNestedType && !model.IsDiscriminatorSubClass && !model.IsJoinedSubClass)
				{
					xmlVisitor.Reset();
					xmlVisitor.CreateXml(model);

					String xml = xmlVisitor.Xml;

					if (xml != String.Empty)
					{
						AddXmlString(config, xml, model);
					}
				}
			}
		}
コード例 #2
0
		private static void AddXmlToNHibernateFromAssmebliesAttributes(ISessionFactoryHolder holder, ActiveRecordModelCollection models)
		{
			Iesi.Collections.Generic.ISet<Assembly> assembliesGeneratedXmlFor = new HashedSet<Assembly>();
			AssemblyXmlGenerator assemblyXmlGenerator = new AssemblyXmlGenerator();

			foreach (ActiveRecordModel model in models)
			{
				if (assembliesGeneratedXmlFor.Contains(model.Type.Assembly)) 
					continue;

				assembliesGeneratedXmlFor.Add(model.Type.Assembly);

				Configuration config = holder.GetConfiguration(holder.GetRootType(model.Type));
					
				string[] configurations = assemblyXmlGenerator.CreateXmlConfigurations(model.Type.Assembly);

				foreach (string xml in configurations)
				{
					if (xml != string.Empty)
					{
						config.AddXmlString(xml);
					}
				}
			}

			foreach (Assembly assembly in registeredAssemblies)
			{
				if (assembliesGeneratedXmlFor.Contains(assembly))
					continue;

				assembliesGeneratedXmlFor.Add(assembly);

				Configuration config = holder.GetConfiguration(holder.GetRootType(typeof(ActiveRecordBase)));

				string[] configurations = assemblyXmlGenerator.CreateXmlConfigurations(assembly);

				foreach (string xml in configurations)
				{
					if (xml != string.Empty)
					{
						config.AddXmlString(xml);
					}
				}
			}
		}