Beispiel #1
0
        public async Task <WrappedResponse <RoomMatchResponseVm> > BlindMatch(long id, long blind)
        {
            WrappedResponse <RoomMatchResponseVm> response =
                await _bus.SendCommand(new BlindMatchCommand(id, blind));

            return(response.MapResponse <RoomMatchResponseVm>(_mapper));
        }
Beispiel #2
0
        /*private readonly IServiceTemplateRedisRepository _ServiceTemplateRedisRep;
         * private readonly IServiceTemplateInfoRepository _ServiceTemplateRep;
         * private readonly IMediatorHandler _bus;
         *
         * public ServiceTemplateCmdHandler(IServiceTemplateRedisRepository ServiceTemplateRedisRep, IServiceTemplateInfoRepository ServiceTemplateRep,
         *  IMediatorHandler bus)
         * {
         *  _ServiceTemplateRedisRep = ServiceTemplateRedisRep;
         *  _ServiceTemplateRep = ServiceTemplateRep;
         *  _bus = bus;
         * }*/

        public Task <WrappedResponse <ServiceTemplateResponseVm> > Handle(ServiceTemplateCommand request, CancellationToken cancellationToken)
        {
            WrappedResponse <ServiceTemplateResponseVm> response = new WrappedResponse <ServiceTemplateResponseVm>(ResponseStatus.LoginError,
                                                                                                                   null, null);

            return(Task.FromResult(response));
        }
Beispiel #3
0
        public async Task <WrappedResponse <string> > ProcessCardPayment
        (
            string cardNumber,
            string expiration,
            string cvc,
            decimal sum,
            string comment,
            string email
        )
        {
            var payment = new CardPayment
            {
                CardNumber = cardNumber,
                Expiration = expiration,
                Cvc        = cvc,
                Sum        = sum,
                Comment    = comment,
                Email      = email
            };

            var validationResult = payment.Validate();

            if (!validationResult.IsValid)
            {
                return(WrappedResponse <string> .Fail($"Неверный формат: {validationResult.Error}"));
            }

            await paymentRepository.SaveCardPaymentAsync(payment).ConfigureAwait(false);

            return(WrappedResponse <string> .Success());
        }
Beispiel #4
0
        public async Task <WrappedResponse <IEnumerable <PaymentRequest> > > SelectPaymentRequests
        (
            string searchColumn,
            string prefix,
            string sortColumn,
            bool descendingOrder
        )
        {
            var searchParameters = new SearchParameters
            {
                Column = searchColumn,
                Prefix = prefix
            };

            var sortParameters = new SortParameters
            {
                Column          = sortColumn,
                DescendingOrder = descendingOrder
            };

            var response = await paymentRepository.SelectPaymentRequestsAsync(searchParameters, sortParameters)
                           .ConfigureAwait(false);

            return(WrappedResponse <IEnumerable <PaymentRequest> > .Success(response));
        }
Beispiel #5
0
        public override void OnException(MethodExecutionArgs args)
        {
            var errorHandler = ErrorHandler.Create();

            errorHandler.LogException(args.Exception);

            var methodReturnType = ((System.Reflection.MethodInfo)args.Method).ReturnType;

            if (methodReturnType.IsConstructedGenericType &&
                methodReturnType.GenericTypeArguments.Length > 0 &&
                methodReturnType.GenericTypeArguments[0] == typeof(IWrappedResponse))
            {
                var response = new WrappedResponse
                {
                    ResultType = ResultType.Failed,
                    State      = errorHandler
                                 .TranslateException(args.Exception)
                                 .GetServiceState()
                };

                args.FlowBehavior = FlowBehavior.Return;
                args.ReturnValue  = response;
            }
            else
            {
                args.FlowBehavior = FlowBehavior.RethrowException;
            }
        }
