コード例 #1
0
        protected void Application_Start()
        {
            AutofacBootstrap.CoreAutoFacInit();
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //            JobConfig.JobRegister();


            int minWorker, minIOC;

            ThreadPool.GetMinThreads(out minWorker, out minIOC);
            LogDbHelper.LogInfo($"线程池最大工作线程数-{minWorker}/IO线程数-${minIOC}", "Global => Application_Start", OperationType.Other);
            if (ThreadPool.SetMinThreads(LsConstant.ThreadPoolCount, LsConstant.ThreadPoolCount))
            {
                LogDbHelper.LogInfo("设置线程池最大工作线程数/IO线程数成功", "Global => Application_Start", OperationType.Other);
            }
            else
            {
                LogDbHelper.LogError("设置线程池最大工作线程数/IO线程数成功", "Global => Application_Start", OperationType.Other);
            }

            JobScheduler.Start();
            AutoMapperConfig.RegisterMappings();

            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(Server.MapPath("log4net.config")));
        }
コード例 #2
0
        public IList <LotteryData> RequestNewDatas()
        {
            if (_iscrawlingData)
            {
                return(null);
            }
            _iscrawlingData = true;

            try
            {
                LogDbHelper.LogDebug("正在从" + _dataSite.Name + "爬取数据", GetType().FullName + "=>RequestNewDatas", OperationType.Job);
                var dataList = CrawNewDatas();
                if (dataList.Count <= 0)
                {
                    LogDbHelper.LogDebug("从" + _dataSite.Name + "爬取数据失败,没有获取到最新的数据", GetType().FullName + "=>RequestNewDatas", OperationType.Job);
                }
                else
                {
                    LogDbHelper.LogDebug("从" + _dataSite.Name + "爬取数据成功,共爬取到" + dataList.Count + "条数据", GetType().FullName + "=>RequestNewDatas", OperationType.Job);
                }

                return(dataList);
            }
            catch (Exception e)
            {
                LogDbHelper.LogError("从" + _dataSite.Name + "爬取数据失败,原因" + e.Message, GetType().FullName + "=>RequestNewDatas", OperationType.Job);
                return(null);
            }
            finally
            {
                _iscrawlingData = false;
            }
        }
コード例 #3
0
        public void InsertUserPlans(string userId, LotteryType lotteryType, UserBasicNorm userBasicNorm, IList <int> planIds)
        {
            string sqlStr1 = "INSERT INTO [dbo].[LotteryAnalyseNorms]([Id],[PlanId],[PlanCycle],[LastStartPeriod],[ForecastCount],[BasicHistoryCount] ,[UnitHistoryCount],[HotWeight],[SizeWeight]" +
                             " ,[ThreeRegionWeight],[MissingValueWeight],[OddEvenWeight],[Modulus],[LotteryType],[Enable],[IsDefault],[CreatTime],[CreateUserId])" +
                             " VALUES(@Id, @PlanId, @PlanCycle, @LastStartPeriod, @ForecastCount, @BasicHistoryCount, @UnitHistoryCount, @HotWeight, @SizeWeight, @ThreeRegionWeight, @MissingValueWeight" +
                             ", @OddEvenWeight, @Modulus, @LotteryType, @ENABLE, @IsDefault, GETDATE(), @CreateUserId)";
            string sqlStr2 = "INSERT INTO [dbo].[UserAnylseNorms]([Id],[UserId],[PlanId],[LotteryAnalyseNormId],[LotteryType],[CreatTime])" +
                             " VALUES(@Id, @UserId,@PlanId, @LotteryAnalyseNormId, @LotteryType, GETDATE())";

            using (var cn = LotteryDbConnection)
            {
                cn.Open();
                using (var trans = cn.BeginTransaction())
                {
                    try
                    {
                        foreach (var planId in planIds)
                        {
                            var lotteryAnalyseNorm = new LotteryAnalyseNorm()
                            {
                                PlanId             = planId,
                                BasicHistoryCount  = userBasicNorm.BasicHistoryCount,
                                CreateUserId       = userId,
                                ForecastCount      = userBasicNorm.ForecastCount,
                                HotWeight          = userBasicNorm.HotWeight,
                                LastStartPeriod    = 0, // Todo: set LastStartPeriod
                                LotteryType        = lotteryType.ToString(),
                                UnitHistoryCount   = userBasicNorm.UnitHistoryCount,
                                Modulus            = userBasicNorm.Modulus,
                                OddEvenWeight      = userBasicNorm.OddEvenWeight,
                                MissingValueWeight = userBasicNorm.MissingValueWeight,
                                ThreeRegionWeight  = userBasicNorm.ThreeRegionWeight,
                                SizeWeight         = userBasicNorm.SizeWeight,
                                PlanCycle          = userBasicNorm.PlanCycle,
                            };
                            var userAnalyseNorm = new UserAnylseNorm()
                            {
                                LotteryAnalyseNormId = lotteryAnalyseNorm.Id,
                                LotteryType          = lotteryType.ToString(),
                                UserId = userId,
                                PlanId = planId,
                            };

                            cn.Execute(sqlStr1, lotteryAnalyseNorm, trans);
                            cn.Execute(sqlStr2, userAnalyseNorm, trans);
                        }
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        LogDbHelper.LogError(ex, GetType() + "=>InsertUserPlans");
                        throw ex;
                    }
                }
            }
        }
