public void InitialiseEntityModel(ArchAngel.Providers.EntityModel.ProviderInfo providerInfo, PreGenerationData data) { providerInfo.MappingSet.CodeParseResults = null; // Clear the current mapped class. providerInfo.MappingSet.EntitySet.Entities.ForEach(e => e.MappedClass = null); // Find the csproj file we are going to use string filename; var csprojDocument = GetCSProjDocument(data, out filename); if (csprojDocument == null) { return; } CSProjFile csproj = new CSProjFile(csprojDocument, filename); var hbmFiles = ProjectLoader.GetHBMFilesFromCSProj(csproj, fileController); // Load HBMs foreach (string hbmFilePath in hbmFiles) { if (!File.Exists(hbmFilePath)) { throw new FileNotFoundException(string.Format("A file is defined is your csproj file [{0}], but it cannot be found: [{1}]", filename, hbmFilePath), hbmFilePath); } } var mappings = hbmFiles.Select(f => MappingFiles.Version_2_2.Utility.Open(f)).ToList(); // Parse the CSharp files var csharpFiles = ProjectLoader.GetCSharpFilesFromCSProj(csproj, fileController); var parseResults = ParseResults.ParseCSharpFiles(csharpFiles); providerInfo.MappingSet.CodeParseResults = parseResults; // Clear the current mapped class. providerInfo.MappingSet.EntitySet.Entities.ForEach(e => e.MappedClass = null); // Map the Entity objects to the parsed Class var entities = providerInfo.MappingSet.EntitySet.Entities.ToDictionary(e => e.Name); foreach (var hm in mappings) { foreach (var hClass in hm.Classes()) { var fullClassName = HibernateMappingHelper.ResolveFullClassName(hClass, hm); var shortClassName = HibernateMappingHelper.ResolveShortClassName(hClass, hm); // try find the entity Entity entity; if (entities.TryGetValue(shortClassName, out entity)) { // try find class in parse results var parsedClass = parseResults.FindClass(fullClassName, entity.Properties.Select(p => p.Name).ToList()); entity.MappedClass = parsedClass; } else { Log.InfoFormat("Could not find entity for class named {0} in the NHibernate project on disk.", shortClassName); } } } // Now, try to map entities that haven't been found yet foreach (var entity in entities.Select(v => v.Value).Where(e => e.MappedClass == null)) { string entityName = entity.Name; // try find class in parse results var parsedClass = parseResults.FindClass(entityName, entity.Properties.Select(p => p.Name).ToList()); entity.MappedClass = parsedClass; } }
public void Setup() { var csprojText = File.ReadAllText(Path.Combine("Resources", "NHProject.txt")); csprojPath = @"C:\test.csproj"; doc = new XmlDocument(); doc.LoadXml(csprojText); nsManager = new XmlNamespaceManager(doc.NameTable); nsManager.AddNamespace("msb", MSB_NAMESPACE); var fileController = MockRepository.GenerateMock<IFileController>(); fileController .Stub(f => f.ReadAllText(csprojPath)) .Return(csprojText); fileController .Stub(f => f.ToAbsolutePath(@"Model\Mappings\Category.hbm.xml", csprojPath)) .Return(@"C:\Model\Mappings\Category.hbm.xml"); fileController .Stub(f => f.ToAbsolutePath(@"Model\Mappings\CustomerDemographic.hbm.xml", csprojPath)) .Return(@"C:\Model\Mappings\CustomerDemographic.hbm.xml"); fileController .Stub(f => f.ToAbsolutePath(@"Model\Mappings\Customer.hbm.xml", csprojPath)) .Return(@"C:\Model\Mappings\Customer.hbm.xml"); fileController .Stub(f => f.ToAbsolutePath(@"hibernate.cfg.xml", csprojPath)) .Return(@"C:\hibernate.cfg.xml"); fileController .Stub(f => f.ToAbsolutePath(@"Model\Category.cs", csprojPath)) .Return(@"C:\Model\Category.cs"); fileController .Stub(f => f.ToAbsolutePath(@"Model\CustomerDemographic.cs", csprojPath)) .Return(@"C:\Model\CustomerDemographic.cs"); fileController .Stub(f => f.ToAbsolutePath(@"Model\Customer.cs", csprojPath)) .Return(@"C:\Model\Customer.cs"); loader = new ProjectLoader(fileController); }