public static void OneTimeInitalize(params Assembly[] assemblies)
        {
            if (sessionFactory != null) return;

            Dictionary<string, string> properties = new Dictionary<string, string>();

            properties.Add("connection.driver_class", "NHibernate.Driver.SQLite20Driver");

            properties.Add("dialect", "NHibernate.Dialect.SQLiteDialect");

            properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");

            properties.Add("query.substitutions", "true=1;false=0");

            properties.Add("connection.connection_string", "Data Source=MyTestDb.db;Version=3;New=True;");

            configuration = new Configuration();

            configuration.SetProperties(properties);

            foreach (Assembly assembly in assemblies)
            {
                configuration = configuration.AddAssembly(assembly);
            }

            sessionFactory = configuration.BuildSessionFactory();
        }
Exemple #2
0
        /// <summary>
        /// 构建一个NHibernate Configuration实例并注册到容器
        /// </summary>
        /// <returns></returns>
        public static Configuration BuildNHibernateConfiguration(this Configuration configuration)
        {
            var nhibernateConfiguration = new NHibernateCfg.Configuration();

            nhibernateConfiguration.SetProperties(GetConfigSettings());
            ObjectContainer.Register(nhibernateConfiguration);
            return(configuration);
        }
 public static void Configure(Configuration configuration)
 {
     IDictionary<string, string> properties = new Dictionary<string, string>();
     properties[Environment.Dialect] = typeof(OracleSpatialDialect).AssemblyQualifiedName;
     properties[Environment.ConnectionProvider] = typeof(DebugConnectionProvider).AssemblyQualifiedName;
     properties[Environment.ConnectionDriver] = typeof(OracleDataClientDriver).AssemblyQualifiedName;
     properties[Environment.ConnectionString] = Settings.Default.ConnectionString;
     //properties[Environment.Hbm2ddlAuto] = "create-drop";
     configuration.SetProperties(properties);
 }
 public static void Configure(Configuration configuration)
 {
     IDictionary<string, string> properties = new Dictionary<string, string>();
     properties[Environment.ProxyFactoryFactoryClass] = typeof(NHibernateFactory).AssemblyQualifiedName;
     properties[Environment.Dialect] = typeof(MySQL57SpatialDialect).AssemblyQualifiedName;
     properties[Environment.ConnectionProvider] = typeof(DebugConnectionProvider).AssemblyQualifiedName;
     properties[Environment.ConnectionDriver] = typeof(MySqlDataDriver).AssemblyQualifiedName;
     properties[Environment.ConnectionString] = Tests.NHibernate.Spatial.Properties.Settings.Default.ConnectionString;
     configuration.SetProperties(properties);
 }
 public static void Configure(Configuration configuration)
 {
     IDictionary<string, string> properties = new Dictionary<string, string>();
     properties[Environment.ProxyFactoryFactoryClass] = typeof(NHibernateFactory).AssemblyQualifiedName;
     properties[Environment.Dialect] = typeof(PostGis20Dialect).AssemblyQualifiedName;
     properties[Environment.ConnectionProvider] = typeof(DebugConnectionProvider).AssemblyQualifiedName;
     properties[Environment.ConnectionDriver] = typeof(NpgsqlDriver).AssemblyQualifiedName;
     properties[Environment.ConnectionString] = Tests.NHibernate.Spatial.Properties.Settings.Default.ConnectionString;
     //properties[Environment.Hbm2ddlAuto] = "create-drop";
     configuration.SetProperties(properties);
 }
		public static void Configure(Configuration configuration)
		{
			IDictionary<string, string> properties = new Dictionary<string, string>();
            properties[Environment.ProxyFactoryFactoryClass] = typeof(NHibernateFactory).AssemblyQualifiedName;
			properties[Environment.Dialect] = typeof(MsSql2008GeometryDialect).AssemblyQualifiedName;
			properties[Environment.ConnectionProvider] = typeof(DebugConnectionProvider).AssemblyQualifiedName;
			properties[Environment.ConnectionDriver] = typeof(SqlClientDriver).AssemblyQualifiedName;
			properties[Environment.ConnectionString] = Settings.Default.ConnectionString;
			//properties[Environment.Hbm2ddlAuto] = "create-drop";
			configuration.SetProperties(properties);
		}
 private void SetNHibernateConfigProperties(Configuration _cfg)
 {
     Dictionary<string, string> newProperties = new Dictionary<string, string>();
     newProperties.Add("connection.connection_string", ConfigSettings.Current.DatabaseConnectionInfo.ConnectionString);
     newProperties.Add("dialect", "NHibernate.Dialect.MsSql2005Dialect");
     newProperties.Add("connection.isolation", "ReadUncommitted");
     newProperties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
     newProperties.Add("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
     newProperties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu");
     _cfg.SetProperties(newProperties);
     _cfg.AddAssembly("Portlet.SimpleQuery");
 }
 private void SetNHibernateConfigProperties(Configuration cfg)
 {
     var newProperties = new Dictionary<string, string>
         {
             {"connection.connection_string", ConfigSettings.Current.DatabaseConnectionInfo.ConnectionString},
             {"dialect", "NHibernate.Dialect.MsSql2005Dialect"},
             {"connection.isolation", "ReadUncommitted"},
             {"connection.provider", "NHibernate.Connection.DriverConnectionProvider"},
             {"connection.driver_class", "NHibernate.Driver.SqlClientDriver"},
             {
                 "proxyfactory.factory_class",
                 "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"
             }
         };
     cfg.SetProperties(newProperties);
     cfg.AddAssembly("BCProxyLogin");
 }
		protected virtual Configuration CreateNHibernateConfiguration(IEnumerable<Assembly> inputAssemblies, ProxyGeneratorOptions options)
		{
			var nhibernateConfiguration = new Configuration();

			nhibernateConfiguration.SetProperties(GetDefaultNHibernateProperties(options));

			foreach (var inputAssembly in inputAssemblies)
			{
				nhibernateConfiguration.AddAssembly(inputAssembly);
			}

			return nhibernateConfiguration;
		}
 public Configuration ConfigureProperties(Configuration nhibernateConfig)
 {
     return nhibernateConfig.SetProperties(_settings.GetProperties());
 }
Exemple #11
0
 static Configuration BuildSessionFactory() {
     var config = new Configuration();
     config.SetProperties(CreateSessionFactoryDefaultProperties());
     config.SetProperty(NhCfgEnv.ConnectionString, "Data Source=db-dev4.gdepb.gov.cn;Initial Catalog=Test;Persist Security Info=True;User ID=udev;Password=devdev");
     var mapper = new ConventionModelMapper();
     mapper.AddMapping(new UserMapping());
     mapper.AddMapping(new RoleMapping());
     var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
     config.AddMapping(mapping);
     return config;
 }
Exemple #12
0
        internal void PrepareSessionFactory(string ConnectionString)
        {
            IDictionary<string, string> Properties = new Dictionary<string, string>();

            Properties.Add("connection.driver_class", "NHibernate.Driver.MySqlDataDriver");
            Properties.Add("connection.connection_string", ConnectionString);
            Properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle");
            Properties.Add("dialect", "NHibernate.Dialect.MySQL5Dialect");

            NHCfg.Configuration Configuration = new NHCfg.Configuration();
            Configuration.SetProperties(Properties);

            foreach(FileInfo FI in new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "database")).GetFiles("*.dll"))
            {
                Configuration.AddAssembly(Assembly.LoadFile(FI.FullName));
            }

            fNHibernateSessionFactory = Configuration.BuildSessionFactory();
        }
