Beispiel #1
0
        /// <summary>
        /// 监听
        /// </summary>
        /// <param name="methodName"></param>
        private static void MonitorResult(Func <ILogger, ISerializer, ResponseCommon> methodName)
        {
            while (true)
            {
                Thread.Sleep(sleepTime);
                Stopwatch watch = new Stopwatch();

                ResponseCommon result = new ResponseCommon();
                try
                {
                    watch.Start();

                    string redisContent = string.Empty;
                    result = methodName(m_ilogger, m_serializer);
                    ConsoleColor msgColor = ConsoleColor.White;
                    if (!result.IsSuccess)
                    {
                        msgColor = ConsoleColor.White;
                    }
                    else
                    {
                        msgColor = ConsoleColor.Green;
                    }

                    watch.Stop();

                    messageQueue.Enqueue(new WriteMessage()
                    {
                        ShowColor = msgColor, ShowText = $"[{result.MsgType}]-[耗时:{ watch.Elapsed.TotalMilliseconds}]{result.MessageContent}"
                    });


                    //==========压力测试代码==========
                    if (result.IsSuccess)
                    {
                        StackExchange.Redis.IDatabase db = BaseConnect.RedisHelper.GetDatabase(8);
                        db.ListRightPush("test:" + result.MessageContent.Substring(0, 7), "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "]处理" + result.MsgType + "业务:" + result.MessageContent);

                        if (result.MsgType == MsgType.InParking)
                        {
                            //入场成功后,再记录数据到出场车牌列表(以便执行出场业务)
                            db.ListRightPush("ExitDataList", result.RedisContent);
                        }
                    }

                    //==========压力测试代码==========
                }
                catch (Exception ex)
                {
                    m_ilogger.LogFatal(LoggerLogicEnum.Tools, "", "", "", "Fujica.com.cn.MonitorServiceClient.MonitorResult", $"执行{result.MsgType}数据发生异常;参数:{result.RedisContent}", ex.ToString());

                    messageQueue.Enqueue(new WriteMessage()
                    {
                        ShowColor = ConsoleColor.Yellow, ShowText = $"[{result.MsgType}]-[{DateTime.Now}]系统发生异常,redis数据:{result.RedisContent};系统异常:{ex.ToString()}"
                    });
                }
            }
        }
Beispiel #2
0
        public long AddListItem(string key, StackExchange.Redis.RedisValue value, string value_ttl)
        {
            if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value_ttl))
            {
                throw new ArgumentException("Parameter is invalid.", "key or value_ttl", null);
            }
            if (value == StackExchange.Redis.RedisValue.Null || value == StackExchange.Redis.RedisValue.EmptyString)
            {
                throw new ArgumentException("Parameter is invalid.", "value", null);
            }

            try
            {
                StackExchange.Redis.RedisValue[] _v = new StackExchange.Redis.RedisValue[2];
                _v[0] = value_ttl;
                _v[1] = value;
                return(_db.ListRightPush(key, _v));
            }
            catch (Exception)
            {
                throw;
            }
            finally
            { }
        }
Beispiel #3
0
        public User Authentzicate(string username, string password)
        {
            string      sqlConnectionString = @"Data Source = ERP-CONGLT\SQLEXPRESS; Initial Catalog = QuanLySanPham; Integrated Security = True";
            var         connection          = new SqlConnection(sqlConnectionString);
            List <User> listuser            = new List <User>();

            connection.Open();
            listuser = connection.Query <User>("Select username,password,type from Login").ToList();
            connection.Close();

            var user = listuser.SingleOrDefault(x => x.Username == username && x.Password == password);

            if (user == null)
            {
                return(null);
            }

            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(_appSettings.Secret);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Role, user.Type),
                }),
                Expires            = DateTime.UtcNow.AddDays(7),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token = tokenHandler.CreateToken(tokenDescriptor);

            user.Token = tokenHandler.WriteToken(token);
            string fullbearer = tokenHandler.WriteToken(token);
            var    allHash    = _database.ListRightPush("mylist", fullbearer);

            return(user.WithoutPassword());
        }