예제 #1
0
        /// <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 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);
        }