Esempio n. 1
0
            public async Task <Result <ulong, QueryStatus> > Handle(Command request, CancellationToken cancellationToken)
            {
                var guild = await _context.Guilds
                            .Include(x => x.CustomPrefixes)
                            .FirstOrDefaultAsync(g => g.Id == request.GuildId);

                if (guild is null)
                {
                    return(QueryResult <ulong> .NotFound());
                }

                var prefix = new CustomPrefix()
                {
                    GuildId = request.GuildId,
                    Prefix  = request.Prefix
                };

                guild.CustomPrefixes.Clear();
                guild.CustomPrefixes.Add(prefix);

                await _context.SaveChangesAsync();

                // Clear the prefixes from the cache we fetch new values on the next message
                await _mediator.Send(new ClearCustomPrefixRequest { Id = request.GuildId });

                return(QueryResult <ulong> .Success(request.GuildId));
            }
Esempio n. 2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public SerialIdDetailResultData(FixedPrefix fixedPrefix, CustomPrefix customPrefix, DateTime createDateTime, string ip, int random)
 {
     FixedPrefix    = fixedPrefix;
     CustomPrefix   = customPrefix;
     CreateDateTime = createDateTime;
     Ip             = ip;
     Random         = random;
 }
Esempio n. 3
0
        public BCommands() : base()
        {
            _prefix = new CustomPrefix("b.");
            BeatCommands     beat     = new BeatCommands();
            CampaignCommands campaign = new CampaignCommands();
            BoardCommands    board    = new BoardCommands();

            COMMAND_TYPES.Add(_prefix._prefix, GetType());
            COMMAND_TYPES.Add(beat._prefix._prefix, beat.GetType());
            COMMAND_TYPES.Add(campaign._prefix._prefix, campaign.GetType());
            COMMAND_TYPES.Add(board._prefix._prefix, board.GetType());
        }
Esempio n. 4
0
 public BeatCommands()
 {
     queues  = new ConcurrentDictionary <ulong, Queue>();
     loops   = new ConcurrentDictionary <ulong, bool>();
     _prefix = new CustomPrefix("b-beat");
 }
Esempio n. 5
0
        /// <summary>
        /// 会员卡生成规则
        /// </summary>
        /// <param name="fixedPrefix"></param>
        /// <param name="customPrefix"></param>
        /// <returns></returns>
        public static SerialIdResultData GetCard(FixedPrefix fixedPrefix, CustomPrefix customPrefix)
        {
            const string zero           = "0";
            const string defaultLocalIp = "00000000";

            lock (LockObj)
            {
                if (!_beginTimespan.HasValue)//IIS被回收或者首次使用
                {
                    _beginTimespan = Helper.ConvertDateTimeInt(DateTime.Now);
                }
                var successSerialId = string.Empty;
                while (string.IsNullOrEmpty(successSerialId))
                {
                    //获取当前时间戳
                    var timestamp = Helper.ConvertDateTimeInt(DateTime.Now);
                    //判断首次使用的时间与当前时间
                    if ((timestamp - _beginTimespan.Value).Equals(0))
                    {
                        Thread.Sleep(10);
                        continue;
                    }
                    //获取固定前缀
                    var fixPrefix = Helper.GetEnumDesc(fixedPrefix);
                    //用户自定义前缀为空,则为A
                    //获取用户自定义前缀
                    var cpx = Helper.GetEnumDesc(customPrefix);
                    //判断本机IP是否为空,为空则获取
                    if (string.IsNullOrEmpty(_localIp))
                    {
                        _localIp = GetIpAddress();
                    }
                    //获取不到本机IP,则用默认值代替
                    if (string.IsNullOrEmpty(_localIp))
                    {
                        _localIp = defaultLocalIp;
                    }
                    //构造随机种子
                    var seed   = Guid.NewGuid().GetHashCode();
                    var random = new Random(seed);
                    //随机订单号的最后3位
                    var timefix = random.Next(0, 99).ToString(CultureInfo.InvariantCulture);
                    while (timefix.Length < 2)//不足3位前面补0
                    {
                        timefix = zero + timefix;
                    }
                    //构建订单号
                    //转换时间戳为16进制,并替换E为U
                    var time = Convert.ToString(timestamp, 16).ToUpper().Replace('E', 'U');
                    //IP替换E为U
                    var localIp  = _localIp.ToUpper().Replace('E', 'U').Substring(0, 4);
                    var serialId = fixPrefix + cpx + time + localIp + timefix;
                    serialId = serialId.ToLower();
                    //判断是否重复
                    var isDone = SystemCacheHelper.TicketStore(serialId);
                    successSerialId = isDone ? serialId : string.Empty;
                }
                //转为小写
                successSerialId = successSerialId.ToLower();
                var resultData = new SerialIdResultData
                {
                    ResultCode = string.IsNullOrEmpty(_localIp) ? ResultCode.Error : ResultCode.Success,
                    SerialId   = successSerialId
                };
                return(resultData);
            }
        }
Esempio n. 6
0
 public CampaignCommands() : base()
 {
     _prefix = new CustomPrefix("b-campaign");
 }