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); } } } }
/// <summary> /// Initialize the mappings using the configuration and /// the list of types /// </summary> public static void Initialize(IConfigurationSource source, params Type[] types) { if (source == null) { throw new ArgumentNullException("source"); } if (types == null) { throw new ArgumentNullException("types"); } // First initialization ISessionFactoryHolder holder = CreateSessionFactoryHolderImplementation(source); holder.ThreadScopeInfo = CreateThreadScopeInfoImplementation(source); RaiseSessionFactoryHolderCreated(holder); ActiveRecordModel.type2Model.Clear(); ActiveRecordBase._holder = holder; // Base configuration SetUpConfiguration(source, typeof(ActiveRecordBase), holder); ActiveRecordModelBuilder builder = new ActiveRecordModelBuilder(); ActiveRecordModelCollection models = builder.Models; foreach (Type type in types) { if (models.Contains(type) || type == typeof(ActiveRecordBase) || type == typeof(ActiveRecordValidationBase)) { continue; } else if (type.IsAbstract && typeof(ActiveRecordBase).IsAssignableFrom(type)) { SetUpConfiguration(source, type, holder); continue; } else if (!IsActiveRecordType(type)) { continue; } builder.Create(type); } GraphConnectorVisitor connectorVisitor = new GraphConnectorVisitor(models); connectorVisitor.VisitNodes(models); SemanticVerifierVisitor semanticVisitor = new SemanticVerifierVisitor(models); semanticVisitor.VisitNodes(models); XmlGenerationVisitor xmlVisitor = new XmlGenerationVisitor(); foreach (ActiveRecordModel model in models) { Configuration cfg = holder.GetConfiguration(holder.GetRootType(model.Type)); if (!model.IsNestedType && !model.IsDiscriminatorSubClass && !model.IsJoinedSubClass) { xmlVisitor.Reset(); xmlVisitor.CreateXml(model); String xml = xmlVisitor.Xml; if (xml != String.Empty) { cfg.AddXmlString(xml); } } } }