public ImportantInfoResponse ParseConfig(ImportantInfoRequest request)
        {
            ImportantInfoList items;

            using (StreamReader r = new StreamReader(_configuration[BannerConfigurationFile]))
            {
                string json = r.ReadToEnd();
                items = JsonConvert.DeserializeObject <ImportantInfoList>(json);

                var item = items.message.SingleOrDefault(m => m.lang == request.lang);

                return(new ImportantInfoResponse()
                {
                    text = item?.text, isClickable = items.isClickable, bannerColor = items.color
                });
            }
        }
예제 #2
0
        public async Task <IActionResult> GetImportantInfo(string lang)
        {
            _logger.LogInformation($"{nameof(GetImportantInfo)} endpoint called.");

            try
            {
                _logger.LogInformation($"Logging request param: {lang}");
                ImportantInfoRequest parameters = new ImportantInfoRequest()
                {
                    lang = lang
                };

                if (!_importantInfoService.ConfigFileExists())
                {
                    return(NoContent());
                }

                var res = _importantInfoService.ParseConfig(parameters);

                if (res.text == null)
                {
                    return(NoContent());
                }

                _logger.LogInformation("Important info send");
                return(Ok(res));
            }
            catch (JsonException je)
            {
                _logger.LogError($"Incorrect JSON format: {je}  [Deserialized request]: {HttpContext.Request.Body}");
                return(BadRequest($"Incorrect JSON format: {je.Message}"));
            }
            catch (ArgumentException ae)
            {
                _logger.LogError("Incorrect input format: " + ae);
                return(BadRequest("Incorrect input format: " + ae.Message));
            }
            catch (Exception e)
            {
                _logger.LogError("Error sending important info:" + e);
                return(StatusCode(500));
            }
        }