Beispiel #6
0
        public async Task <IActionResult> ProcessBankPayment
        (
            string inn,
            string bic,
            string accountNumber,
            int vat,
            decimal sum
        )
        {
            var payment = new BankPayment
            {
                Inn           = inn,
                Bic           = bic,
                AccountNumber = accountNumber,
                Vat           = vat,
                Sum           = sum
            };

            var validationResult = payment.Validate();

            if (!validationResult.IsValid)
            {
                return(Json(WrappedResponse <string> .Fail($"Неверный формат: {validationResult.Error}")));
            }

            using (var buffer = new MemoryStream())
            {
                using (var streamWriter = new StreamWriter(buffer))
                {
                    await streamWriter.WriteLineAsync(payment.AsBankStatement());
                }

                return(File(buffer.ToArray(), MediaTypeNames.Application.Octet, ""));
            }
        }
        public async Task <WrappedResponse <MoneyInfo> > Handle(GetMoneyCommand request, CancellationToken cancellationToken)
        {
            var moneyInfo = await _moneyRedisRep.GetMoneyInfo(request.Id);

            if (moneyInfo == null)
            {
                using (var locker = _moneyRedisRep.Locker(KeyGenTool.GenUserKey(request.Id,
                                                                                MoneyInfo.ClassName)))
                {
                    await locker.LockAsync();

                    moneyInfo = await _moneyRep.FindAndAdd(request.Id,
                                                           new MoneyInfo(request.Id, 0, 0, 0, 0, 0));

                    _ = _moneyRedisRep.SetMoneyInfo(moneyInfo);
                }

                if (moneyInfo == null)
                {
                    return(new WrappedResponse <MoneyInfo>(ResponseStatus.GetMoneyError, null, null));
                }
            }
            WrappedResponse <MoneyInfo> response = new WrappedResponse <MoneyInfo>
                                                       (ResponseStatus.Success, null, moneyInfo);

            Log.Debug($"GetMoneyCommand:{moneyInfo.CurCoins},{moneyInfo.Carry}");
            return(response);
        }
Beispiel #8
0
        public async Task <WrappedResponse <string> > ProcessPaymentRequest
        (
            string inn,
            string bic,
            string accountNumber,
            int vat,
            decimal sum,
            string phone,
            string email
        )
        {
            var paymentRequest = new PaymentRequest
            {
                Inn           = inn,
                Bic           = bic,
                AccountNumber = accountNumber,
                Vat           = vat,
                Sum           = sum,
                Phone         = phone,
                Email         = email
            };

            var validationResult = paymentRequest.Validate();

            if (!validationResult.IsValid)
            {
                return(WrappedResponse <string> .Fail($"Неверный формат: {validationResult.Error}"));
            }

            await paymentRepository.SavePaymentRequestAsync(paymentRequest).ConfigureAwait(false);

            return(WrappedResponse <string> .Success());
        }
        protected WrappedResponse <T> WrappedOK <T>(T o)
        {
            var result = new WrappedResponse <T>(o);

            // aggiungo i messaggi
            SetMessages(result);
            return(result);
        }
        public static async Task <WrappedResponse <RoomMatchResponseVm> > MatchRoom(long id, long blind, string curRoomId)
        {
            //获取这个玩家的redis锁
            using var locker = _redis.Locker(KeyGenTool.GenUserKey(id, nameof(UserRoomInfo)));

            if (!await locker.TryLockAsync())
            {
                return(new WrappedResponse <RoomMatchResponseVm>(ResponseStatus.IsMatching, null, null));
            }

            //查询redis是否有这个玩家
            RoomInfo roomInfo     = null;
            var      userRoomInfo = await _redis.GetUserRoomInfo(id);

            if (userRoomInfo != null)
            {
                roomInfo = new RoomInfo(userRoomInfo.RoomId, 0, userRoomInfo.GameKey, userRoomInfo.Blind);
            }
            else
            {
                roomInfo = await RoomManager.GetRoom(blind);
            }
            try
            {
                WrappedResponse <JoinGameRoomMqResponse> roomResponse =
                    await RoomManager.SendToGameRoom <JoinGameRoomMqCmd, WrappedResponse <JoinGameRoomMqResponse> >
                        (roomInfo.GameKey, new JoinGameRoomMqCmd(id, roomInfo.RoomId, roomInfo.GameKey));

                if (roomResponse.ResponseStatus == ResponseStatus.Success)
                {
                    _ = _redis.SetUserRoomInfo(new UserRoomInfo(id, roomInfo.RoomId, roomInfo.GameKey, blind, MatchingStatus.Success));
                    return(new WrappedResponse <RoomMatchResponseVm>(ResponseStatus.Success, null,
                                                                     new RoomMatchResponseVm(roomInfo.RoomId, roomInfo.Blind, roomInfo.GameKey)));
                }
                else
                {
                    if (roomResponse.Body != null)
                    {
                        RoomInfo newRoomInfo = new RoomInfo(roomResponse.Body.RoomId, roomResponse.Body.UserCount,
                                                            roomResponse.Body.GameKey, roomResponse.Body.Blind);
                        RoomManager.UpdateRoom(newRoomInfo);
                    }

                    _ = _redis.DeleteUserRoomInfo(id);
                    return(new WrappedResponse <RoomMatchResponseVm>(roomResponse.ResponseStatus, roomResponse.ErrorInfos, null));
                }
            }

            catch
            {
                _ = _redis.DeleteUserRoomInfo(id);
                Log.Error($"user {id} join room {roomInfo.RoomId} error");
                return(new WrappedResponse <RoomMatchResponseVm>(ResponseStatus.BusError, null, null));
            }
        }
        private static bool CheckForError <T>(WrappedResponse <T> response) where T : class
        {
            if (response.IsSuccessful)
            {
                Console.WriteLine(typeof(T).Name + " succeeded.");
                return(true);
            }

            Console.WriteLine(typeof(T).Name + " failed.");
            Console.WriteLine("  ReturnCode: " + response.Error.ReturnCode);
            Console.WriteLine("  ReturnText: " + response.Error.ReturnText);
            Console.WriteLine("[Press enter to continue]");
            Console.ReadLine();

            return(false);
        }
