Exemplo n.º 1
0
        public async Task AddAsync <TEntity>(IEnumerable <TEntity> entities) where TEntity : class
        {
            PropertyDataValidator.Verify(this, entities);
            await GetCollectionEntity <TEntity>().InsertManyAsync(entities);

            DbCacheManager.Add(entities);
        }
Exemplo n.º 2
0
        public IHttpActionResult Main()
        {
            var body    = new RequestBody();
            var account = body.GetPostString("account");
            var mobile  = BaiRongDataProvider.UserDao.GetMobileByAccount(account);

            var    isSuccess = false;
            string errorMessage;

            if (string.IsNullOrEmpty(mobile) || !StringUtils.IsMobile(mobile))
            {
                errorMessage = "账号对应的用户未设置手机号码";
            }
            else
            {
                var code = StringUtils.GetRandomInt(1111, 9999);
                DbCacheManager.RemoveAndInsert($"SiteServer.API.Controllers.Users.SendSms.{mobile}.Code", code.ToString());
                isSuccess = SmsManager.SendVerify(mobile, code, ConfigManager.UserConfigInfo.FindPasswordSmsTplId, out errorMessage);
            }

            return(Ok(new
            {
                IsSuccess = isSuccess,
                Mobile = mobile,
                ErrorMessage = errorMessage
            }));
        }
Exemplo n.º 3
0
        public IHttpActionResult Main()
        {
            var body = new RequestBody();

            var mobile   = body.GetPostString("mobile");
            var password = body.GetPostString("password");
            var code     = body.GetPostString("code");

            var dbCode = DbCacheManager.GetValue($"SiteServer.API.Controllers.Users.SendSms.{mobile}.Code");

            var    isRegister = false;
            string errorMessage;

            if (code != dbCode)
            {
                errorMessage = "短信验证码不正确";
            }
            else
            {
                var userInfo = new UserInfo
                {
                    UserName = mobile,
                    Mobile   = mobile,
                    Password = password
                };
                isRegister = BaiRongDataProvider.UserDao.Insert(userInfo, PageUtils.GetIpAddress(), out errorMessage);
            }

            return(Ok(new {
                IsRegister = isRegister,
                ErrorMessage = errorMessage
            }));
        }
        public IHttpActionResult Main()
        {
            var body     = new RequestBody();
            var mobile   = body.GetPostString("mobile");
            var password = body.GetPostString("password");

            var isSms        = false;
            var isRegister   = false;
            var errorMessage = string.Empty;

            if (ConfigManager.UserConfigInfo.RegisterVerifyType == EUserVerifyType.Mobile)
            {
                var code = StringUtils.GetRandomInt(1111, 9999);
                DbCacheManager.RemoveAndInsert($"SiteServer.API.Controllers.Users.SendSms.{mobile}.Code", code.ToString());
                isSms = SmsManager.SendVerify(mobile, code, ConfigManager.UserConfigInfo.RegisterSmsTplId, out errorMessage);
            }

            if (!isSms)
            {
                var userInfo = new UserInfo
                {
                    UserName = mobile,
                    Mobile   = mobile,
                    Password = password
                };
                isRegister = BaiRongDataProvider.UserDao.Insert(userInfo, PageUtils.GetIpAddress(), out errorMessage);
            }

            return(Ok(new {
                IsSms = isSms,
                IsRegister = isRegister,
                ErrorMessage = errorMessage
            }));
        }
Exemplo n.º 5
0
        public override async Task AddAsync <TEntity>(TEntity entity)
        {
            PropertyDataValidator.Verify(this, entity);
            await GetCollectionEntity <TEntity>().InsertOneAsync(entity);

            DbCacheManager.Add(entity);
        }
Exemplo n.º 6
0
        public override async Task UpdateAsync <TEntity>(Expression <Func <TEntity, bool> > filter, TEntity entity)
        {
            PropertyDataValidator.Verify(this, entity);
            await GetCollectionEntity <TEntity>().ReplaceOneAsync(filter, entity);

            DbCacheManager.Update(entity, filter);
        }
