// Return the HTTP Response given a url used to test if an external service is up // 400 - Bad Request, should be ok it means service is up but the data is malformed // 404 Not Found this indicates that the service is unavailable public static ApiWebResponse GetHRServerStatus(IConfiguration configuration) { var hruri = configuration.GetSection("HumanReview:uri").Value + "auth/token"; ApiWebResponse ApiResp = new ApiWebResponse(); WebClient client = new WebClient(); string result = ""; try { result = client.DownloadString(hruri); ApiResp.Message = "OK"; } catch (WebException e) { ApiResp.Message = e.Message; if (e.Response is HttpWebResponse response) { ApiResp.StatusCode = (int)response.StatusCode; ApiResp.Response = e.Response; } else { ApiResp.StatusCode = 0; ApiResp.Response = null; } } return(ApiResp); }
private bool ValidateWorkItemData(WorkItemPostData newdata, IConfiguration configuration) { JwtSecurityToken HRToken = new JwtSecurityToken(newdata.Token); if (Helper.TokenValid(HRToken) == false) { return(false); } if (newdata.ModuleTableEntryID == 0) { return(false); } if (newdata.ProfileId == "") { return(false); } if (newdata.Token == "") { return(false); } // Get the Entity Detail from MMMDB, return if not found var EntityDetails = _mmmcontext.Entities.Where(t => t.Ent_ID == Convert.ToInt32(newdata.ProfileId)).FirstOrDefault(); if (EntityDetails == null) { return(false); } // Check if HR is up before calling HR routines ApiWebResponse hrResponse = Helper.GetHRServerStatus(configuration); // We expect a 400 - Bad Request, if 404 Not Found, return an error if (hrResponse.StatusCode == 404) { return(false); } return(true); }