Beispiel #12
0
        public async Task <WrappedResponse <GameInfo> > Handle(GetGameInfoCommand request, CancellationToken cancellationToken)
        {
            GameInfo gameinfo = await _redisRepository.GetGameInfo(request.Id);

            if (gameinfo == null)
            {
                using var loker = _redisRepository.Locker(KeyGenTool.GenUserKey(request.Id, GameInfo.ClassName));
                loker.Lock();
                gameinfo = await _gameRepository.FindAndAdd(request.Id, new GameInfo(request.Id, 0, 0, 0));

                _ = _redisRepository.SetGameInfo(gameinfo);
            }

            WrappedResponse <GameInfo> response = new WrappedResponse <GameInfo>(ResponseStatus.Success,
                                                                                 null, gameinfo);

            return(response);
        }
        private void SetMessages <T>(WrappedResponse <T> result)
        {
            // UIMESSAGE MANAGING:

            // WARNING:: To avoid a null pointer exception
            // if service are not injected, check if
            // MessageService is not null

            if (MessageService != null && MessageService.HasMessages)
            {
                if (result.Metadata == null)
                {
                    result.Metadata = new Metadata();
                }

                result.Metadata.UiMessages = MessageService.UiMessages;
            }
        }
        private async Task <IWrappedResponse> CreateAction(Rules.BalanceTransfer.Create.MainRule rule)
        {
            var sourceAccount      = rule.Context.SourceAccount;
            var destinationAccount = rule.Context.DestinationAccount;

            var loadCarrierId = (int)rule.Context.LoadCarrierId;
            var quantity      = (int)rule.Context.LoadCarrierQuantity;

            var postingRequest = new PostingRequestsCreateRequest()
            {
                Type   = PostingRequestType.Charge, //HACK Only to fix UI, from LTMS WebApp viewpoint  it would be a credit
                Reason = PostingRequestReason.Transfer,
                RefLtmsProcessTypeId = (int)RefLtmsProcessType.BalanceTransfer,
                Positions            = new List <PostingRequestPosition>()
                {
                    new PostingRequestPosition()
                    {
                        LoadCarrierId       = loadCarrierId,
                        LoadCarrierQuantity = Math.Abs(quantity)
                    }
                },
                RefLtmsProcessId            = Guid.NewGuid(),
                RefLtmsTransactionId        = Guid.NewGuid(),
                PostingAccountId            = sourceAccount.Id,
                SourceRefLtmsAccountId      = destinationAccount.RefLtmsAccountId, // on LTMS ViewPoint source and destination have to be switched
                DestinationRefLtmsAccountId = sourceAccount.RefLtmsAccountId,      // on LTMS ViewPoint source and destination have to be switched
                Note    = rule.Context.Parent.Note,
                DplNote = rule.Context.Parent.DplNote
            };
            var response = (IWrappedResponse <IEnumerable <PostingRequest> >) await _postingRequestService.Create(postingRequest);

            //To avoit breaking changes with UI
            //Only one PostingRequest is returned
            var result = new WrappedResponse <PostingRequest>()
            {
                ResultType = response.ResultType, Data = response.Data.First(), Errors = response.Errors,
                Id         = response.Id, Warnings = response.Warnings
            };

            ;
            return(result);
        }
