public static bool UpdateWebsiteFaviconUrl(UpdateWebsiteDetails details) { if (details == null) { return(false); } try { HttpClient client = new HttpClient(); client.DefaultRequestHeaders .Accept .Add(new MediaTypeWithQualityHeaderValue("application/json")); var jsonData = JsonConvert.SerializeObject(details); var response = client.PostAsync(new Uri(String.Format(updateFaviconUrl, EnvironmentConstants.ApplicationConfiguration.APIDomain)), new StringContent(jsonData, Encoding.UTF8, "application/json")).Result; if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { throw new Exception("UnAuthorized"); } else if (!((int)response.StatusCode >= 200 && (int)response.StatusCode <= 300))//If status code is not 20X, error. { throw new Exception(String.Format("API call unsuccessful : {0}", updateFaviconUrl)); } return(true); } catch (Exception ex) { Log.Error(ex, String.Format("Error updating the project, ProjectId:{0}", details.ProjectId)); } return(false); }
public static void InitialiseKrawler(string projectId, Uri uri) { try { #region Get the Details var screenshot = GetScreenShotOfUrl(projectId, uri); var faviconUrl = GetFaviconUrl(projectId, uri); var robotsResult = GetAndSaveRobotsTxt(projectId, uri); #endregion #region Wait for result and save in DB var screenShotUrl = screenshot.Result; if (String.IsNullOrEmpty(screenShotUrl) && String.IsNullOrEmpty(faviconUrl)) { return; } UpdateWebsiteDetails details = new UpdateWebsiteDetails { FaviconUrl = faviconUrl, ScreenShotUrl = screenShotUrl, ProjectId = projectId }; APIHelper.UpdateWebsiteFaviconUrl(details); #endregion } catch (Exception ex) { Log.Error(ex, $"ProjectId:{projectId}, Message:Error in initialising phase"); } }