Exemplo n.º 1
0
            public async Task Add_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken)
            {
                var args = new AddArgs();
                await args.ReadAsync(iprot, cancellationToken);

                await iprot.ReadMessageEndAsync(cancellationToken);

                var result = new AddResult();

                try
                {
                    result.Success = await _iAsync.@AddAsync(args.Num1, args.Num2, cancellationToken);

                    await oprot.WriteMessageBeginAsync(new TMessage("Add", TMessageType.Reply, seqid), cancellationToken);

                    await result.WriteAsync(oprot, cancellationToken);
                }
                catch (TTransportException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Error occurred in processor:");
                    Console.Error.WriteLine(ex.ToString());
                    var x = new TApplicationException(TApplicationException.ExceptionType.InternalError, " Internal error.");
                    await oprot.WriteMessageBeginAsync(new TMessage("Add", TMessageType.Exception, seqid), cancellationToken);

                    await x.WriteAsync(oprot, cancellationToken);
                }
                await oprot.WriteMessageEndAsync(cancellationToken);

                await oprot.Transport.FlushAsync(cancellationToken);
            }
Exemplo n.º 2
0
        public void Add(AddArgs opt)
        {
            if (!Processor.Hosts.ContainsKey(opt.Name))
            {
                Processor.Hosts.Add(opt.Name, opt.Address);
            }
            else
            {
                Processor.Hosts[opt.Name] = opt.Address;
            }

            opt.Result.Message = string.Format("host entry added for {0} @ {1}", opt.Name, opt.Address);
        }
Exemplo n.º 3
0
        public async Task <APIResult> Add([FromBody] AddArgs args)
        {
            if (string.IsNullOrEmpty(args.Phone))
            {
                throw new ArgumentNullException("Phone");
            }
            if (!smsOptions.SmsTemplates.ContainsKey(args.TaskType))
            {
                throw new Exception($"{args.TaskType}短信模板未配置");
            }

            var phone       = args.Phone.Trim();
            var operationIP = GetIp();

            var isPhone = Regex.IsMatch(phone, @"^1[23456789]\d{9}$", RegexOptions.IgnoreCase);

            if (!isPhone)
            {
                throw new Exception("手机号码格式不正确,请正确输入手机号码!");
            }

            var isBindMember = memberDb.IsBindMemberPhone(phone);

            if (!isBindMember)
            {
                throw new Exception(string.Format("手机号码:{0}没有绑定会员", phone));
            }

            memberDb.CheckMemberSMSValiCodeTaskLimitRule(phone, operationIP, args.TaskType);

            var code    = CommonUtil.CreateIntNoncestr(6);
            var content = string.Format(smsOptions.SmsTemplates[args.TaskType], code);
            await smsHandler.SendAsync(phone, content);

            MemberSMSValiCodeTask task = new MemberSMSValiCodeTask()
            {
                Phone       = phone,
                IP          = operationIP,
                TaskState   = MemberSMSValiCodeTaskState.未使用,
                TaskTime    = DateTime.Now,
                TaskEndTime = DateTime.Now.AddMinutes(3),
                TaskType    = args.TaskType,
                Code        = code,
            };

            memberDb.AddToMemberSMSValiCodeTask(task);
            memberDb.SaveChanges();

            return(Success());
        }
Exemplo n.º 4
0
            public async Task <int> @AddAsync(int num1, int num2, CancellationToken cancellationToken = default(CancellationToken))
            {
                await OutputProtocol.WriteMessageBeginAsync(new TMessage("Add", TMessageType.Call, SeqId), cancellationToken);

                var args = new AddArgs();

                args.Num1 = num1;
                args.Num2 = num2;

                await args.WriteAsync(OutputProtocol, cancellationToken);

                await OutputProtocol.WriteMessageEndAsync(cancellationToken);

                await OutputProtocol.Transport.FlushAsync(cancellationToken);

                var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken);

                if (msg.Type == TMessageType.Exception)
                {
                    var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken);

                    await InputProtocol.ReadMessageEndAsync(cancellationToken);

                    throw x;
                }

                var result = new AddResult();
                await result.ReadAsync(InputProtocol, cancellationToken);

                await InputProtocol.ReadMessageEndAsync(cancellationToken);

                if (result.__isset.success)
                {
                    return(result.Success);
                }
                throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "Add failed: unknown result");
            }
Exemplo n.º 5
0
        public APIResult Add([FromBody] AddArgs args)
        {
            if (args.ShopId == 0)
            {
                throw new ArgumentNullException("ShopId");
            }
            if (!args.StartDate.HasValue)
            {
                throw new ArgumentNullException("StartDate");
            }
            if (!args.EndDate.HasValue)
            {
                throw new ArgumentNullException("EndDate");
            }
            if (args.Items.Count == 0)
            {
                throw new Exception("请输入具体规则");
            }
            CheckShopActor(args.ShopId, ShopActorType.超级管理员);

            ShopOrderMoneyOff shopOrderMoneyOff = new ShopOrderMoneyOff()
            {
                Name        = args.Name,
                StartDate   = args.StartDate.Value.Date,
                EndDate     = args.EndDate.Value.Date,
                ShopId      = args.ShopId,
                IsScanCode  = args.IsScanCode,
                IsSelfOrder = args.IsSelfOrder,
                IsTakeout   = args.IsTakeout,
                IsEnable    = true,
                IsDel       = false
            };

            db.AddTo(shopOrderMoneyOff);
            db.SaveChanges();

            //若在优惠期间,则开始优惠
            DateTime now = DateTime.Now.Date;

            if (now >= shopOrderMoneyOff.StartDate.Value && now <= shopOrderMoneyOff.EndDate.Value)
            {
                ShopOrderMoneyOffCache cache = new ShopOrderMoneyOffCache()
                {
                    ShopId     = shopOrderMoneyOff.ShopId,
                    MoneyOffId = shopOrderMoneyOff.Id
                };
                db.AddTo(cache);
            }


            foreach (var item in args.Items)
            {
                ShopOrderMoneyOffRule rule = new ShopOrderMoneyOffRule()
                {
                    MoneyOffId = shopOrderMoneyOff.Id,
                    FullAmount = (int)Math.Floor(item.FullAmount * 100),
                    Discount   = (int)Math.Floor(item.Discount * 100),
                    IsDel      = false
                };
                db.AddTo(rule);
            }
            db.SaveChanges();
            return(Success());
        }
Exemplo n.º 6
0
 static void Add(AddArgs args)
 {
     // add was executed
 }