コード例 #4
0
        protected void Application_End()
        {
            LogDbHelper.LogWarn("应用停止,IIS将应用回收", "Global => Application_End", OperationType.Other);

            Thread.Sleep(1000);

            try
            {
                //这里设置你的web地址,可以随便指向你的任意一个aspx页面甚至不存在的页面,目的是要激发Application_Start
                string          url = Utils.GetConfigValuesByKey("EndAppTriggerRestartUrl");
                HttpWebRequest  myHttpWebRequest  = (HttpWebRequest)WebRequest.Create(url);
                HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
                Stream          receiveStream     = myHttpWebResponse.GetResponseStream();//得到回写的字节流
                LogDbHelper.LogWarn("App Restart Success", "Global => Application_End", OperationType.Other);
            }
            catch (Exception ex)
            {
                LogDbHelper.LogError("App Restart Failure" + ex.Message, "Global => Application_End", OperationType.Other);
            }
        }
コード例 #5
0
        public LotteryData Insert(LotteryData newData)
        {
            var redisKey = AppUtils.GetLotteryRedisKey(newData.LotteryType, LsConstant.LotteryDataCacheKey);

            try
            {
                CacheHelper.AddCacheListItem(redisKey, newData);
                if (CacheHelper.GetCache <IList <LotteryData> >(redisKey).Count >= LsConstant.LOAD_HISTORY_LOTTERYDATA)
                {
                    //var mostOldLottery = RedisHelper.GetAll<LotteryData>(redisKey).Last();
                    //RedisHelper.RemoveList(redisKey, mostOldLottery);
                }
            }
            catch (Exception ex)
            {
                LogDbHelper.LogError(ex, GetType() + "UpdateLotteryDataCache");
                throw ex;
            }

            var lotteryDataId = _lotteryDapperService.Add(newData);

            return(CacheHelper.GetCache <IList <LotteryData> >(redisKey).First(p => p.Id == newData.Id));
        }
コード例 #6
0
ファイル: LoginManager.cs プロジェクト: szp11/LotteryService
        public LoginResult Login(string accountName, string password)
        {
            var userInfo = ((IUserDapperRepository)_dapperRepository).GetUserByAccountName(accountName);

            LoginResult     loginResult = null;
            LoginResultType loginResultType;

            // 1. 判断是否存在用户
            if (userInfo == null)
            {
                loginResultType = LoginResultType.InvalidUserNameAccount;
                loginResult     = new LoginResult(loginResultType);
                LogDbHelper.LogWarn("登录失败,不存在用户{0}", GetType().FullName + "Login", OperationType.Account);
                return(loginResult);
            }

            // 2. 判断密码是否正确
            else if (!AppUtils.VerifyPassword(accountName, password, userInfo.Password, userInfo.UserRegistType))
            {
                loginResultType = LoginResultType.InvalidPassword;
                loginResult     = new LoginResult(loginResultType);
            }
            // 3. 判断用户状态是否被激活
            else if (!userInfo.IsActive)
            {
                loginResultType = LoginResultType.UserIsNotActive;
                loginResult     = new LoginResult(loginResultType);
            }
            // 4.判断用户是否已经登录,如果登录了,提示用户不要重复登录
            //else if (!string.IsNullOrWhiteSpace(userInfo.TokenId))
            //{
            //    loginResultType = LoginResultType.UserAlreadyLogged;
            //    loginResult = new LoginResult(loginResultType);
            //}
            else
            {
                loginResult = new LoginResult(userInfo, accountName, userInfo.UserRegistType);
            }
            try
            {
                if (loginResult.ResultType != LoginResultType.Success)
                {
                    ((IUserDapperRepository)_dapperRepository).LoginFail(userInfo.Id, accountName, loginResult.ResultType);
                    LogDbHelper.LogWarn("登录失败, 原因:" + loginResult.LoginResultMsg, GetType().FullName + "Login", OperationType.Account);
                }
                else
                {
                    ((IUserDapperRepository)_dapperRepository).LoginSuccess(userInfo.Id, accountName, loginResult.ResultType,
                                                                            loginResult.TokenId, loginResult.LoginTime);
                    // :todo 缓存TokenId
                    LogDbHelper.LogInfo(loginResult.LoginResultMsg, GetType().FullName + "Login", OperationType.Account);
                }
            }
            catch (Exception ex)
            {
                ((IUserDapperRepository)_dapperRepository).LoginFail(userInfo.Id, accountName, loginResult.ResultType);
                LogDbHelper.LogError("登录失败, 原因:" + ex.ToString(), GetType().FullName + "Login", OperationType.Account);
                loginResult = new LoginResult(ex);
            }

            return(loginResult);
        }
