/// <summary> /// This function formats the job title string to fit in three line on email template. /// </summary> /// <param name="jobTitleString"></param> /// <returns>returns formated job title string</returns> public static string FormatYourConnectionJobTitle(string jobTitleString) { HelperMethods.AddLogs("Enter into FormatYourConnectionJobTitle"); int noOfCharInOneLine = 27; string formatedString = string.Empty; string jobTitle = jobTitleString; string lastCharOfEachLine = string.Empty; if (jobTitleString.Length > noOfCharInOneLine) { HelperMethods.AddLogs(string.Format("FormatYourConnectionJobTitle Actual job title String-> {0}.", jobTitleString)); for (int i = 0; i < 3; i++) { string tempSubString = string.Empty; if (jobTitle.Length > noOfCharInOneLine) { lastCharOfEachLine = jobTitle.Substring(noOfCharInOneLine, 1); if (string.IsNullOrWhiteSpace(lastCharOfEachLine)) { formatedString += jobTitle.Substring(0, noOfCharInOneLine) + (i == 2 ? "..." : "<br />"); jobTitle = jobTitle.Substring(noOfCharInOneLine); } else { tempSubString = jobTitle.Substring(0, noOfCharInOneLine); if (tempSubString.LastIndexOf(" ") > 0) { formatedString += tempSubString.Substring(0, tempSubString.LastIndexOf(" ")) + (i == 2 ? "..." : "<br />"); jobTitle = jobTitle.Substring(tempSubString.LastIndexOf(" ")); } else { formatedString += jobTitle.Substring(0, noOfCharInOneLine) + (i == 2 ? "..." : "<br />"); jobTitle = jobTitle.Substring(noOfCharInOneLine); } } HelperMethods.AddLogs(string.Format("FormatYourConnectionJobTitle job title Substring({0})-> {1}.", i.ToString(), jobTitle)); } else { formatedString += jobTitle; break; } } } else { formatedString = jobTitleString; } HelperMethods.AddLogs("Exit from FormatYourConnectionJobTitle"); return(formatedString); }
/// <summary> /// This method execute web request to get response. /// </summary> /// <param name="request">request string to execute.</param> /// <returns>Response stream</returns> public Stream ExecuteWebRequest(string request, ref Int32 statusCode) { Stream responseStream = null; try { HttpWebRequest httpRequest = WebRequest.Create(request) as HttpWebRequest; int requestTimeoutTime = 30 * 60 * 1000;// i.e. 30 mins httpRequest.Timeout = requestTimeoutTime; HttpWebResponse response = httpRequest.GetResponse() as HttpWebResponse; statusCode = Convert.ToInt32(response.StatusCode); if (response.StatusCode != HttpStatusCode.OK) { statusCode = Convert.ToInt32(response.StatusCode); System.Diagnostics.Debug.WriteLine("Http Request Error: StatusCode: " + response.StatusCode + "Description : " + response.StatusDescription); HelperMethods.AddLogs(string.Format("ExecuteWebRequest: Http Request Error: StatusCode = {0}, Description = {1}", response.StatusCode, response.StatusDescription)); } // Get response stream responseStream = response.GetResponseStream(); // Dispose the response stream. //responseStream.Dispose(); } catch (WebException webException) { HttpWebResponse webResponse = webException.Response as HttpWebResponse; if (webResponse != null) { statusCode = Convert.ToInt32(webResponse.StatusCode); } else { statusCode = Convert.ToInt32(webException.Status); } } catch (Exception ex) { HelperMethods.AddLogs(string.Format("ExecuteWebRequest: Exception = {0}", ex.Message)); } return(responseStream); }
/// <summary> /// This method removes specfic words(blacklist words) from company name. /// </summary> /// <param name="companyName">companyName</param> /// <returns>string with replaced words form string.</returns> public static string IgnoreBlackListWordFromCompanyName(string companyName) { if (listOfBlacklistedWords.Count == 0) { lock (_singletonLock) { if (listOfBlacklistedWords.Count == 0) { HelperMethods.AddLogs("IgnoreBlackListWordFromCompanyName: ListOfBlacklistedWords count is zero. So get List of blacklist companies from database."); OFunnelDatabaseHandler databaseHandler = new OFunnelDatabaseHandler(); DataSet dataSet = databaseHandler.GetBlacklistedWords(); // creating list of Blacklisted Words to compare two companies. if (HelperMethods.IsValidDataSet(dataSet) && dataSet.Tables[0].Rows.Count > 0) { for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++) { listOfBlacklistedWords.Add(Convert.ToString(dataSet.Tables[0].Rows[i]["words"])); } } } } } string companyNameAfterIgnoringBlacklisteddWord = companyName; if (!string.IsNullOrEmpty(companyNameAfterIgnoringBlacklisteddWord)) { if (listOfBlacklistedWords != null && listOfBlacklistedWords.Count > 0) { StringBuilder companyNameBuilder = new StringBuilder(" " + companyNameAfterIgnoringBlacklisteddWord.ToUpper() + " "); string replaceWith = " "; foreach (string blackListWord in listOfBlacklistedWords) { companyNameBuilder.Replace(" " + blackListWord.ToUpper() + " ", replaceWith); } companyNameAfterIgnoringBlacklisteddWord = companyNameBuilder.ToString().Trim(); } } return(companyNameAfterIgnoringBlacklisteddWord); }
/// <summary> /// This method execute web request to check server status. /// </summary> /// <param name="request">request string to execute.</param> /// <returns>Response stream</returns> public Stream ExecuteWebRequest(string request, ref int statusCode, ref string statusDescription, ref string errorMessage) { Stream responseStream = null; try { statusCode = 1000; statusDescription = "Unknown"; errorMessage = "Unknown error has occured."; HttpWebRequest httpRequest = WebRequest.Create(request) as HttpWebRequest; HttpWebResponse response = httpRequest.GetResponse() as HttpWebResponse; statusCode = Convert.ToInt32(response.StatusCode); statusDescription = response.StatusDescription; errorMessage = string.Empty; if (response.StatusCode != HttpStatusCode.OK) { statusCode = Convert.ToInt32(response.StatusCode); statusDescription = response.StatusDescription; errorMessage = string.Empty; System.Diagnostics.Debug.WriteLine("Http Request Error: StatusCode: " + response.StatusCode + "Description : " + response.StatusDescription); HelperMethods.AddLogs(string.Format("ExecuteWebRequest: Http Request Error: StatusCode = {0}, Description = {1}", response.StatusCode, response.StatusDescription)); } // Get response stream responseStream = response.GetResponseStream(); // Dispose the response stream. //responseStream.Dispose(); } catch (WebException webException) { try { HttpWebResponse webResponse = webException.Response as HttpWebResponse; if (webResponse != null) { statusCode = Convert.ToInt32(webResponse.StatusCode); statusDescription = webResponse.StatusDescription; Stream stream = webResponse.GetResponseStream(); StreamReader streamReader = new StreamReader(stream); string textErrorMessage = streamReader.ReadToEnd(); errorMessage = textErrorMessage; } else { statusCode = Convert.ToInt32(webException.Status); statusDescription = "WebException Status Messgae =>" + webException.Message; errorMessage = webException.StackTrace; } } catch (Exception ex) { statusCode = 1008; statusDescription = "ExceptionOccurred"; errorMessage = ex.Message; HelperMethods.AddLogs(string.Format("ExecuteWebRequest: Exception occurred when handling WebException Exception = {0}", ex.Message)); } } catch (Exception ex) { HelperMethods.AddLogs(string.Format("ExecuteWebRequest: Exception = {0}", ex.Message)); statusCode = 1008; statusDescription = "ExceptionOccurred"; errorMessage = ex.Message; } return(responseStream); }
/// <summary> /// This method returns LinkedIn list for specified userId /// </summary> /// <param name="userId">userId</param> /// <returns>Response string</returns> public string GetLinkedInListWithUserId(string userId) { string responseData = string.Empty; try { NameValueCollection nameValue = new NameValueCollection(); nameValue["userId"] = userId; string message = HelperMethods.GetParametersListForLogMessage(nameValue); HelperMethods.AddLogs("Enter into GetLinkedInListWithUserId. Parameters List => " + message); if (!string.IsNullOrEmpty(userId)) { OFunnelDatabaseHandler oFunnelDatabaseHandler = new OFunnelDatabaseHandler(); DataSet dataSet = oFunnelDatabaseHandler.GetLinkedInAccessTokenFromUserId("'" + userId + "'"); if (HelperMethods.IsValidDataSet(dataSet)) { string authToken = Convert.ToString(dataSet.Tables[0].Rows[0]["accessToken"]); if (!string.IsNullOrEmpty(authToken)) { // Create request to get profile from LinkedIn. string linkedInListUrl = this.CreateRequestToGetLinkedInListFromLinkedIn(authToken); if (!string.IsNullOrEmpty(linkedInListUrl)) { Int32 httpStatusCode = -1; Stream response = this.ExecuteRequestToGetResult(linkedInListUrl, ref httpStatusCode); if (response != null) { StreamReader streamReader = new StreamReader(response); responseData = streamReader.ReadToEnd(); response.Dispose(); } else { HelperMethods.AddLogs("GetLinkedInListWithUserId: LinkedIn connections response stream is null so LinkedIn connections not found for this user, either there is no connection for this user or some error occured."); } } } } else { HelperMethods.AddLogs(string.Format("GetLinkedInListWithUserId: Failed to get Access Token from database for userId = {0}.", userId)); } } else { HelperMethods.AddLogs("GetLinkedInListWithUserId: BadRequest as Required parameter {userId} is missing."); } } catch (Exception ex) { HelperMethods.AddLogs(string.Format("GetLinkedInListWithUserId: Failed to get LinkedIn connections from LinkedIn for userId = {0}. Exception Occured {1}", userId, ex.Message)); Debug.WriteLine("Failed to get LinkedIn Connections. Exception: " + ex.Message); } HelperMethods.AddLogs("Exit from GetLinkedInListWithUserId. \n\n"); return(responseData); }