Beispiel #15
0
        public async Task <WrappedResponse <LevelInfo> > Handle(GetLevelInfoCommand request, CancellationToken cancellationToken)
        {
            LevelInfo levelinfo = await _redisRepository.GetLevelInfo(request.Id);

            if (levelinfo == null)
            {
                //从数据库中获取
                using var loker = _redisRepository.Locker(KeyGenTool.GenUserKey(request.Id, LevelInfo.ClassName));
                loker.Lock();
                levelinfo = await _levelRepository.FindAndAdd(request.Id,
                                                              new LevelInfo(request.Id, 1, 0, LevelManager.GetNeedExp(1)));

                _ = _redisRepository.SetLevelInfo(levelinfo);
            }

            WrappedResponse <LevelInfo> response = new WrappedResponse <LevelInfo>(ResponseStatus.Success,
                                                                                   null, levelinfo);

            return(response);
        }
        public async Task <ActionResult <IEnumerable <DocumentNumberSequence> > > GetByCustomerId(int id)
        {
            var request = new DocumentNumberSequenceSearchRequest
            {
                CustomerId = id
            };

            var response = (IWrappedResponse <IQueryable <DocumentNumberSequence> >) await _numberSequencesService.Search(request);

            var responseToConvert = new WrappedResponse <IEnumerable <DocumentNumberSequence> >
            {
                Data       = response.Data.AsEnumerable(),
                Errors     = response.Errors,
                Id         = response.Id,
                State      = response.State,
                Warnings   = response.Warnings,
                ResultType = response.ResultType
            };

            return(await Task.FromResult <IWrappedResponse>(responseToConvert).Convert <IEnumerable <DocumentNumberSequence> >(this));
        }