Exemple #13
0
        public void Configure()
        {
            Configuration = new Configuration().DataBaseIntegration(
                x =>
            {
#if DEBUG
                x.LogSqlInConsole = true;
                x.LogFormattedSql = true;
#endif
            });

            OnConfiguring();

            //var filePath = ConfigFile;
            //filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath);

            //var cfg = Configuration.Configure(filePath);

            var cfg = Configuration.SetProperties(_parameters);
            Console.WriteLine("NhRepositoryConfiguration Parameters");
            _parameters.ToList().ForEach(x => Console.WriteLine("{0}:{1}", x.Key, x.Value));
            Action <IEnumerable <string> > funcCreateInitialScripts =
                scriptFileNames =>
            {
                var scriptBuilder = new StringBuilder();
                scriptFileNames
                .ToList().ForEach(
                    scriptFile =>
                {
                    using (var streamReader = new StreamReader(scriptFile, Encoding.GetEncoding("iso-8859-9")))
                    {
                        scriptBuilder.AppendLine(streamReader.ReadToEnd());
                    }
                }
                    );
                cfg.AddAuxiliaryDatabaseObject(new SimpleAuxiliaryDatabaseObject(scriptBuilder.ToString(), null));
            };

            Action <IEnumerable <string> > actCodeMappings =
                assemblyFileNames =>
            {
                var modelMapper = new ModelMapper();
                assemblyFileNames.ToList().ForEach(
                    assebmlyFile => modelMapper.AddMappings(Assembly.Load(assebmlyFile).GetExportedTypes()));

                var mp = modelMapper.CompileMappingForAllExplicitlyAddedEntities();
                // For Duplicate mapping
                mp.autoimport = false;
                cfg.AddDeserializedMapping(mp, null);
            };

            Action <IEnumerable <string> > actXmlMappings = assemblyFileNames => assemblyFileNames.ToList().ForEach(
                assebmlyFile => cfg.AddAssembly(assebmlyFile));

            if (_databaseConfiguration.AllowInstall)
            {
                funcCreateInitialScripts(_databaseConfiguration.GetScriptFiles());
            }

            var codeMappings = _databaseConfiguration.GetMappings(MappingType.Code);

            if (codeMappings.Any())
            {
                actCodeMappings(codeMappings);
            }

            var xmlMappings = _databaseConfiguration.GetMappings(MappingType.Xml);
            if (xmlMappings.Any())
            {
                actXmlMappings(xmlMappings);
            }

            SchemaMetadataUpdater.QuoteTableAndColumns(cfg);

            if (_databaseConfiguration.AllowInstall)
            {
                new SchemaExport(cfg).SetOutputFile(_databaseConfiguration.ScriptFilePath).Create(false, true);
            }
            Configured = true;

            OnConfigured();
        }