Exemplo n.º 7
0
 public int QueryCount <TEntity>(Expression <Func <TEntity, bool> > filter) where TEntity : class
 {
     SqlGenerator.QueryCount(this, filter);
     return(DbCacheManager.GetCount(this, filter, () =>
     {
         return int.TryParse(Convert.ToString(DbHelper.ExecuteScalar(SqlStatement)), out int result) ? result : default(int);
     }));
 }
Exemplo n.º 8
0
 public TEntity QueryOne <TEntity>(Expression <Func <TEntity, bool> > filter) where TEntity : class
 {
     SqlGenerator.QueryOne(this, filter);
     return(DbCacheManager.GetEntity(this, filter, () =>
     {
         return DbHelper.ExecuteEntity <TEntity>(SqlStatement);
     }));
 }
Exemplo n.º 9
0
 public List <TEntity> QueryList <TEntity>(Expression <Func <TEntity, bool> > filter, Expression <Func <TEntity, object> > orderBy, bool isDESC = false) where TEntity : class
 {
     SqlGenerator.QueryOrderBy(this, filter, orderBy, isDESC);
     return(DbCacheManager.GetEntities(this, filter, () =>
     {
         return DbHelper.ExecuteList <TEntity>(SqlStatement);
     }));
 }
Exemplo n.º 10
0
 public override void Submit_OnClick(object sender, EventArgs e)
 {
     if (Page.IsPostBack && Page.IsValid)
     {
         CacheUtils.Clear();
         DbCacheManager.Clear();
         PageUtils.Redirect(PageUtils.GetSettingsUrl(nameof(PageCache), null));
     }
 }
        /// <summary>
        /// 刷新全部缓存区
        /// </summary>
        public void FlushAllCache()
        {
            if (DbCacheManager == null)
            {
                throw new InvalidOperationException("DbCacheManager is undefined, please define it first.");
            }

            DbCacheManager.FlushAllCache();
        }
        /// <summary>
        /// 刷新当前操作对象缓存区
        /// </summary>
        /// <param name="collectionName"></param>
        public void FlushCurrentCollectionCache(string collectionName = null)
        {
            if (DbCacheManager == null)
            {
                throw new InvalidOperationException("DbCacheManager is undefined, please define it first.");
            }

            DbCacheManager.FlushCurrentCollectionCache(collectionName);
        }
Exemplo n.º 13
0
 public void SaveTableNameCache(NameValueCollection nameValueCollection)
 {
     if (nameValueCollection != null && nameValueCollection.Count > 0)
     {
         var cacheKey   = GetTableNameNameValueCollectionDbCacheKey();
         var cacheValue = TranslateUtils.NameValueCollectionToString(nameValueCollection);
         DbCacheManager.RemoveAndInsert(cacheKey, cacheValue);
     }
 }
Exemplo n.º 14
0
        public NameValueCollection GetTableNameCache()
        {
            NameValueCollection nameValueCollection = null;
            var cacheValue = DbCacheManager.GetValue(GetTableNameNameValueCollectionDbCacheKey());

            if (!string.IsNullOrEmpty(cacheValue))
            {
                nameValueCollection = TranslateUtils.ToNameValueCollection(cacheValue);
            }
            return(nameValueCollection);
        }
Exemplo n.º 15
0
        public void AddAsync <TEntity>(TEntity entity) where TEntity : class
        {
            switch (DataBaseType)
            {
            case DataBaseType.MongoDB:
                GetCollectionEntity <TEntity>().InsertOneAsync(entity);
                break;

            default:
                break;
            }
            DbCacheManager.Add(this, entity);
        }
Exemplo n.º 16
0
        public void AddAsync <TEntity>(IEnumerable <TEntity> entities) where TEntity : class
        {
            switch (DataBaseType)
            {
            case DataBaseType.MongoDB:
                GetCollectionEntity <TEntity>().InsertManyAsync(entities);
                break;

            default:
                break;
            }
            DbCacheManager.Add(this, entities);
        }
Exemplo n.º 17
0
        public void DeleteAsync <TEntity>(Expression <Func <TEntity, bool> > filter) where TEntity : class
        {
            SqlStatement = filter.ToString();
            switch (DataBaseType)
            {
            case DataBaseType.MongoDB:
                GetCollectionEntity <TEntity>().DeleteManyAsync(filter);
                break;

            default:
                break;
            }
            DbCacheManager.Delete(this, filter);
        }
