예제 #1
0
        public override Task <ExchangeDataRequest> ExchangeData(ExchangeDataRequest request, ServerCallContext context)
        {
            _logger.LogInformation($"ExchangeData called");

            // Process request metadata received from client
            foreach (var item in context.RequestHeaders)
            {
                _logger.LogInformation($"ServerCallContext.RequestHeaders[] key={item.Key}, value={item.Value}");
            }

            // Set response metadata to be sent to client
            context.ResponseTrailers.Add(new Grpc.Core.Metadata.Entry("ServerResponseField1", "ServerResponseValue1"));
            context.ResponseTrailers.Add(new Grpc.Core.Metadata.Entry("ServerResponseField2", "ServerResponseValue2"));

            return(Task.FromResult(new ExchangeDataRequest()));
        }
예제 #2
0
        public HttpResponseMessage Post(HttpRequestMessage request, [FromBody] ExchangeDataRequest data)
        {
            int type = 0;
            GenericApiResponse response     = new GenericApiResponse();
            GameBL             gameBL       = new GameBL();
            PersonBL           ConsumerAuth = new PersonBL();
            ExchangeCoinsBL    exchangeBL   = new ExchangeCoinsBL();
            int    coins  = 0;
            string error  = "";
            string code   = "";
            Random random = new Random();

            try
            {
                IEnumerable <string> AppVersion = null;
                request.Headers.TryGetValues("AppVersion", out AppVersion);

                IEnumerable <string> Platform = null;
                request.Headers.TryGetValues("Platform", out Platform);

                bool ApplyValidation = bool.Parse(ConfigurationManager.AppSettings["ApplyValidationAppVersion"].ToString());

                if (ApplyValidation == false || (AppVersion != null && Platform != null))
                {
                    string versionRequired = "";

                    var isValidVersion = (ApplyValidation == false) ? true : gameBL.IsValidAppVersion(AppVersion.FirstOrDefault(), Platform.FirstOrDefault(), ref error, ref versionRequired);

                    if (isValidVersion)
                    {
                        if (string.IsNullOrEmpty(data.LocationID) && (data.ChestType == 0 || data.ChestType == 0))
                        {
                            response.HttpCode = 400;
                            response.Message  = "LocationID or ChestType cannot be empty";
                            return(Request.CreateResponse <IResponse>(HttpStatusCode.BadRequest, response));
                        }
                        else
                        {
                            IEnumerable <string> key = null;
                            request.Headers.TryGetValues("authenticationKey", out key);
                            var consumerFb = ConsumerAuth.authenticateConsumer(key.FirstOrDefault().ToString());

                            if (consumerFb != null)
                            {
                                string RandomCoinsOrSouvenir = ConfigurationManager.AppSettings["RandomCoinOrSouvenir"].ToString();

                                var range        = RandomCoinsOrSouvenir.Split(',');
                                int minValue     = int.Parse(range[0]);
                                int maxValue     = int.Parse(range[1]);
                                int RandomResult = random.Next(minValue, maxValue);

                                if (RandomResult <= 9)
                                {
                                    type = 1;
                                }
                                else
                                {
                                    type = 2;
                                }

                                if (type == 1)
                                {
                                    var result = exchangeBL.ProcessExchangeCoins(data.LocationID, data.Longitude, data.Latitude, data.ChestType, consumerFb.ConsumerID, ref coins, data.AgeID);

                                    if (error == "")
                                    {
                                        ExchangeCoinsInteractor interactor = new ExchangeCoinsInteractor();

                                        var responseSuccess = interactor.createExchangeCoinsResultsResponse(result, coins);
                                        return(Request.CreateResponse <IResponse>(HttpStatusCode.OK, responseSuccess));
                                    }
                                    else
                                    {
                                        response.HttpCode = 500;
                                        response.Message  = "something went wrong";
                                        return(Request.CreateResponse <IResponse>(HttpStatusCode.InternalServerError, response));
                                    }
                                }
                                else
                                {
                                    var result = exchangeBL.ProcessExchangeSouvenir(data.LocationID, data.Longitude, data.Latitude, data.ChestType, consumerFb.ConsumerID, ref error, data.AgeID);

                                    ExchangeCoinsInteractor interactor = new ExchangeCoinsInteractor();

                                    var responseSuccess = interactor.createExchangeSouvewnorResultsResponse(result, error);
                                    return(Request.CreateResponse <IResponse>(HttpStatusCode.OK, responseSuccess));
                                }
                            }
                            else
                            {
                                response.HttpCode = 404;
                                response.Message  = "Facebook information not found";
                                return(Request.CreateResponse <IResponse>(HttpStatusCode.BadRequest, response));
                            }
                        }
                    }
                    else
                    {
                        response.HttpCode     = 426;
                        response.InternalCode = versionRequired;
                        response.Message      = "Upgrade required";
                        return(Request.CreateResponse <IResponse>(HttpStatusCode.UpgradeRequired, response));
                    }
                }
                else
                {
                    response.HttpCode = 404;
                    response.Message  = "Version or Platform parameter can not be null";
                    return(Request.CreateResponse <IResponse>(HttpStatusCode.BadRequest, response));
                }
            }
            catch (Exception)
            {
                response.HttpCode = 500;
                response.Message  = "something went wrong";
                return(Request.CreateResponse <IResponse>(HttpStatusCode.InternalServerError, response));
            }
        }