Ejemplo n.º 1
0
        public RespondCompanyInfoViewModel GetCompanyInfoViewModel(RequestCompanyInfoViewModel request)
        {
            var respond = MemcacheHelper.Get(() =>
            {
                var filePath = BuildConnectionFilePath.BuildFilePath(request.CompanyID);
                var _respond = new RespondCompanyInfoViewModel();
                if (ExistsFileHelper.ExistsFile(filePath))
                {
                    var connectionConfig = ConfigHelper.GetConfig <DbConnectionConfig>(filePath);
                    _respond             = new RespondCompanyInfoViewModel
                    {
                        CompanyID      = request.CompanyID,
                        ConnectTimeout = connectionConfig.ConnectTimeout,
                        Database       = connectionConfig.Database,
                        Password       = connectionConfig.Password,
                        Server         = connectionConfig.Server,
                        UserID         = connectionConfig.UserID
                    };
                    return(_respond);
                }

                var parameter = new CompanyInfoParameter
                {
                    CompanyID = request.CompanyID
                };
                var dataModel = this.mCompanyInfoDataAccess.GetCompanyInfoDataModelByID(parameter);
                if (dataModel == null)
                {
                    return(_respond);
                }
                _respond = new RespondCompanyInfoViewModel
                {
                    CompanyID      = dataModel.comid,
                    ConnectTimeout = dataModel.timeout,
                    Database       = dataModel.dbase,
                    Password       = dataModel.pwd,
                    Server         = dataModel.dbserver,
                    UserID         = dataModel.uid
                };
                var _DbconnectionConfig = new DbConnectionConfig
                {
                    ConnectTimeout = dataModel.timeout,
                    Database       = dataModel.dbase,
                    Password       = dataModel.pwd,
                    Server         = dataModel.dbserver,
                    UserID         = dataModel.uid
                };
                ConfigHelper.Save(_DbconnectionConfig, filePath);
                return(_respond);
            }, string.Format(preCachedKey, "GetCompanyInfoViewModel"), false, request.CompanyID);

            return(respond);
        }
Ejemplo n.º 2
0
        public MongoDbBaseDataAccess()
        {
            var user     = CPSSAuthenticate.GetCurrentUser();
            var filePath = "~/config/mongodbconfig.config";

            if (user != null)
            {
                filePath = string.Format("~/config/{0}/mongodbconfig.config", user.CompanySerialNum);
                if (!ExistsFileHelper.ExistsFile(filePath))
                {
                    var config = new MongoDbConfig
                    {
                        Server   = WebConfigHelper.GetMongoDbServer(),
                        Database = string.Format("MongoDbLog_{0}", user.CompanySerialNum)
                    };
                    ConfigHelper.Save(config, filePath);
                }
            }
            //if (!ExistsFileHelper.ExistsFile(filePath)) throw new Exception("MongoDb库连接配置文件不存在。");
            var mongoDbConfig = ConfigHelper.GetConfig <MongoDbConfig>(filePath);

            this.InitMongoDataBase(mongoDbConfig.Server, mongoDbConfig.Database);
        }