Beispiel #1
0
        public static (bool, string) ValidateRouteDetails(RouteDetails details)
        {
            if (details.FromSystemName.Length > MAX_NAME_LENGTH)
            {
                return(false, $"From Name must be less than {MAX_NAME_LENGTH} characters.");
            }

            if (details.ToSystemName.Length > MAX_NAME_LENGTH)
            {
                return(false, $"To Name must be less than {MAX_NAME_LENGTH} characters.");
            }

            foreach (var c in BAD_CHARACTERS)
            {
                if (details.ToSystemName.Contains(c) ||
                    details.FromSystemName.Contains(c))
                {
                    return(false, $"System names may not contain the {c} character.");
                }
            }

            if (details.AcceptableExtraDistance <= 0f || float.IsNaN(details.AcceptableExtraDistance) ||
                float.IsInfinity(details.AcceptableExtraDistance))
            {
                return(false, $"Acceptable Extra Distance must be a positive number.");
            }

            return(true, null);
        }
Beispiel #2
0
        public async Task <IActionResult> GetSuggestions([FromBody] RouteDetails details)
        {
            (bool success, string errorMessage) = RouteDetailsValidator.ValidateRouteDetails(details);
            if (!success)
            {
                Logger.LogWarning(LoggingEvents.BadRouteDetails, errorMessage, DateTime.Now);
                return(BadRequest(errorMessage));
            }

            Logger.LogInformation(LoggingEvents.GetSuggestions,
                                  $"{DateTime.Now} [{details.FromSystemName}] - [{details.ToSystemName}] : {details.AcceptableExtraDistance}");
            try
            {
                var results = await galaxy.GenerateSuggestions(details);

                Logger.LogInformation(LoggingEvents.GetSuggestionsSuccess,
                                      $"{DateTime.Now} POIs found: {results.Suggestions.Count}");
                return(Ok(results));
            }
            catch (SystemNotFoundException systemNotFoundException)
            {
                Logger.LogWarning(LoggingEvents.SystemNotFound,
                                  $"{DateTime.Now} Name: {systemNotFoundException.SystemName}");
                return(NotFound($"System '{systemNotFoundException.SystemName}' was not found in the galaxy."));
            }
            catch (TripWithinBubbleException)
            {
                Logger.LogWarning(LoggingEvents.TripWithinBubble,
                                  $"{DateTime.Now} Trip within bubble.");
                return(NotFound("Your trip is entirely within the 'bubble' of near-Earth systems, whose nearby POIs are excluded from this search."
                                + " Try setting your sights further afield!"));
            }
            catch (OperationCanceledException)
            {
                Logger.LogError(LoggingEvents.Timeout, $"{DateTime.Now} Timeout in GetSuggestions");
                return(NotFound("Elite Dangerous Star Map could not be consulted, please try again later."));
            }
            catch (GalaxyNotInitialisedException)
            {
                Logger.LogError(LoggingEvents.NotYetInitialised, $"{DateTime.Now} Request received before galaxy initialised!");
                return(NotFound("Galaxy data server is busy initialising, please try again later."));
            }
            catch (Exception ex)
            {
                Logger.LogError(LoggingEvents.UnknownError, ex, $"{DateTime.Now} Error in GetSuggestions");
                throw;
            }
        }
Beispiel #3
0
 public async Task <ScenicSuggestionResults> GenerateSuggestions(RouteDetails details)
 {
     return(await GenerateSuggestions(details.FromSystemName, details.ToSystemName, details.AcceptableExtraDistance));
 }