Exemple #1
0
        public async Task <string> Post([FromBody] MPowPoolDailyRewardWithValid obj)
        {
            BAppInfo            bll  = new BAppInfo(connStr);
            BPowPoolDailyReward bllp = new BPowPoolDailyReward(connStr);
            Result <int>        res  = new Result <int>();

            try
            {
                var mo = await bll.GetAppInfo(obj.appID);

                if (mo == null)
                {
                    res = new Result <int>(ResultCode.Fail, " There's no such app that appID is " + obj.appID, 0);
                    return(JsonConvert.SerializeObject(res));
                }
                string secretKey = mo.secretKey.Trim();
                var    isOK      = DataValid.Valid(obj.requestSign, obj.appID, obj.signPlain, obj.timeSpan, secretKey);
                if (isOK)
                {
                    //insert into PowPoolDailyReward
                    var lst   = obj.rewardLst;
                    var tasks = new List <Task>();
                    foreach (var v in lst)
                    {
                        //Thread.Sleep(10);
                        tasks.Add(Task.Factory.StartNew(() => bllp.InsertOne(v)));
                    }

                    try
                    {
                        Task.WaitAll(tasks.ToArray());
                        res = new Result <int>(ResultCode.Ok, null, lst.Count);
                    }
                    catch (AggregateException ae)
                    {
                        var str = string.Empty;
                        foreach (var ex in ae.InnerExceptions)
                        {
                            str += "Name: " + ex.GetType().Name + ", msg:" + ex.Message + " | ";
                        }
                        res = new Result <int>(ResultCode.Fail, str, 0);
                    }
                    //var tr = bllp.InsertOne(obj.rewardLst[0]);
                    //res = new Result<int>(ResultCode.Ok, null, 1);
                }
                else
                {
                    res = new Result <int>(ResultCode.Fail, null, 0);
                }
                return(JsonConvert.SerializeObject(res));
            }
            catch (Exception ex)
            {
                res = new Result <int>(ResultCode.Fail, ex.Message, 0);
                return(JsonConvert.SerializeObject(res));
            }
        }
Exemple #2
0
        public async Task <string> Post([FromBody] MUnlockBlockLstWithSign obj)
        {
            Result <int> res = new Result <int>();

            try
            {
                BAppInfo     bll_info = new BAppInfo(connStr);
                BUnlockBlock bllp     = new BUnlockBlock(connStr);

                var mo = await bll_info.GetAppInfo(obj.appID);

                if (mo == null)
                {
                    res = new Result <int>(ResultCode.Fail, " There's no such app that appID is " + obj.appID, 0);
                    return(JsonConvert.SerializeObject(res));
                }
                string secretKey = mo.secretKey.Trim();
                var    isOK      = DataValid.Valid(obj.requestSign, obj.appID, obj.signPlain, obj.timeSpan, secretKey);

                Console.Out.WriteLine("isOK?" + isOK);
                if (isOK)
                {
                    var lst   = obj.balanceLst;
                    var tasks = new List <Task>();
                    foreach (var v in lst)
                    {
                        //Thread.Sleep(10);
                        tasks.Add(Task.Factory.StartNew(() => bllp.InsertOne(v, zone)));
                    }
                    try
                    {
                        Task.WaitAll(tasks.ToArray());
                        res = new Result <int>(ResultCode.Ok, null, lst.Count);
                    }
                    catch (AggregateException ae)
                    {
                        var str = string.Empty;
                        foreach (var ex in ae.InnerExceptions)
                        {
                            str += "Name: " + ex.GetType().Name + ", msg:" + ex.Message + " | ";
                        }
                        res = new Result <int>(ResultCode.Fail, str, 0);
                    }
                }
                else
                {
                    res = new Result <int>(ResultCode.Fail, null, 0);
                }
                return(JsonConvert.SerializeObject(res));
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine("err:" + ex);
                res = new Result <int>(ResultCode.Fail, ex.Message, 0);
                return(JsonConvert.SerializeObject(res));
            }
        }
Exemple #3
0
        public async Task <bool> Post(MValid mop)
        {
            BAppInfo bll = new BAppInfo(connStr);

            try
            {
                var mo = await bll.GetAppInfo(mop.appID);

                string secretKey = mo.secretKey.Trim();
                return(DataValid.Valid(mop.requestSign, mop.appID, mop.signPlain, mop.timeSpan, secretKey));
            }
            catch (Exception)
            {
                return(false);
            }
        }