Beispiel #17
0
        public IActionResult Update([FromBody] ApplicationDraft applicationDraft)
        {
            WrappedResponse <object> result = _applicationService.UpdateDraftApplication(applicationDraft);

            return(new OkObjectResult(result));
        }
        public async Task <WrappedResponse <AccountResponse> > Handle(LoginCommand request, CancellationToken cancellationToken)
        {
            var newAccountInfo = request.Info;
            //判断该平台ID是否已经注册, 先从redis查找
            var loginCheckInfo = await _redisRep.GetLoginCheckInfo(newAccountInfo.PlatformAccount);

            bool        isRegister = false;
            AccountInfo accountInfo;

            if (loginCheckInfo != null)
            {
                //直接通过ID去查找这个玩家信息
                accountInfo = await _redisRep.GetAccountInfo(loginCheckInfo.Id);

                //为空从数据库读取
                if (accountInfo == null)
                {
                    accountInfo = await _accountRep.GetByIdAsync(loginCheckInfo.Id);
                }
            }
            else
            {
                //查找数据库中是否有这个账号
                accountInfo = await _accountRep.GetByPlatform(newAccountInfo.PlatformAccount);

                if (accountInfo == null)
                {
                    //注册新账号
                    isRegister = true;
                    long newUid = await _genRepository.GenNewId();

                    accountInfo = new AccountInfo(newUid, newAccountInfo.PlatformAccount,
                                                  newAccountInfo.UserName, newAccountInfo.Sex, newAccountInfo.HeadUrl,
                                                  newAccountInfo.Type, DateTime.Now);
                    await _accountRep.AddAsync(accountInfo);
                }
            }

            if (accountInfo != null)
            {
                newAccountInfo.Id = accountInfo.Id;
                string          token = TokenTool.GenToken(accountInfo.Id);
                AccountResponse accounResponse;
                bool            isNeedUpdate = false;
                if (!isRegister && accountInfo.IsNeedUpdate(newAccountInfo))
                {
                    isNeedUpdate = true;
                }
                if (isRegister)
                {
                    var mqResponse = await _moneyAddClient.GetResponseExt <AddMoneyMqCmd, WrappedResponse <MoneyMqResponse> >
                                         (new AddMoneyMqCmd(accountInfo.Id, InitRewardInfo.RewardCoins, 0, AddReason.InitReward));

                    var moneyInfo = mqResponse.Message.Body;
                    accounResponse = new AccountResponse(newAccountInfo.Id,
                                                         newAccountInfo.PlatformAccount,
                                                         newAccountInfo.UserName,
                                                         newAccountInfo.Sex,
                                                         newAccountInfo.HeadUrl,
                                                         token, new MoneyInfo(moneyInfo.CurCoins + moneyInfo.Carry,
                                                                              moneyInfo.CurDiamonds,
                                                                              moneyInfo.MaxCoins,
                                                                              moneyInfo.MaxDiamonds), WSHostManager.GetOneHost(), true,
                                                         newAccountInfo.Type);
                }
                else
                {
                    var mqResponse = await _moneyClient.GetResponseExt <GetMoneyMqCmd, WrappedResponse <MoneyMqResponse> >
                                         (new GetMoneyMqCmd(accountInfo.Id));

                    var moneyInfo = mqResponse.Message.Body;
                    accounResponse = new AccountResponse(newAccountInfo.Id,
                                                         newAccountInfo.PlatformAccount,
                                                         newAccountInfo.UserName,
                                                         newAccountInfo.Sex,
                                                         newAccountInfo.HeadUrl, token,
                                                         new MoneyInfo(moneyInfo.CurCoins + moneyInfo.Carry,
                                                                       moneyInfo.CurDiamonds,
                                                                       moneyInfo.MaxCoins,
                                                                       moneyInfo.MaxDiamonds), WSHostManager.GetOneHost(), false, newAccountInfo.Type);
                }

                _ = _bus.RaiseEvent <LoginEvent>(new LoginEvent(Guid.NewGuid(),
                                                                accounResponse, isRegister, isNeedUpdate, newAccountInfo));
                WrappedResponse <AccountResponse> retRresponse =
                    new WrappedResponse <AccountResponse>(ResponseStatus.Success, null, accounResponse);
                return(retRresponse);
            }
            WrappedResponse <AccountResponse> response = new WrappedResponse <AccountResponse>(ResponseStatus.LoginError,
                                                                                               null, null);

            return(response);
        }
Beispiel #19
0
        public async Task <WrappedResponse <string> > ToggleCardPaymentSafety(Guid paymentId, bool isSafe)
        {
            await paymentRepository.ToggleCardPaymentSafetyAsync(paymentId, isSafe).ConfigureAwait(false);

            return(WrappedResponse <string> .Success());
        }
Beispiel #20
0
        public IActionResult Delete(long id)
        {
            WrappedResponse <object> result = _applicationService.DeleteApplication(id);

            return(new OkObjectResult(result));
        }
Beispiel #21
0
        public async Task <WrappedResponse <RoomMatchResponseVm> > Playnow(long id)
        {
            WrappedResponse <RoomMatchResponseVm> response = await _bus.SendCommand(new PlaynowCommand(id));

            return(response.MapResponse <RoomMatchResponseVm>(_mapper));
        }