Beispiel #1
0
        public async Task <IActionResult> Index([FromQuery] string algorithm, [FromQuery] bool?detailedResults, [FromQuery] bool?debugMode,
                                                [FromServices] IOptionsSnapshot <Config.RecommendationsConfig> recConfig, [FromServices] IAnimeRecsClientFactory recClientFactory)
        {
            if (!ModelState.IsValid)
            {
                string errorString = ModelBindingHelpers.ConstructErrorString(ModelState);
                _logger.LogDebug("Invalid input received for home page: {0}", errorString);
                return(View("Error", new ErrorViewModel(exception: null)));
            }

            algorithm = algorithm ?? recConfig.Value.DefaultRecSource;
            bool displayDetailedResults = detailedResults ?? false;
            bool debugModeOn            = debugMode ?? false;

            string recSourceType = null;

            using (AnimeRecsClient client = recClientFactory.GetClient(algorithm))
            {
                try
                {
                    recSourceType = await client.GetRecSourceTypeAsync(algorithm,
                                                                       TimeSpan.FromMilliseconds(recConfig.Value.TimeoutMilliseconds), CancellationToken.None);
                }
                catch
                {
                    ;
                }
            }

            bool algorithmAvailable = recSourceType != null;

            bool targetScoreNeeded = false;

            if (AnimeRecs.RecService.DTO.RecSourceTypes.AnimeRecs.Equals(recSourceType, StringComparison.OrdinalIgnoreCase) && displayDetailedResults)
            {
                targetScoreNeeded = true;
            }

            HomeViewModel viewModel = new HomeViewModel(
                algorithm: algorithm,
                algorithmAvailable: algorithmAvailable,
                targetScoreNeeded: targetScoreNeeded,
                displayDetailedResults: displayDetailedResults,
                debugModeOn: debugModeOn
                );


            return(View(viewModel));
        }
Beispiel #2
0
 public AjaxError(ModelStateDictionary modelState)
 {
     ErrorCode = InvalidInput;
     Message   = ModelBindingHelpers.ConstructErrorString(modelState);
 }