Exemplo n.º 18
0
        public void Update <TEntity>(Expression <Func <TEntity, bool> > filter, TEntity entity) where TEntity : class
        {
            SqlStatement = filter.ToString();
            switch (DataBaseType)
            {
            case DataBaseType.MongoDB:
                GetCollectionEntity <TEntity>().ReplaceOne(filter, entity);
                break;

            default:
                break;
            }
            DbCacheManager.Update(this, entity, filter);
        }
Exemplo n.º 19
0
        protected DbContext(string connectionString_Write, params string[] connectionStrings_Read)
        {
            if (string.IsNullOrEmpty(connectionString_Write))
            {
                throw new ArgumentNullException(nameof(connectionString_Write), "argument can not be null");
            }

            if (this.ConnectionManager == null)
            {
                this.ConnectionManager = new ConnectionManager(connectionString_Write, connectionStrings_Read);
            }

            DbCacheManager = new DbCacheManager(this);
        }
Exemplo n.º 20
0
        public int QueryCount <TEntity>(Expression <Func <TEntity, bool> > filter) where TEntity : class
        {
            SqlStatement = filter.ToString();
            return(DbCacheManager.GetCount(this, filter, () =>
            {
                switch (DataBaseType)
                {
                case DataBaseType.MongoDB:
                    return Convert.ToInt32(GetCollectionEntity <TEntity>().Count(filter));

                default:
                    break;
                }
                return default(int);
            }));
        }
Exemplo n.º 21
0
        public TEntity QueryOne <TEntity>(Expression <Func <TEntity, bool> > filter) where TEntity : class
        {
            SqlStatement = filter.ToString();
            return(DbCacheManager.GetEntity(this, filter, () =>
            {
                switch (DataBaseType)
                {
                case DataBaseType.MongoDB:
                    return QueryList(filter).FirstOrDefault();

                default:
                    break;
                }
                return default(TEntity);
            }));
        }
Exemplo n.º 22
0
        public List <TEntity> QueryList <TEntity>(Expression <Func <TEntity, bool> > filter) where TEntity : class
        {
            SqlStatement = filter.ToString();
            return(DbCacheManager.GetEntities(this, filter, () =>
            {
                switch (DataBaseType)
                {
                case DataBaseType.MongoDB:
                    return GetCollectionEntity <TEntity>().Find(filter).ToList();

                default:
                    break;
                }
                return default(List <TEntity>);
            }));
        }
Exemplo n.º 23
0
        public override int Delete <TEntity>(Expression <Func <TEntity, bool> > filter)
        {
            this.Parameters.Clear();
            this.ConnectionManager.SetConnectionString(OperationType.Write);
            this.DbConnection          = this.GetDbConnection(this.ConnectionManager.CurrentConnectionString);
            this.DbCommand.Connection  = this.DbConnection;
            this.DbCommand.CommandType = CommandType.Text;
            this.CommandTextGenerator.Delete(filter);
            this.TableName = GetTableName <TEntity>();

            this.DBTransaction.SyncCommandTransaction();

            int res = this.QueryExecutor.ExecuteNonQuery(this);

            DbCacheManager.Delete(filter);
            return(res);
        }
Exemplo n.º 24
0
        public override async Task <int> DeleteAsync <TEntity>(TEntity entity)
        {
            this.Parameters.Clear();
            this.ConnectionManager.SetConnectionString(OperationType.Write);
            this.DbConnection          = this.GetDbConnection(this.ConnectionManager.CurrentConnectionString);
            this.DbCommand.Connection  = this.DbConnection;
            this.DbCommand.CommandType = CommandType.Text;
            this.CommandTextGenerator.Delete(entity);
            this.TableName = GetTableName <TEntity>();

            this.DBTransaction.SyncCommandTransaction();

            int res = await this.QueryExecutor.ExecuteNonQueryAsync(this);

            DbCacheManager.Delete(entity);
            return(res);
        }
