Exemple #1
0
        public static string ClassName(string name, string outputNamespace)
        {
            var asmQualifiedName = new StringBuilder();

            if (name.Split(Shared.Core.NfSettings.DefaultTypeSeparator).Length > 1)
            {
                var nameParts       = name.Split(Shared.Core.NfSettings.DefaultTypeSeparator);
                var actualClassName = nameParts[(nameParts.Length - 1)].Replace(" ", Globals.REPLACE_SPACE_WITH_SEQUENCE);
                nameParts[(nameParts.Length - 1)] = NfString.SafeDotNetTypeName(actualClassName);
                name = string.Join(Shared.Core.NfSettings.DefaultTypeSeparator.ToString(CultureInfo.InvariantCulture), nameParts);
            }

            //remove any chars not allowed in C# ids
            name = NfString.SafeDotNetTypeName(name);

            //capitalize first letter of whole word to avoid conflict with C# reserved words
            name = NfString.CapWords(name, Shared.Core.NfSettings.DefaultTypeSeparator);

            if (!String.IsNullOrWhiteSpace(outputNamespace))
            {
                outputNamespace = NfString.CapWords(outputNamespace, Shared.Core.NfSettings.DefaultTypeSeparator);
                asmQualifiedName.AppendFormat("{0}{1}", outputNamespace, Shared.Core.NfSettings.DefaultTypeSeparator);
            }

            asmQualifiedName.Append(name);

            if (!String.IsNullOrWhiteSpace(outputNamespace))
            {
                asmQualifiedName.AppendFormat(", {0}", NfReflect.DraftCscExeAsmName(outputNamespace));
            }

            var typeName = new NfTypeName(asmQualifiedName.ToString());

            if (!String.IsNullOrWhiteSpace(outputNamespace))
            {
                return(typeName.AssemblyQualifiedName);
            }

            return(typeName.FullName);
        }
Exemple #2
0
        public static XElement HibernateConfigurationNode(string connectionString, string outputNamespace)
        {
            outputNamespace = NfString.CapWords(outputNamespace, Shared.Core.NfSettings.DefaultTypeSeparator);
            XNamespace hbmXmlNs           = Globals.HBM_XML_NS;
            var        hbmConfigNode      = new XElement(hbmXmlNs + Nm.HIBERNATE_CONFIGURATION);
            var        sessionFactoryNode = new XElement(Nm.SESSION_FACTORY);

            var propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.ConnectionProvider))
            {
                Value = "NHibernate.Connection.DriverConnectionProvider"
            };

            sessionFactoryNode.Add(propertyNode);

            propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.ConnectionDriver))
            {
                Value = "NHibernate.Driver.SqlClientDriver"
            };
            sessionFactoryNode.Add(propertyNode);

            propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.Dialect))
            {
                Value = "NHibernate.Dialect.MsSql2008Dialect"
            };
            sessionFactoryNode.Add(propertyNode);

            propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.ConnectionString))
            {
                Value = connectionString
            };

            sessionFactoryNode.Add(propertyNode);

            propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.Isolation))
            {
                Value = "ReadCommitted"
            };

            sessionFactoryNode.Add(propertyNode);

            propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.CommandTimeout))
            {
                Value = "30"
            };

            sessionFactoryNode.Add(propertyNode);

            propertyNode = new XElement(Nm.PROPERTY, new XAttribute(Nm.NAME, NHibernate.Cfg.Environment.MaxFetchDepth))
            {
                Value = "3"
            };

            sessionFactoryNode.Add(propertyNode);

            var mappingNode = new XElement(Nm.MAPPING, new XAttribute(Nm.ASSEMBLY, NfReflect.DraftCscExeAsmName(outputNamespace)));

            sessionFactoryNode.Add(mappingNode);

            hbmConfigNode.Add(sessionFactoryNode);

            return(hbmConfigNode);
        }