示例#1
0
        public async Task <SubmitPixelResponse> SubmitPixel(SubmitPixelRequest request)
        {
            var queueResponse = await QueueEngine.QueueProcessor.QueueItem(request);

            if (!queueResponse.Success)
            {
                return new SubmitPixelResponse {
                           Success = queueResponse.Success, Message = queueResponse.Message
                }
            }
            ;

            var response = queueResponse as SubmitPixelResponse;
            await Task.WhenAny
            (
                PixelHubClient.NotifyPixel(response.PixelNotification),
                PixelHubClient.NotifyPrize(response.PrizeNotification),
                PixelHubClient.NotifyPoints(response.PointsNotification)
            );

            return(response);
        }
示例#2
0
        private async Task <SubmitPixelResponse> ProcessSubmitPixelRequest(IDbConnection connection, SubmitPixelRequest pixelRequest)
        {
            var stopwatch      = GetStopwatch();
            var addPixelResult = await connection.QueryFirstAsync <AddPixelResult>(StoredProcedure.Game_AddPixel, new
            {
                GameId    = pixelRequest.GameId,
                UserId    = pixelRequest.UserId,
                X         = pixelRequest.X,
                Y         = pixelRequest.Y,
                Type      = pixelRequest.Type,
                Color     = pixelRequest.Color,
                Points    = pixelRequest.Points,
                MaxPoints = pixelRequest.MaxPoints,
                GameType  = pixelRequest.GameType
            }, commandType : CommandType.StoredProcedure);

            if (addPixelResult == null)
            {
                throw new QueueException("Failed to update pixel");
            }

            if (!string.IsNullOrEmpty(addPixelResult.Error))
            {
                Log.Message(LogLevel.Error, $"[AddPixel] - GameId: {pixelRequest.GameId.ToString().PadRight(3)}, UserId: {pixelRequest.UserId.ToString().PadRight(3)}, X: {pixelRequest.X.ToString().PadRight(3)}, Y: {pixelRequest.Y.ToString().PadRight(3)}, Error: {addPixelResult.Error}, {GetElapsedTime(stopwatch)}");
                return(new SubmitPixelResponse {
                    Success = false, Message = addPixelResult.Error
                });
            }

            var addClickResult = await connection.QueryFirstAsync <AddClickResult>(StoredProcedure.Game_AddClick, new
            {
                GameId = pixelRequest.GameId,
                UserId = pixelRequest.UserId,
                Type   = ClickType.Pixel,
                X      = pixelRequest.X,
                Y      = pixelRequest.Y
            }, commandType : CommandType.StoredProcedure);

            if (addClickResult == null || addClickResult.ClickId <= 0)
            {
                throw new QueueException("Failed to add click");
            }

            if (!string.IsNullOrEmpty(addClickResult.Error))
            {
                Log.Message(LogLevel.Error, $"[AddPixel] - GameId: {pixelRequest.GameId.ToString().PadRight(3)}, UserId: {pixelRequest.UserId.ToString().PadRight(3)}, X: {pixelRequest.X.ToString().PadRight(3)}, Y: {pixelRequest.Y.ToString().PadRight(3)}, Error: {addClickResult.Error}, {GetElapsedTime(stopwatch)}");
                return(new SubmitPixelResponse {
                    Success = false, Message = addClickResult.Error
                });
            }

            var response = new SubmitPixelResponse
            {
                Success            = true,
                PointsNotification = new PointsNotification
                {
                    UserId = pixelRequest.UserId,
                    Points = addClickResult.PrizeId.HasValue
                                        ? addClickResult.UserPoints
                                        : addPixelResult.UserPoints
                },
                PixelNotification = new PixelNotification
                {
                    PixelId = addPixelResult.PixelId,
                    X       = pixelRequest.X,
                    Y       = pixelRequest.Y,
                    Color   = pixelRequest.Color,
                    Points  = addPixelResult.NewPoints,
                    Type    = pixelRequest.Type,

                    UserId   = addPixelResult.UserId,
                    UserName = addPixelResult.UserName,

                    GameId   = pixelRequest.GameId,
                    GameName = addClickResult.GameName
                }
            };

            if (addClickResult.PrizeId.HasValue)
            {
                response.PrizeNotification = new PrizeNotification
                {
                    PrizeId = addClickResult.PrizeId.Value,
                    X       = pixelRequest.X,
                    Y       = pixelRequest.Y,

                    Name        = addClickResult.PrizeName,
                    Points      = addClickResult.PrizePoints,
                    Description = addClickResult.PrizeDescription,

                    UserId   = addPixelResult.UserId,
                    UserName = addPixelResult.UserName,

                    GameId   = pixelRequest.GameId,
                    GameName = addClickResult.GameName
                };
            }

            Log.Message(LogLevel.Info, $"[AddPixel] - GameId: {pixelRequest.GameId.ToString().PadRight(3)}, UserId: {pixelRequest.UserId.ToString().PadRight(3)}, X: {pixelRequest.X.ToString().PadRight(3)}, Y: {pixelRequest.Y.ToString().PadRight(3)}, Color: {pixelRequest.Color}, {GetElapsedTime(stopwatch)}");
            return(response);
        }
示例#3
0
 public Task <SubmitPixelResponse> SubmitPixel(SubmitPixelRequest request)
 {
     return(SafeInvoke <SubmitPixelResponse>(nameof(SubmitPixel), request));
 }