コード例 #1
0
        /// <summary>
        /// 拦截并分发请求
        /// </summary>
        /// <param name="context"></param>
        /// <param name="requestEvent"></param>
        /// <returns></returns>
        protected override async Task <APIGatewayProxyResponseEvent> Handler(SCFContext context, APIGatewayProxyRequestEvent requestEvent)
        {
            if (requestEvent == null)
            {
                return(new APIGatewayProxyResponseEvent()
                {
                    ErrorCode = 413,
                    ErrorMessage = "request is not correctly execute"
                });
            }
            if (requestEvent.RequestContext == null)
            {
                return(new APIGatewayProxyResponseEvent()
                {
                    ErrorCode = 410,
                    ErrorMessage = "event is not come from api gateway",
                });
            }
            var path = $"{requestEvent.HttpMethod.ToUpper()} {requestEvent.Path.ToLower()}";

            if (!handlerMapper.ContainsKey(path))
            {
                return(new APIGatewayProxyResponseEvent()
                {
                    ErrorCode = 411,
                    ErrorMessage = "request is not from setting api path"
                });
            }
            return(await handlerMapper[path](requestEvent));
        }
コード例 #2
0
 protected virtual async Task <APIGatewayProxyResponseEvent> Handler(SCFContext context, APIGatewayProxyRequestEvent requestEvent)
 {
     return(new APIGatewayProxyResponseEvent()
     {
         StatusCode = 200,
         IsBase64Encoded = false,
         Headers = new Dictionary <string, string>(),
         Body = requestEvent.ToString()
     });
 }
コード例 #3
0
        public override async Task <string> ProcessEvent(string responseBody, SCFContext context)
        {
            _logger.LogInformation($"start {context.Handler }");

            APIGatewayProxyRequestEvent requestEvent = JsonConvert.DeserializeObject <APIGatewayProxyRequestEvent>(responseBody);

            var response = await Handler(context, requestEvent);

            return(response.ToString());
        }
コード例 #4
0
 public virtual async Task <string> ProcessEvent(string responseBody, SCFContext context)
 {
     return("Event :" + responseBody + "\t Context: " + context.ToString());
 }
コード例 #5
0
        protected override async Task <APIGatewayProxyResponseEvent> Handler(SCFContext context, APIGatewayProxyRequestEvent requestEvent)
        {
            if (requestEvent != null && requestEvent.RequestContext == null)
            {
                return(new APIGatewayProxyResponseEvent()
                {
                    ErrorCode = 410,
                    ErrorMessage = "event is not come from api gateway",
                });
            }
            if (requestEvent != null)
            {
                if (requestEvent.Path != "/api/jobs/getjobs" && requestEvent.Path != "/api/jobs/getdetailsinfo" && requestEvent.Path != "/api/geocode/regeo")
                {
                    return(new APIGatewayProxyResponseEvent()
                    {
                        ErrorCode = 411,
                        ErrorMessage = "request is not from setting api path"
                    });
                }
                if (requestEvent.Path == "/api/jobs/getjobs" && requestEvent.HttpMethod.ToUpper() == "GET")
                {
                    string sources   = requestEvent.QueryString["sources"];
                    string city      = requestEvent.QueryString["city"];
                    string searchKey = requestEvent.QueryString["searchkey"];
                    string pageIndex = requestEvent.QueryString["pageindex"];
                    var    jobs      = await jobsManager.GetJobsAsync(sources.Split('-').ToList(), city, searchKey, int.Parse(pageIndex));

                    var response = new APIGatewayProxyResponseEvent()
                    {
                        StatusCode      = 200,
                        ErrorCode       = 0,
                        ErrorMessage    = "",
                        Body            = JsonConvert.SerializeObject(jobs),
                        IsBase64Encoded = false,
                        Headers         = new Dictionary <string, string>()
                    };
                    response.Headers.Add("Content-Type", "application/json");
                    response.Headers.Add("Access-Control-Allow-Origin", "*");
                    return(response);
                }
                if (requestEvent.Path == "/api/jobs/getdetailsinfo" && requestEvent.HttpMethod.ToUpper() == "GET")
                {
                    string source = requestEvent.QueryString["source"];
                    string url    = requestEvent.QueryString["url"];
                    var    jobs   = await jobsManager.GetDetailsInfo(source, url);

                    var response = new APIGatewayProxyResponseEvent()
                    {
                        StatusCode      = 200,
                        IsBase64Encoded = false,
                        Headers         = new Dictionary <string, string>()
                    };
                    if (jobs == null)
                    {
                        response.ErrorCode    = -1;
                        response.ErrorMessage = "user code exception caught";
                    }
                    else
                    {
                        response.ErrorCode    = 0;
                        response.ErrorMessage = "";
                        response.Body         = JsonConvert.SerializeObject(jobs);
                    }
                    response.Headers.Add("Content-Type", "application/json");
                    response.Headers.Add("Access-Control-Allow-Origin", "*");
                    return(response);
                }
                if (requestEvent.Path == "/api/geocode/regeo" && requestEvent.HttpMethod.ToUpper() == "GET")
                {
                    string         location       = requestEvent.QueryString["location"];
                    ReGeoParameter reGeoParameter = new ReGeoParameter()
                    {
                        Location   = location,
                        Batch      = false,
                        Output     = "JSON",
                        Radius     = 1000,
                        RoadLevel  = 0,
                        Extensions = "base",
                        Poitype    = string.Empty
                    };

                    var regeo = await amapWebApi.GetRegeoAsync(reGeoParameter);

                    var response = new APIGatewayProxyResponseEvent()
                    {
                        StatusCode      = 200,
                        IsBase64Encoded = false,
                        Headers         = new Dictionary <string, string>()
                    };
                    if (regeo == null)
                    {
                        response.ErrorCode    = -1;
                        response.ErrorMessage = "user code exception caught";
                    }
                    else
                    {
                        response.ErrorCode    = 0;
                        response.ErrorMessage = "";
                        response.Body         = string.IsNullOrEmpty(regeo.ReGeoCode.AddressComponent.City) ? regeo.ReGeoCode.AddressComponent.Province : regeo.ReGeoCode.AddressComponent.City;
                    }
                    response.Headers.Add("Content-Type", "application/json");
                    response.Headers.Add("Access-Control-Allow-Origin", "*");
                    return(response);
                }
            }
            return(new APIGatewayProxyResponseEvent()
            {
                ErrorCode = 413,
                ErrorMessage = "request is not correctly execute"
            });
        }