Esempio n. 1
0
 public void SetDefaultConnectionStr()
 {
     if (_configuration != null)
     {
         string connectionString = EDoc2Utility.GenerateConnectionString();
         if (!string.IsNullOrEmpty(connectionString))
         {
             _configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionString, connectionString);
         }
     }
 }
Esempio n. 2
0
        private static void InitConfiguration()
        {
            var         fileName = "hibernate.config";
            EDoc2DbType dbType   = (EDoc2DbType)EDoc2Utility.DatabaseType;

            switch (dbType)
            {
            case EDoc2DbType.SqlServer:
                fileName = "hibernate.sqlserver.config";
                break;

            case EDoc2DbType.Oracle:
                fileName = "hibernate.oracle.config";
                break;

            case EDoc2DbType.MySql:
                fileName = "hibernate.mysql.config";
                break;

            case EDoc2DbType.Dm:
                fileName = "hibernate.dm.config";
                break;

            default:
                break;
            }
            _configuration = new Configuration().Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName));
            string connectionString = EDoc2Utility.GenerateConnectionString();

            if (_configuration.Properties.ContainsKey(NHibernate.Cfg.Environment.ConnectionProvider))
            {
                _configuration.Properties.Remove(NHibernate.Cfg.Environment.ConnectionProvider);
            }
            if (!string.IsNullOrEmpty(connectionString))
            {
                _configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionString, connectionString);
                int commandTimeout = PageHelper.GetConfigurationSettingsValue("CommandTimeout", 1800);
                _configuration.SetProperty(NHibernate.Cfg.Environment.CommandTimeout, commandTimeout.ToString());
            }
            using (var stream = new MemoryStream())
            {
                HbmSerializer.Default.Serialize(stream, System.Reflection.Assembly.Load("Macrowing.Portal.Platform.Core"));

#if DEBUG // 生成实体映射文件
                try
                {
                    using (var fileStream = File.Create(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Macrowing.Portal.Platform.Core.hbm.xml")))
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        stream.CopyTo(fileStream);
                    }
                }
                catch (Exception ex)
                {
                    EDoc2.Package.Log.LogManager.Error(ex.Message, ex.ToString());
                }
#endif

                stream.Position = 0;
                _configuration.AddInputStream(stream);
            }
        }