Exemple #14
0
        /// <summary>
        /// Este método permite configurar el servicio de persistencia global.
        /// Qué significa esto depende de la implementación de la innerface y
        /// de el servicio subyacente utilizado para efectivamente gestionar
        /// los datos. En este caso se trata de una configuración del servicio 
        /// del NHibernate por lo que se setean los valores iniciales necesarios 
        /// para arrancar el ISessionFactory. Se deberá establecer el valor 
        /// _configurado (protected) a 'true' una vez que se haya configurado 
        /// el servicio.
        /// </summary>
        public static void ConfigurarPersistencia()
        {
            try {
                if (_configurado)
                    return;

                Configuration configuration = new Configuration();

                configuration.SetProperties(_propiedades);

                foreach (string s in _incluidos)
                    configuration.AddAssembly(s);

                if (EsquemaORM.Helper != null)
                    EsquemaORM.GenerarEsquema(configuration);

                _sessionFactory = configuration.BuildSessionFactory();

                if (EsquemaORM.Helper != null)
                    EsquemaORM.CargarEsquema();

                _configurado = true;
            } catch (Exception e) {
                throw new PersistErrorException("DB-INIT-ERROR", e.ToString());
            }
        }
 /// <inheritdoc/>
 public virtual Configuration CreateConfiguration(NetworkCredential credential, Firma company)
 {
     var cfg = new Configuration();
     cfg.SetProperties(new Dictionary<string, string>
     {
         { Environment.ConnectionString, GetConnectionString(credential, company) },
         { Environment.Dialect, typeof(NHibernate.Dialect.SybaseSQLAnywhere12Dialect).AssemblyQualifiedName },
         { Environment.ConnectionDriver, typeof(NHibernate.Driver.SybaseSQLAnywhereDotNet4Driver).AssemblyQualifiedName },
     });
     foreach (var mappingAssembly in MappingAssemblies)
     {
         cfg.AddAssembly(mappingAssembly);
     }
     return cfg;
 }