private static ActiveRecordModelCollection BuildModels(ISessionFactoryHolder holder,
		                                                       IConfigurationSource source,
		                                                       IEnumerable<Type> types, bool ignoreProblematicTypes)
		{
			ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();

			builder.SetExtension(new ModelBuilderExtensionComposite(extensions));

			ActiveRecordModelCollection models = builder.Models;

			foreach(Type type in types)
			{
				if (ShouldIgnoreType(type))
				{
					if (ignoreProblematicTypes)
					{
						continue;
					}
					else
					{
						throw new ActiveRecordException(
							String.Format("Type `{0}` is registered already", type.FullName));
					}
				}
				else if (IsConfiguredAsRootType(type))
				{
					if (TypeDefinesADatabaseBoundary(type))
					{
						SetUpConfiguration(source, type, holder);
						continue;
					}
					else
					{
						throw new ActiveRecordException(
							string.Format(
								"Type `{0}` is not a valid root type.  Make sure it is abstract and does not define a table itself.",
								type.FullName));
					}
				}
				else if (!IsActiveRecordType(type))
				{
					if (ignoreProblematicTypes)
					{
						continue;
					}
					else
					{
						throw new ActiveRecordException(
							String.Format("Type `{0}` is not an ActiveRecord type. Use ActiveRecordAttributes to define one", type.FullName));
					}
				}

				if (type.ContainsGenericParameters)
				{
					// Owing to a restriction in NHibernate the reflection optimiser will not work
					// if we have generic types so turn it off. Do we have anywhere we could log this?
					Environment.UseReflectionOptimizer = false;
				}

				ActiveRecordModel model = builder.Create(type);

				if (model == null)
				{
					throw new ActiveRecordException(
						String.Format("ActiveRecordModel for `{0}` could not be created", type.FullName));
				}

				registeredTypes.Add(type, String.Empty);

				if (ModelCreated != null)
				{
					ModelCreated(model, source);
				}
			}

			return models;
		}
Esempio n. 2
0
		private static ActiveRecordModelCollection BuildModels(ISessionFactoryHolder holder,
		                                                       IConfigurationSource source,
		                                                       IEnumerable<Type> types, bool ignoreProblematicTypes)
		{
			ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder();

			builder.SetExtension(new ModelBuilderExtensionComposite(extensions));

			ActiveRecordModelCollection models = builder.Models;

			foreach(Type type in types)
			{
				if (ShouldIgnoreType(type))
				{
					if (ignoreProblematicTypes)
					{
						continue;
					}
					else
					{
						throw new ActiveRecordException(
							String.Format("Type `{0}` is registered already", type.FullName));
					}
				}
				else if (IsConfiguredAsRootType(type))
				{
					if (TypeDefinesADatabaseBoundary(type))
					{
						SetUpConfiguration(source, type, holder);
						continue;
					}
					else
					{
						throw new ActiveRecordException(
							string.Format(
								"Type `{0}` is not a valid root type.  Make sure it is abstract and does not define a table itself.",
								type.FullName));
					}
				}
				else if (!IsActiveRecordType(type))
				{
					if (ignoreProblematicTypes)
					{
						continue;
					}
					else
					{
						throw new ActiveRecordException(
							String.Format("Type `{0}` is not an ActiveRecord type. Use ActiveRecordAttributes to define one", type.FullName));
					}
				}

				ActiveRecordModel model = builder.Create(type);

				if (model == null)
				{
					throw new ActiveRecordException(
						String.Format("ActiveRecordModel for `{0}` could not be created", type.FullName));
				}

				registeredTypes.Add(type, String.Empty);

				if (ModelCreated != null)
				{
					ModelCreated(model, source);
				}
			}

			return models;
		}