Exemplo n.º 25
0
        public void AddAsync <TEntity>(IEnumerable <TEntity> entities) where TEntity : class
        {
            List <BatchExecuteModel> batchExecuteModels = new List <BatchExecuteModel>();

            foreach (var item in entities)
            {
                SqlGenerator.Add(this, item, out Dictionary <string, object> paramsDic);

                batchExecuteModels.Add(new BatchExecuteModel
                {
                    CommandTextOrSpName = SqlStatement,
                    ParamsDic           = paramsDic
                });
            }
            DbHelper.BatchExecuteNonQueryAsync(batchExecuteModels);
            DbCacheManager.Add(this, entities);
        }
Exemplo n.º 26
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            if (!IsPostBack)
            {
                BreadCrumbSettings(AppManager.Settings.LeftMenu.Utility, "系统缓存", AppManager.Settings.Permission.SettingsUtility);

                CacheCount      = CacheUtils.GetCacheCount() + DbCacheManager.GetCount();
                CacheSize       = 100 - CacheUtils.GetCacheEnabledPercent();
                CachePercentStr = $@"<div style=""width:230px;"" class=""progress progress-success progress-striped"">
            <div class=""bar"" style=""width: {100 - CacheUtils.GetCacheEnabledPercent()}%""></div><span>&nbsp;{CacheSize +"%"}</span>
          </div>";
            }
        }
Exemplo n.º 27
0
        public void SmsCode_OnClick(object sender, EventArgs e)
        {
            var smsCode  = TbSmsCode.Text;
            var userName = ViewState["UserName"];
            var code     = DbCacheManager.GetValueAndRemove($"BaiRong.BackgroundPages.FrameworkFindPwd.{userName}.Code");

            if (smsCode != code)
            {
                LtlMessage.Text = GetMessageHtml("找回密码错误:短信验证码不正确", true);
                return;
            }

            LtlPageTitle.Text            = "重设密码";
            LtlMessage.Text              = string.Empty;
            PhStepAccount.Visible        = false;
            PhStepSmsCode.Visible        = false;
            PhStepChangePassword.Visible = true;
        }
Exemplo n.º 28
0
        public List <TEntity> QueryListPaging <TEntity>(int pageIndex, int pageSize, Expression <Func <TEntity, object> > orderBy, Expression <Func <TEntity, bool> > filter, bool isDESC = false) where TEntity : class
        {
            if (pageIndex <= 0)
            {
                pageIndex = 1;
            }

            if (pageSize <= 0)
            {
                pageSize = 10;
            }

            SqlGenerator.QueryPaging(this, pageIndex, pageSize, filter, orderBy, isDESC);
            return(DbCacheManager.GetEntities(this, filter, () =>
            {
                return DbHelper.ExecuteList <TEntity>(SqlStatement);
            }));
        }
Exemplo n.º 29
0
        public override int Add <TEntity>(TEntity entity)
        {
            PropertyDataValidator.Verify <TEntity>(this, entity);

            this.Parameters.Clear();
            this.ConnectionManager.SetConnectionString(OperationType.Write);
            this.DbConnection          = this.GetDbConnection(this.ConnectionManager.CurrentConnectionString);
            this.DbCommand.Connection  = this.DbConnection;
            this.DbCommand.CommandType = CommandType.Text;
            this.CommandTextGenerator.Add(entity);
            this.TableName = GetTableName <TEntity>();

            this.DBTransaction.SyncCommandTransaction();

            int res = this.QueryExecutor.ExecuteNonQuery(this);

            DbCacheManager.Add(entity);
            return(res);
        }
Exemplo n.º 30
0
        public static void SetServiceOnline(bool isOnline)
        {
            if (isOnline)
            {
                var cacheValue = CacheManager.GetCache(CacheKeyStatus) as string;
                if (TranslateUtils.ToBool(cacheValue))
                {
                    return;
                }

                DbCacheManager.RemoveAndInsert(CacheKeyStatus, DateTime.Now.ToString(CultureInfo.InvariantCulture));
                CacheManager.SetCache(CacheKeyStatus, true.ToString(), DateTime.Now.AddMinutes(10));
            }
            else
            {
                DbCacheManager.GetValueAndRemove(CacheKeyStatus);
                ClearStatusCache();
                ClearIsPendingCreateCache();
                ClearTaskCache();
            }
        }