示例#1
0
        /// <summary>
        /// 保存模块数据库配置
        /// </summary>
        /// <param name="dbConfig">配置对象</param>
        /// <returns></returns>
        private string SaveModuleDbConfig(Sys_DbConfig dbConfig)
        {
            string errMsg = string.Empty;

            if (dbConfig != null)
            {
                try
                {
                    string tableName = string.Empty;
                    BaseDAL <Sys_Module> moduleDal = new BaseDAL <Sys_Module>(this.CurrUser);
                    Sys_Module           module    = moduleDal.GetEntityById(out errMsg, dbConfig.Id);
                    if (module == null || string.IsNullOrEmpty(module.TableName))
                    {
                        tableName = tableIdDic.Where(x => x.Value == dbConfig.Id).FirstOrDefault().Key;
                    }
                    else
                    {
                        tableName = module.TableName;
                    }
                    if (string.IsNullOrWhiteSpace(tableName))
                    {
                        return("找不到模块表!");
                    }
                    string modelConfigPath = ModelConfigHelper.GetModelConfigXml();
                    string node            = string.Format("/Root/{0}", tableName);
                    bool   nodeIsExists    = XmlHelper.NodeIsExists(modelConfigPath, node);
                    if (!nodeIsExists) //不存在实体节点配置信息,插入节点
                    {
                        XmlHelper.Insert(modelConfigPath, "/Root", tableName, string.Empty, string.Empty);
                    }
                    XmlHelper.Update(modelConfigPath, node, "AutomaticPartition", dbConfig.AutomaticPartition ? "1" : "0");
                    XmlHelper.Update(modelConfigPath, node, "AutoReCreateIndex", dbConfig.AutoReCreateIndex ? "1" : "0");
                    XmlHelper.Update(modelConfigPath, node, "CreateIndexPageDensity", dbConfig.CreateIndexPageDensity.ObjToStr());
                    XmlHelper.Update(modelConfigPath, node, "readConnString", dbConfig.ReadConnString);
                    XmlHelper.Update(modelConfigPath, node, "writeConnString", dbConfig.WriteConnString);
                    TempDatabaseType dbType = (TempDatabaseType)Enum.Parse(typeof(DatabaseType), dbConfig.DbType.ToString());
                    XmlHelper.Update(modelConfigPath, node, "dbType", dbType.ToString());
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                }
            }
            return(errMsg);
        }
示例#2
0
        /// <summary>
        /// 从xml配置文件中获取模块缓存配置
        /// </summary>
        /// <param name="tableName">模块表名或类名</param>
        /// <param name="moduleName">模块名称</param>
        /// <param name="moduleId">模块ID</param>
        /// <returns></returns>
        private Sys_DbConfig GetModuleCacheConfig(string tableName, string moduleName = null, Guid?moduleId = null)
        {
            //将未添加到模块表中的模块也加进来
            List <Type> modelTypes = GetAllModelTypes();
            Type        modelType  = modelTypes.Where(x => x.Name == tableName).FirstOrDefault();
            Guid        id         = Guid.Empty;

            if (!moduleId.HasValue)
            {
                if (!tableIdDic.ContainsKey(tableName))
                {
                    Guid tempId = Guid.NewGuid();
                    tableIdDic.Add(tableName, tempId);
                    id = tempId;
                }
                else
                {
                    id = tableIdDic[tableName];
                }
            }
            else
            {
                id = moduleId.Value;
            }
            Sys_DbConfig dbConfig = new Sys_DbConfig()
            {
                Id         = id,
                ModuleName = string.IsNullOrEmpty(moduleName) ? tableName : moduleName
            };

            if (modelType == null)
            {
                return(dbConfig);
            }
            string dbTypeStr = WebConfigHelper.GetAppSettingValue("DbType");

            if (string.IsNullOrEmpty(dbTypeStr))
            {
                dbTypeStr = "0";
            }
            TempDatabaseType dbType        = (TempDatabaseType)Enum.Parse(typeof(TempDatabaseType), dbTypeStr);
            string           tempDbTypeStr = string.Empty;
            string           readConnStr   = ModelConfigHelper.GetModelConnString(modelType, out tempDbTypeStr);
            string           writeConnStr  = ModelConfigHelper.GetModelConnString(modelType, out tempDbTypeStr, false);

            if (tempDbTypeStr != string.Empty) //实体配置了数据库类型
            {
                try
                {
                    dbType = (TempDatabaseType)Enum.Parse(typeof(DatabaseType), tempDbTypeStr);
                }
                catch { }
            }
            dbConfig.DbTypeOfEnum    = dbType;
            dbConfig.ReadConnString  = readConnStr;
            dbConfig.WriteConnString = writeConnStr;
            string modelConfigPath = ModelConfigHelper.GetModelConfigXml();
            string node            = string.Format("/Root/{0}", tableName);
            bool   nodeIsExists    = XmlHelper.NodeIsExists(modelConfigPath, node);

            if (!nodeIsExists) //不存在实体节点配置信息,找对应基类的节点配置信息
            {
                //取实体基类
                Type baseType = modelType.BaseType;
                if (baseType != null)                                         //存在基类
                {
                    node         = string.Format("/Root/{0}", baseType.Name); //基类节点
                    nodeIsExists = XmlHelper.NodeIsExists(modelConfigPath, node);
                }
            }
            if (!nodeIsExists)
            {
                return(dbConfig);
            }
            string autoReCreateIndex      = XmlHelper.Read(modelConfigPath, node, "AutoReCreateIndex");      //是否自动重建索引
            string createIndexPageDensity = XmlHelper.Read(modelConfigPath, node, "CreateIndexPageDensity"); //重建索引页密度
            string automaticPartition     = XmlHelper.Read(modelConfigPath, node, "AutomaticPartition");     //是否自动分区
            string partitionInterval      = XmlHelper.Read(modelConfigPath, node, "PartitionInterval");      //分区间隔记录数

            dbConfig.AutoReCreateIndex      = autoReCreateIndex.ObjToInt() == 1;
            dbConfig.CreateIndexPageDensity = createIndexPageDensity.ObjToInt();
            dbConfig.AutomaticPartition     = automaticPartition.ObjToInt() == 1;
            dbConfig.PartitionInterval      = partitionInterval.ObjToInt();
            return(dbConfig);
        }