コード例 #7
0
        public void UpdateUserPlans(string userId, LotteryType lotteryType, UserBasicNorm userBasicNorm, IList <int> planIds,
                                    IList <int> userOldLotteryPlanIds)
        {
            string sqlStr1 = "SELECT * FROM [dbo].[UserAnylseNorms] WHERE UserId=@UserId AND LotteryType=@LotteryType AND PlanId=@PlanId";
            string sqlStr2 = "INSERT INTO [dbo].[UserAnylseNorms]([Id],[UserId],[PlanId],[LotteryAnalyseNormId],[LotteryType],[CreatTime])" +
                             " VALUES(@Id, @UserId,@PlanId, @LotteryAnalyseNormId, @LotteryType, GETDATE())";

            string sqlStr2_1 = "INSERT INTO [dbo].[LotteryAnalyseNorms]([Id],[PlanId],[PlanCycle],[LastStartPeriod],[ForecastCount],[BasicHistoryCount] ,[UnitHistoryCount],[HotWeight],[SizeWeight]" +
                               " ,[ThreeRegionWeight],[MissingValueWeight],[OddEvenWeight],[Modulus],[LotteryType],[Enable],[IsDefault],[CreatTime],[CreateUserId])" +
                               " VALUES(@Id, @PlanId, @PlanCycle, @LastStartPeriod, @ForecastCount, @BasicHistoryCount, @UnitHistoryCount, @HotWeight, @SizeWeight, @ThreeRegionWeight, @MissingValueWeight" +
                               ", @OddEvenWeight, @Modulus, @LotteryType, @ENABLE, @IsDefault, GETDATE(), @CreateUserId)";

            string sqlStr3 = "SELECT * FROM [dbo].[LotteryAnalyseNorms] WHERE Id=@Id";

            string sqlStr4 = "DELETE [dbo].[UserAnylseNorms] WHERE Id = @Id";

            string sqlStr5 = "UPDATE [dbo].[LotteryAnalyseNorms]" +
                             "SET [LastStartPeriod] = @LastStartPeriod" +
                             ",[Enable] = @Enable" +
                             ",[ModifyTime] = GETDATE()" +
                             " WHERE [Id] = @Id";

            string lotteryAnalyseNormHashKey = string.Format(LsConstant.LotteryAnalyseNormRedisKey, lotteryType);

            using (var cn = LotteryDbConnection)
            {
                cn.Open();
                using (var trans = cn.BeginTransaction())
                {
                    try
                    {
                        // 1. 遍历更改的planIds
                        foreach (var planId in planIds)
                        {
                            var userAnylseNorm = cn.QuerySingleOrDefault <UserAnylseNorm>(sqlStr1, new
                            {
                                UserId      = userId,
                                LotteryType = lotteryType.ToString(),
                                PlanId      = planId,
                            }, trans);
                            // 如果用户还没有添加过该计划
                            if (userAnylseNorm == null)
                            {
                                #region 用户没有添加过该计划

                                var lotteryAnalyseNorm = new LotteryAnalyseNorm()
                                {
                                    PlanId             = planId,
                                    BasicHistoryCount  = userBasicNorm.BasicHistoryCount,
                                    CreateUserId       = userId,
                                    ForecastCount      = userBasicNorm.ForecastCount,
                                    HotWeight          = userBasicNorm.HotWeight,
                                    LastStartPeriod    = 0, // Todo: set LastStartPeriod
                                    LotteryType        = lotteryType.ToString(),
                                    UnitHistoryCount   = userBasicNorm.UnitHistoryCount,
                                    Modulus            = userBasicNorm.Modulus,
                                    OddEvenWeight      = userBasicNorm.OddEvenWeight,
                                    MissingValueWeight = userBasicNorm.MissingValueWeight,
                                    ThreeRegionWeight  = userBasicNorm.ThreeRegionWeight,
                                    SizeWeight         = userBasicNorm.SizeWeight,
                                    PlanCycle          = userBasicNorm.PlanCycle,
                                };

                                userAnylseNorm = new UserAnylseNorm()
                                {
                                    LotteryAnalyseNormId = lotteryAnalyseNorm.Id,
                                    LotteryType          = lotteryType.ToString(),
                                    UserId = userId,
                                    PlanId = planId,
                                };
                                cn.Execute(sqlStr2_1, lotteryAnalyseNorm, trans);
                                cn.Execute(sqlStr2, userAnylseNorm, trans);

                                RedisHelper.SetHash(lotteryAnalyseNormHashKey, lotteryAnalyseNorm.Id,
                                                    lotteryAnalyseNorm);
                                #endregion
                            }
                            else
                            {
                                #region 用户添加过该计划

                                var lotteryAnalyseNorm = cn.QuerySingle <LotteryAnalyseNorm>(sqlStr3, new
                                {
                                    Id = userAnylseNorm.LotteryAnalyseNormId
                                }, trans);
                                if (!lotteryAnalyseNorm.Enable)
                                {
                                    lotteryAnalyseNorm.Enable          = true;
                                    lotteryAnalyseNorm.ModifyTime      = DateTime.Now;
                                    lotteryAnalyseNorm.LastStartPeriod = 0;  // Todo: set LastStartPeriod

                                    cn.Execute(sqlStr5, new
                                    {
                                        lotteryAnalyseNorm.Id,
                                        lotteryAnalyseNorm.Enable,
                                        LatestStartPeriod = lotteryAnalyseNorm.LastStartPeriod
                                    }, trans);

                                    RedisHelper.SetHash(lotteryAnalyseNormHashKey, lotteryAnalyseNorm.Id,
                                                        lotteryAnalyseNorm);
                                }

                                #endregion
                            }
                        }
                        // 2. 将旧计划且当前没有选的计划移除

                        #region 将旧计划且当前没有选的计划移除

                        foreach (var oldPlanId in userOldLotteryPlanIds)
                        {
                            if (planIds.Contains(oldPlanId))
                            {
                                continue;
                            }
                            var userAnylseNorm = cn.QuerySingleOrDefault <UserAnylseNorm>(sqlStr1, new
                            {
                                UserId      = userId,
                                LotteryType = lotteryType.ToString(),
                                PlanId      = oldPlanId,
                            }, trans);

                            if (userAnylseNorm != null)
                            {
                                cn.Execute(sqlStr4, new
                                {
                                    Id = userAnylseNorm.Id
                                }, trans);

                                #region 修改LotteryAnalyseNorm 指标

                                var lotteryAnalyseNorm = cn.QuerySingle <LotteryAnalyseNorm>(sqlStr3, new
                                {
                                    Id = userAnylseNorm.LotteryAnalyseNormId
                                }, trans);
                                if (lotteryAnalyseNorm.Enable)
                                {
                                    lotteryAnalyseNorm.Enable          = false;
                                    lotteryAnalyseNorm.LastStartPeriod = 0;  // Todo: set LastStartPeriod

                                    cn.Execute(sqlStr5, new
                                    {
                                        lotteryAnalyseNorm.Id,
                                        lotteryAnalyseNorm.Enable,
                                        LatestStartPeriod = lotteryAnalyseNorm.LastStartPeriod
                                    }, trans);

                                    RedisHelper.Remove(lotteryAnalyseNormHashKey, lotteryAnalyseNorm.Id);
                                }

                                #endregion
                            }
                        }

                        #endregion

                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        LogDbHelper.LogError(ex, GetType().FullName + "UpdateUserPlans");
                        trans.Rollback();
                        throw ex;
                    }
                }
            }
        }