Пример #1
0
 public static string Convert(string classMapName, MappedClassInfo classInfo, string nameSpace)
 {
     CodeFileBuilder builder = new CodeFileBuilder();
     ClassMapBody bodyBuilder = new ClassMapBody(builder);
     builder.AddUsing("System");
     builder.AddUsing("FluentNHibernate.Mapping");
     builder.StartNamespace(nameSpace);
     {
         builder.StartClass(classMapName + ": ClassMap<" + classInfo.ClassName + ">", false, false);
         {
             builder.StartMethod("public " + classMapName + "()");
             {
                 if (!String.IsNullOrEmpty(classInfo.TableName))
                 {
                     builder.AddLine(FluentNHibernateNames.Table + "(\"" + classInfo.TableName + "\");");
                 }
                 foreach (var info in classInfo.Properties)
                 {
                     bodyBuilder.Add("", info);
                 }
             }
             builder.EndBlock();
         }
         builder.EndBlock();
     }
     builder.EndBlock();
     return builder.ToString();
 }
Пример #2
0
        public static MappedClassInfo LoadFile(string nhibernateFilePath)
        {
            MappingDocumentParser parser = new MappingDocumentParser();
            HbmMapping mapping;

            try
            {
                using (FileStream stream = File.OpenRead(nhibernateFilePath))
                {
                    mapping = parser.Parse(stream);
                }
            }
            catch (Exception)
            {
                Console.WriteLine(nhibernateFilePath);
                throw;
            }

            if (mapping.Items.Length != 1)
            {
                throw new ParserException("NHibernate file has NO data: " + nhibernateFilePath);
            }

            MappedClassInfo classInfo = new MappedClassInfo((HbmClass) mapping.Items[0], nhibernateFilePath);
            return classInfo;
        }
Пример #3
0
        public static MappedClassInfo LoadFromString(string hbmData)
        {
            MappingDocumentParser parser = new MappingDocumentParser();
            MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(hbmData));
            HbmMapping mapping = parser.Parse(stream);

            if (mapping.Items.Length != 1)
            {
                throw new ParserException("NO data in: " + hbmData);
            }

            MappedClassInfo classInfo = new MappedClassInfo((HbmClass) mapping.Items[0], "from text");
            return classInfo;
        }
Пример #4
0
        private void ConvertFile(MappedClassInfo classInfo, string nameSpace, string destDirectory)
        {
            string classNameAndNamespace = classInfo.ClassName;
            int    dotLoc    = classNameAndNamespace.LastIndexOf('.');
            string className = classNameAndNamespace;

            if (dotLoc != -1)
            {
                className = className.Substring(dotLoc + 1);
            }
            string classMapName = className + "Map";
            string result       = Convert(classMapName, classInfo, nameSpace);

            File.WriteAllText(Path.Combine(destDirectory, classMapName + ".cs"), result);
        }
Пример #5
0
        public static MappedClassInfo LoadFromString(string hbmData)
        {
            MappingDocumentParser parser  = new MappingDocumentParser();
            MemoryStream          stream  = new MemoryStream(Encoding.ASCII.GetBytes(hbmData));
            HbmMapping            mapping = parser.Parse(stream);

            if (mapping.Items.Length != 1)
            {
                throw new ParserException("NO data in: " + hbmData);
            }

            MappedClassInfo classInfo = new MappedClassInfo((HbmClass)mapping.Items[0], "from text");

            return(classInfo);
        }
Пример #6
0
        public static string Convert(string classMapName, MappedClassInfo classInfo, string nameSpace)
        {
            CodeFileBuilder builder = new CodeFileBuilder();

            builder.AddUsing("System");
            builder.AddUsing("FluentNHibernate.Mapping");
            builder.StartNamespace(nameSpace);
            {
                builder.StartClass(classMapName + ": ClassMap<" + classInfo.ClassName + ">", false, false);
                {
                    builder.StartMethod("public " + classMapName + "()");
                    {
                        if (!String.IsNullOrEmpty(classInfo.TableName))
                        {
                            builder.AddLine(FluentNHibernateNames.Table + "(\"" + classInfo.TableName + "\");");
                        }

                        new CacheBuilder(builder).Add(classInfo.Cache, true);

                        if (!classInfo.Mutable)
                        {
                            builder.AddLine("ReadOnly();");
                        }

                        ClassMapBody bodyBuilder = new ClassMapBody(builder);
                        foreach (var info in classInfo.Properties)
                        {
                            bodyBuilder.Add("", info);
                        }
                    }
                    builder.EndBlock();
                }
                builder.EndBlock();
            }
            builder.EndBlock();
            return(builder.ToString());
        }