public void GetSearchData(object parameters)
        {
            #region Twitter

            Array arrayParams = (Array)parameters;

            DiscoverySearch           dissearch       = (DiscoverySearch)arrayParams.GetValue(0);
            DiscoverySearchRepository dissearchrepo   = (DiscoverySearchRepository)arrayParams.GetValue(1);
            DiscoverySearch           discoverySearch = (DiscoverySearch)arrayParams.GetValue(2);

            oAuthTwitter oauth = new oAuthTwitter();
            oauth.ConsumerKey       = ConfigurationManager.AppSettings["consumerKey"].ToString();
            oauth.ConsumerKeySecret = ConfigurationManager.AppSettings["consumerSecret"].ToString();
            oauth.CallBackUrl       = ConfigurationManager.AppSettings["callbackurl"].ToString();


            TwitterAccountRepository twtAccRepo = new TwitterAccountRepository();
            //ArrayList alst = twtAccRepo.getAllTwitterAccounts();
            ArrayList alst = twtAccRepo.getAllTwitterAccountsOfUser(discoverySearch.UserId);
            foreach (TwitterAccount item in alst)
            {
                oauth.AccessToken       = item.OAuthToken;
                oauth.AccessTokenSecret = item.OAuthSecret;
                oauth.TwitterUserId     = item.TwitterUserId;
                oauth.TwitterScreenName = item.TwitterScreenName;
                if (TwitterHelper.CheckTwitterToken(oauth, discoverySearch.SearchKeyword))
                {
                    break;
                }
                else
                {
                }
            }

            GlobusTwitterLib.Twitter.Core.SearchMethods.Search search = new GlobusTwitterLib.Twitter.Core.SearchMethods.Search();
            Newtonsoft.Json.Linq.JArray twitterSearchResult           = search.Get_Search_Tweets(oauth, discoverySearch.SearchKeyword);

            foreach (var item in twitterSearchResult)
            {
                var results = item["statuses"];

                foreach (var chile in results)
                {
                    try
                    {
                        dissearch.CreatedTime     = SocioBoard.Helper.Extensions.ParseTwitterTime(chile["created_at"].ToString().TrimStart('"').TrimEnd('"'));;
                        dissearch.EntryDate       = DateTime.Now;
                        dissearch.FromId          = chile["user"]["id_str"].ToString().TrimStart('"').TrimEnd('"');
                        dissearch.FromName        = chile["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                        dissearch.ProfileImageUrl = chile["user"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"');
                        dissearch.SearchKeyword   = discoverySearch.SearchKeyword;
                        dissearch.Network         = "twitter";
                        dissearch.Message         = chile["text"].ToString().TrimStart('"').TrimEnd('"');
                        dissearch.MessageId       = chile["id_str"].ToString().TrimStart('"').TrimEnd('"');
                        dissearch.Id     = Guid.NewGuid();
                        dissearch.UserId = discoverySearch.UserId;//user.Id;


                        if (!dissearchrepo.isKeywordPresent(dissearch.SearchKeyword, dissearch.MessageId))
                        {
                            dissearchrepo.addNewSearchResult(dissearch);
                        }
                    }
                    catch (Exception ex)
                    {
                        //logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.StackTrace);
                    }
                }
            }
            #endregion
        }
        public string getresults(string keyword)
        {
            User   user      = (User)Session["LoggedUser"];
            int    i         = 0;
            string searchRes = string.Empty;

            if (!string.IsNullOrEmpty(keyword))
            {
                DiscoverySearch           dissearch     = new DiscoverySearch();
                DiscoverySearchRepository dissearchrepo = new DiscoverySearchRepository();

                //Get data from Database if present, against the specified keyword
                List <DiscoverySearch> discoveryList = dissearchrepo.getResultsFromKeyword(keyword);

                if (discoveryList.Count == 0) //if no data, get the data for specified keyword from social media apis
                {
                    #region Twitter

                    try
                    {
                        oAuthTwitter oauth = new oAuthTwitter();
                        oauth.ConsumerKey       = ConfigurationManager.AppSettings["consumerKey"].ToString();
                        oauth.ConsumerKeySecret = ConfigurationManager.AppSettings["consumerSecret"].ToString();
                        oauth.CallBackUrl       = ConfigurationManager.AppSettings["callbackurl"].ToString();
                        TwitterAccountRepository twtAccRepo = new TwitterAccountRepository();
                        ArrayList alst = twtAccRepo.getAllTwitterAccounts();
                        foreach (TwitterAccount item in alst)
                        {
                            oauth.AccessToken       = item.OAuthToken;
                            oauth.AccessTokenSecret = item.OAuthSecret;
                            oauth.TwitterUserId     = item.TwitterUserId;
                            oauth.TwitterScreenName = item.TwitterScreenName;
                            if (TwitterHelper.CheckTwitterToken(oauth, keyword))
                            {
                                break;
                            }
                            else
                            {
                            }
                        }

                        Search search = new Search();
                        JArray twitterSearchResult = search.Get_Search_Tweets(oauth, keyword);

                        foreach (var item in twitterSearchResult)
                        {
                            var results = item["statuses"];

                            foreach (var chile in results)
                            {
                                try
                                {
                                    dissearch.CreatedTime     = SocioBoard.Helper.Extensions.ParseTwitterTime(chile["created_at"].ToString().TrimStart('"').TrimEnd('"'));;
                                    dissearch.EntryDate       = DateTime.Now;
                                    dissearch.FromId          = chile["user"]["id_str"].ToString().TrimStart('"').TrimEnd('"');
                                    dissearch.FromName        = chile["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                                    dissearch.ProfileImageUrl = chile["user"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"');
                                    dissearch.SearchKeyword   = txtSearchText.Text;
                                    dissearch.Network         = "twitter";
                                    dissearch.Message         = chile["text"].ToString().TrimStart('"').TrimEnd('"');
                                    dissearch.MessageId       = chile["id_str"].ToString().TrimStart('"').TrimEnd('"');
                                    dissearch.Id     = Guid.NewGuid();
                                    dissearch.UserId = user.Id;

                                    string postID  = chile["id"].ToString();
                                    string postURL = "https://twitter.com/" + dissearch.FromName + "/status/" + postID;

                                    if (!dissearchrepo.isKeywordPresent(dissearch.SearchKeyword, dissearch.MessageId))
                                    {
                                        dissearchrepo.addNewSearchResult(dissearch);
                                    }

                                    searchRes += this.BindData(dissearch, i, postURL);


                                    i++;
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.StackTrace);
                    }
                    #endregion
                    #region Facebook
                    try
                    {
                        #region FacebookSearch
                        int    j           = 0;
                        string accesstoken = string.Empty;
                        FacebookAccountRepository fbAccRepo = new FacebookAccountRepository();
                        ArrayList asltFbAccount             = fbAccRepo.getAllFacebookAccounts();
                        foreach (FacebookAccount item in asltFbAccount)
                        {
                            accesstoken = item.AccessToken;
                            if (FacebookHelper.CheckFacebookToken(accesstoken, txtSearchText.Text))
                            {
                                break;
                            }
                        }

                        string facebookSearchUrl = "https://graph.facebook.com/search?q=" + txtSearchText.Text + " &type=post&access_token=" + accesstoken;
                        var    facerequest       = (HttpWebRequest)WebRequest.Create(facebookSearchUrl);
                        facerequest.Method = "GET";
                        string outputface = string.Empty;
                        using (var response = facerequest.GetResponse())
                        {
                            using (var stream = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1252)))
                            {
                                outputface = stream.ReadToEnd();
                            }
                        }
                        if (!outputface.StartsWith("["))
                        {
                            outputface = "[" + outputface + "]";
                        }


                        JArray facebookSearchResult = JArray.Parse(outputface);

                        foreach (var item in facebookSearchResult)
                        {
                            var data = item["data"];

                            foreach (var chile in data)
                            {
                                try
                                {
                                    dissearch.CreatedTime     = DateTime.Parse(chile["created_time"].ToString());
                                    dissearch.EntryDate       = DateTime.Now;
                                    dissearch.FromId          = chile["from"]["id"].ToString();
                                    dissearch.FromName        = chile["from"]["name"].ToString();
                                    dissearch.ProfileImageUrl = "http://graph.facebook.com/" + chile["from"]["id"] + "/picture?type=small";
                                    dissearch.SearchKeyword   = txtSearchText.Text;
                                    dissearch.Network         = "facebook";
                                    dissearch.Message         = chile["message"].ToString();
                                    dissearch.MessageId       = chile["id"].ToString();
                                    dissearch.Id     = Guid.NewGuid();
                                    dissearch.UserId = user.Id;

                                    string postURL = "https://www.facebook.com/" + dissearch.MessageId;

                                    if (!dissearchrepo.isKeywordPresent(dissearch.SearchKeyword, dissearch.MessageId))
                                    {
                                        dissearchrepo.addNewSearchResult(dissearch);
                                    }
                                    searchRes += this.BindData(dissearch, i, postURL);
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.StackTrace);
                    }
                    #endregion

                    #endregion
                }
                else // if data is there, bind data from databse
                {
                    foreach (DiscoverySearch item in discoveryList)
                    {
                        string postURL = string.Empty;
                        if (item.Network == "facebook")
                        {
                            postURL = "https://www.facebook.com/" + item.MessageId;;
                        }
                        else if (item.Network == "twitter")
                        {
                            postURL = "https://twitter.com/" + item.FromName + "/status/" + item.MessageId;
                        }

                        searchRes += this.BindData(item, i, postURL);
                        i++;
                    }
                }
            }
            return(searchRes);
        }