Ejemplo n.º 1
0
        static async Task <GetLocationResponse> GetProductAsync()
        {
            var                 product  = new GetLocationResponse();
            var                 path     = "https://linh-foodtruc-location-api.azurewebsites.net/FoodTruck/Location/get/currentLocation";
            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(path);

            if (response.IsSuccessStatusCode)
            {
                product = await response.Content.ReadAsAsync <GetLocationResponse>();
            }
            return(product);
        }
Ejemplo n.º 2
0
        internal static GetLocationResponse ConvertToReponse(Location latestLoc)
        {
            var response = new GetLocationResponse
            {
                Location = new LocationInfo
                {
                    StreetNumber        = latestLoc.StreetNumber.IgnoreNull(),
                    StreetName          = latestLoc.StreetName.IgnoreNull(),
                    City                = latestLoc.City.IgnoreNull(),
                    State               = latestLoc.State.IgnoreNull(),
                    ZipCode             = latestLoc.ZipCode.IgnoreNull(),
                    FullAddress         = latestLoc.FullAddress.IgnoreNull(),
                    LocationDescription = latestLoc.LocationDescription.IgnoreNull()
                }
            };

            return(response);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
            [RequestBodyType(typeof(GetLocationRequest), "Get Location")] GetLocationRequest req,
            CancellationToken cancellationToken)
        {
            try
            {
                GetLocationResponse response = await _mediator.Send(req, cancellationToken);

                return(new OkObjectResult(ResponseWrapper <GetLocationResponse, AddressServiceErrorCode> .CreateSuccessfulResponse(response)));
            }
            catch (Exception exc)
            {
                _logger.LogErrorAndNotifyNewRelic("Exception occured in GetLocation", exc);
                return(new ObjectResult(ResponseWrapper <GetLocationResponse, AddressServiceErrorCode> .CreateUnsuccessfulResponse(AddressServiceErrorCode.UnhandledError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Ejemplo n.º 4
0
        public virtual IHttpActionResult GetCurrentLocation()
        {
            var response = new GetLocationResponse();

            try
            {
                LocationDa da        = new LocationDa();
                var        latestLoc = da.GetLatestLocation();
                var        location  = LocationConverter.ConvertToReponse(latestLoc);
                var        json      = JsonConvert.SerializeObject(location, new JsonSerializerSettings {
                    Formatting = Formatting.None
                });
                response = JsonConvert.DeserializeObject <GetLocationResponse>(json);

                da.Dispose();
            }
            catch (Exception ex)
            {
            }
            return(new HttpActionResult(HttpStatusCode.OK, response));
        }
Ejemplo n.º 5
0
        public override void OnRequest(OrbClientInfo clientInfo, OrbRequestArgs args)
        {
            // cast the clientInfo into the OrbClientState subclass that contains addition info
            // such as the OrbClientID, Account, and logged in char if online.
            OrbClientState client = (OrbClientState)clientInfo;

            if (client.OnlineMobile != null)
            {
                // char is logged in, return its location
                GetLocationResponse resp = new GetLocationResponse();
                resp.X = client.OnlineMobile.Location.X;
                resp.Y = client.OnlineMobile.Location.Y;
                resp.Z = client.OnlineMobile.Location.Z;

                // send the response back to the test utility
                SendResponse(resp);
            }
            else
            {
                // char is offline, return null
                SendResponse(null);
            }
        }