private void WriteMappingsTo(Func <HibernateMapping, XmlTextWriter> writerBuilder, bool shouldDispose) { EnsureMappingsBuilt(); foreach (var mapping in compiledMappings) { var serializer = new MappingXmlSerializer(); var document = serializer.Serialize(mapping); XmlTextWriter xmlWriter = null; try { xmlWriter = writerBuilder(mapping); xmlWriter.Formatting = Formatting.Indented; document.WriteTo(xmlWriter); } finally { if (shouldDispose && xmlWriter != null) { xmlWriter.Close(); } } } }
public void WriteMappingsTo(string folder) { EnsureMappingsBuilt(); foreach (var mapping in compiledMappings) { var serializer = new MappingXmlSerializer(); var document = serializer.Serialize(mapping); string filename; if (MergeMappings) { filename = GetMappingFileName(); } else if (mapping.Classes.Count() > 0) { filename = mapping.Classes.First().Type.FullName + ".hbm.xml"; } else { filename = "filter-def." + mapping.Filters.First().Name + ".hbm.xml"; } using (var writer = new XmlTextWriter(Path.Combine(folder, filename), Encoding.Default)) { writer.Formatting = Formatting.Indented; document.WriteTo(writer); } } }
private static string render_xml(Action <FluentNHibernate.PersistenceModel> addMappings) { var model = new FluentNHibernate.PersistenceModel(); addMappings(model); var mappings = model.BuildMappings(); var doc = new MappingXmlSerializer().Serialize(mappings.First()); return(doc.OuterXml); }
public void VerifyAll(IXmlWriter <TMappingType> writer) { foreach (var test in _tests) { var mapping = new TMappingType(); test.ApplyToSource(mapping); var serializer = new MappingXmlSerializer(); var xmlDoc = writer.Write(mapping); test.Check(xmlDoc); } }
public virtual void Configure(Configuration cfg) { EnsureMappingsBuilt(); foreach (var mapping in compiledMappings.Where(m => !m.Classes.Any())) { var serializer = new MappingXmlSerializer(); XmlDocument document = serializer.Serialize(mapping); cfg.AddDocument(document); } foreach (var mapping in compiledMappings.Where(m => m.Classes.Any())) { var serializer = new MappingXmlSerializer(); XmlDocument document = serializer.Serialize(mapping); if (cfg.GetClassMapping(mapping.Classes.First().Type) == null) { cfg.AddDocument(document); } } }
public void VerifyAll(IXmlWriter <TMappingType> writer) { foreach (var test in _tests) { TMappingType mapping; if (constructor == null) { mapping = (TMappingType)typeof(TMappingType).InstantiateUsingParameterlessConstructor(); } else { mapping = constructor(); } test.ApplyToSource(mapping); var serializer = new MappingXmlSerializer(); var xmlDoc = writer.Write(mapping); test.Check(xmlDoc); } }
public void Configure(Configuration cfg) { var rootMapping = BuildHibernateMapping(); ApplyVisitors(rootMapping); var serializer = new MappingXmlSerializer(); XmlDocument document = serializer.Serialize(rootMapping); cfg.AddDocument(document); }