示例#1
0
        // Facebook Constructor
        public Facebook()
        {
            Biz.SN.SNXmlAutoBiz oBiz = null;
            Hashtable ht = new Hashtable();
            DataSet dsAccessToken = null;

            try
            {
                // 조회 대상 키워드 조회
                oBiz = new SNXmlAutoBiz();
                ht.Add("SNSAPIKEYTYPE", "FACEBOOK_ACCESSTOKEN");

                dsAccessToken = oBiz.XmlGetData("uspSNSAPIKeyMgmtView", ht);

                if (dsAccessToken != null)
                {
                    // Token 정보 조회
                    _accessToken = dsAccessToken.Tables[0].Rows[0]["SNSAPIKeyValue"].ToString();
                }
            }
            catch (Exception ex)
            {
                log.Error("Facebook>GetAccessToken> " + ex.ToString());
            }
            finally
            {
                if (oBiz != null)
                    oBiz = null;
            }
        }
示例#2
0
        /// <summary>
        /// Facebook 검색 시작
        /// </summary>
        public void StartSearch()
        {
            Biz.SN.SNXmlAutoBiz oBiz = null;
            Hashtable ht = new Hashtable();
            DataSet dsKeywords = null;

            try
            {
                // 조회 대상 키워드 조회
                oBiz = new SNXmlAutoBiz();

                ht.Add("CHANNELTYPE", "20"); // Facebook 키워드 조회
                dsKeywords = oBiz.XmlGetData("uspKeywordList", ht);

                #region    키워드 조회 Function
                Func<object, int> action = (object oKeyword) =>
                {
                    int result = 0;
                    string searchKeyword = "";
                    string keywordId = "";
                    string keyword = "";
                    string exceptKeyword = "";
                    string pagingNext = "";

                    DataRow k = (DataRow)oKeyword;

                    keywordId = k["KeywordId"].ToString();
                    keyword = k["Keyword"].ToString();
                    exceptKeyword = k["ExceptKeyword"].ToString();
                    pagingNext = k["PagingNextUrl"].ToString();

                    // 수집 키워드
                    // 쉼표(,)를 기준으로 복수개의 관심주제어가 존재할 경우 처리
                    // e.g. 넥서스7,nexus7
                    /*if (keyword.IndexOf(',') < 0)
                    {
                        searchKeyword = keyword.Trim();
                    }
                    else
                    {
                        string[] Skeywords = keyword.Split(',');
                        foreach (string sk in Skeywords)
                        {
                            searchKeyword += sk.Trim() + " OR ";
                        }

                        if (searchKeyword.Substring(searchKeyword.Length - 3, 3) == "OR ")
                            searchKeyword = searchKeyword.Substring(0, searchKeyword.Length - 3);
                    }
                    */

                    // 포함할 키워드
                    if (!String.IsNullOrEmpty(keyword))
                    {
                        if (keyword.IndexOf(',') < 0)
                        {
                            searchKeyword += HttpUtility.UrlEncode(keyword.Trim(), Encoding.UTF8);
                        }
                        else
                        {
                            string[] Skeywords = keyword.Split(',');
                            foreach (string sk in Skeywords)
                            {
                                searchKeyword += HttpUtility.UrlEncode(sk.Trim(), Encoding.UTF8) + "|";
                            }

                            if (searchKeyword.Substring(searchKeyword.Length - 1, 1) == "|")
                                searchKeyword = searchKeyword.Substring(0, searchKeyword.Length - 1);
                        }
                    }

                    // 제외할 키워드
                    // Facebook API 는 제외를 지원하지 않음
                    /*
                    if (!String.IsNullOrEmpty(exceptKeyword))
                    {
                        if (exceptKeyword.IndexOf(',') < 0)
                        {
                            searchKeyword += " -" + exceptKeyword.Trim() + " ";
                        }
                        else
                        {
                            string[] Skeywords = exceptKeyword.Split(',');
                            foreach (string sk in Skeywords)
                            {
                                searchKeyword += " -" + sk.Trim() + " ";
                            }

                        }
                    } */

                    searchKeyword = searchKeyword.Replace("  ", " ").Trim();

                    // Keyword 검색
                    Facebook t = new Facebook();

                    t.SearchFacebook(keywordId, searchKeyword, exceptKeyword, pagingNext);

                    return result;
                };
                #endregion 키워드 조회 Function

                #region    키워드 조회 Task

                if (dsKeywords != null)
                {
                    if (dsKeywords.Tables[0].Rows.Count > 0)
                    {
                        // 키워드 갯수 만큼 Task 생성하여 조회
                        Task<int>[] tasks = new Task<int>[dsKeywords.Tables[0].Rows.Count];
                        int taskIdx = 0;

                        foreach (DataRow dr in dsKeywords.Tables[0].Rows)
                        {
                            tasks[taskIdx] = Task<int>.Factory.StartNew(action, dr);

                            taskIdx++;
                        }

                        Task.WaitAll(tasks);
                    }
                }

                #endregion 키워드 조회 Task
            }
            catch (Exception ex)
            {
                log.Error("Facebook>Start Search>" + ex.ToString());
            }
            finally
            {
                if (oBiz != null)
                    oBiz = null;
            }
        }