Esempio n. 1
0
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            var tokenParam = actionExecutedContext.Request.Headers.Authorization.Parameter;

            if (tokenParam == null)
            {
                CustomNLogger.LogException("Token authorization failed");
            }
        }
Esempio n. 2
0
 public string AddNewSavedText(SavedText savedText)
 {
     try
     {
         _dbContext.SavedTexts.Add(savedText);
         return("Entry inserted successfully");
     }
     catch (Exception ex)
     {
         CustomNLogger.LogException(ex.Message);
         return(null);
     }
 }
Esempio n. 3
0
        public bool ServiceRunning()
        {
            using (var client = new HttpClient())
            {
                var response = client.GetAsync($"{ApiUrl}/status/check");
                if (!response.Result.IsSuccessStatusCode)
                {
                    CustomNLogger.LogException($"TextWebApi at {ApiUrl} is down");
                }

                return(response.Result.IsSuccessStatusCode);
            }
        }
Esempio n. 4
0
        public async Task <string> GetResponseFromApi(string contentToSend)
        {
            CheckAndSetToken();
            using (var client = new HttpClient())
            {
                var transferObject = new SimpleDto {
                    Text = contentToSend
                };
                var contentBody = new StringContent(JsonConvert.SerializeObject(transferObject), Encoding.UTF8, "application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);

                var response = await client.PostAsync($"{ApiUrl}/text-infos/count-words", contentBody);

                if (!response.IsSuccessStatusCode)
                {
                    CustomNLogger.LogException($"error occurred: \n{response.StatusCode} \n{response.RequestMessage.RequestUri}");
                    return("There is currently error in communication with API");
                }

                return(await response.Content.ReadAsStringAsync());
            }
        }