Esempio n. 1
0
        /// <summary>
        /// 구글 파트에서 설정을 불러옵니다.
        /// </summary>
        /// <param name="option"></param>
        public void LoadGoogle(GoogleCSESearchOption option)
        {
            if (option == null)
            {
                option = GoogleCSESearchOption.GetDefault();
            }

            drpGoogle.Since = option.DateRange.Since.GetValueOrDefault();
            drpGoogle.Until = option.DateRange.Until.GetValueOrDefault();

            tbGoogleOffset.Text      = option.Offset.ToString();
            tbGoogleSearchCount.Text = option.SearchCount.ToString();

            goCbOutput1.IsChecked = option.OutputServices.HasFlag(OutputFormat.CSV);
            goCbOutput2.IsChecked = option.OutputServices.HasFlag(OutputFormat.Json);
            goCbOutput3.IsChecked = option.OutputServices.HasFlag(OutputFormat.MySQL);
            goCbOutput4.IsChecked = option.OutputServices.HasFlag(OutputFormat.AccessDB);

            googleCountry.SelectedIndex = (int)option.CountryCode;

            useGoogleDate.IsChecked = option.UseDateSearch;

            if (option.SplitWithDate)
            {
                rbGoogleSplitWithDate.IsChecked = true;
            }
            else
            {
                rbGoogleNoSplit.IsChecked = true;
            }
        }
Esempio n. 2
0
        public void SearchGoogle()
        {
            // 동일한 서비스는 끝나기 전까지 실행이 불가능함.
            if (googleSearching)
            {
                AddLog("이미 Google CSE 서비스에서 검색을 실행중입니다.", TaskLogType.Failed);
                return;
            }

            // 날짜 유효성 미리 검사

            if (SettingManager.GoogleCSESearchOption.UseDateSearch)
            {
                if (!SettingManager.GoogleCSESearchOption.DateRange.Vaild)
                {
                    AddLog("구글 검색의 날짜 설정이 잘못되었습니다.", TaskLogType.Failed);
                    return;
                }
            }

            googleSearching = true;
            _detailsOption.GoogleEnableChange(false);
            _vertManager.ChangeEditable(false, ServiceKind.GoogleCSE);
            lvGoogle.Items.Clear();

            Thread thr = new Thread(() =>
            {
                var sw = new Stopwatch();
                var googleCSESearcher        = new GoogleCSESearcher();
                bool isCanceled              = false;
                SearchResult info            = SearchResult.Fail_APIError;
                GoogleCSESearchOption option = null;

                googleCSESearcher.SearchProgressChanged += Searcher_SearchProgressChanged;
                googleCSESearcher.SearchFinished        += Searcher_SearchFinished;
                googleCSESearcher.ChangeInfoMessage     += Searcher_ChangeInfoMessage;
                googleCSESearcher.SearchItemFound       += Searcher_SearchItemFound;

                Dispatcher.Invoke(() =>
                {
                    sw.Start();
                    AddLog("Google CSE 검색 엔진을 초기화중입니다.", TaskLogType.SearchReady);

                    option       = SettingManager.GoogleCSESearchOption;
                    option.Query = tbQuery.Text;

                    var tb = new TaskProgressBar();

                    tb.SetValue(title: "Google CSE 검색", message: "검색이 진행중입니다.", maximum: 1);

                    lvTask.Items.Insert(0, tb);
                    dict[googleCSESearcher] = tb;

                    if (option.OutputServices == OutputFormat.None)
                    {
                        tb.SetValue(message: "결과를 내보낼 위치가 없습니다.", maximum: 1);
                        AddLog("검색을 내보낼 위치가 없습니다.", TaskLogType.Failed);
                        tb.TaskFinished = true;
                        info            = SearchResult.Fail_InvaildSetting;
                        isCanceled      = true;
                    }

                    googleCSESearcher.Vertification(SettingManager.GoogleCredentials.Item1, SettingManager.GoogleCredentials.Item3);

                    if (!googleCSESearcher.IsVerification) // 인증되지 않았을 경우
                    {
                        tb.SetValue(message: "API키가 인증되지 않았습니다.", maximum: 1);
                        tb.TaskFinished = true;
                        AddLog("API키가 인증되지 않았습니다.", TaskLogType.Failed);

                        info       = SearchResult.Fail_APIError;
                        isCanceled = true;
                    }
                });

                IEnumerable <GoogleCSESearchResult> googleResult = null;
                ExportResultPack pack = null;

                if (!isCanceled)
                {
                    try
                    {
                        googleResult = googleCSESearcher.Search(option);

                        if (googleResult.Count() == 0)
                        {
                            info = SearchResult.Fail_NoResult;
                            AddLog("검색 결과가 없습니다.", TaskLogType.Failed);
                        }
                        else
                        {
                            info = SearchResult.Success;
                            AddLog("검색 결과를 내보내는 중입니다.", TaskLogType.Searching);
                            pack = Export(option.OutputServices, googleResult, ServiceKind.GoogleCSE);
                        }
                    }
                    catch (InvaildOptionException)
                    {
                        AddLog("'Google CSE' 검색 중 오류가 발생했습니다. [날짜를 사용하지 않은 상태에서는 '하루 기준' 옵션을 사용할 수 없습니다.]", TaskLogType.Failed);
                        info = SearchResult.Fail_InvaildSetting;
                    }
                    catch (Exception)
                    {
                        AddLog("'Google CSE' 검색 중 오류가 발생했습니다. [잘못된 인증 정보를 입력했습니다.]", TaskLogType.Failed);
                        info = SearchResult.Fail_APIError;
                        Dispatcher.Invoke(() =>
                        {
                            SettingManager.GoogleCredentials.Item2 = VerifyType.Invalid;
                            SettingManager.GoogleCredentials.Item4 = VerifyType.Invalid;
                        });
                    }
                    if (info != SearchResult.Success)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            dict[googleCSESearcher].SetValue(message: "설정 오류가 발생했습니다.", maximum: 1);
                            dict[googleCSESearcher].TaskFinished = true;
                        });
                    }
                    else if (info != SearchResult.Fail_NoResult)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            dict[googleCSESearcher].SetValue(message: "검색 결과가 없습니다.", maximum: 1);
                            dict[googleCSESearcher].TaskFinished = true;
                        });
                    }
                }

                Dispatcher.Invoke(() => {
                    AddLog($"Google CSE 검색에 소요된 시간 : {sw.ElapsedMilliseconds}ms", TaskLogType.Complete);

                    _taskReport.AddReport(new TaskReportData()
                    {
                        Query            = option.Query,
                        RequestService   = ServiceKind.GoogleCSE,
                        SearchCount      = option.SearchCount,
                        SearchData       = googleResult,
                        SearchDate       = DateTime.Now,
                        SearchResult     = info,
                        OutputFormat     = option.OutputServices,
                        ExportResultPack = pack
                    });

                    _taskReport.SetLastReport();

                    googleSearching = false;
                    _detailsOption.GoogleEnableChange(true);
                    _vertManager.ChangeEditable(true, ServiceKind.GoogleCSE);
                });
            });

            thr.Start();
        }
Esempio n. 3
0
        static SettingManager()
        {
            _exportOptionSetting = new ObjectSerializer <ExportOptionSetting>().Deserialize(AppSetting.ExportOption);

            if (_exportOptionSetting == null)
            {
                _exportOptionSetting = new ExportOptionSetting()
                {
                    AccessFileName       = string.Empty,
                    AccessFolderLocation = string.Empty,
                    CSVFileName          = string.Empty,
                    CSVFolderLocation    = string.Empty,
                    CSVOverlapOption     = 0,
                    JsonFileName         = string.Empty,
                    JsonFolderLocation   = string.Empty,
                    JsonOverlapOption    = 0,
                    JsonSort             = true,
                    MySQLConnAddr        = "localhost",
                    MySQLConnString      = string.Empty,
                    MySQLDatabaseName    = "plurcrawler",
                    MySQLManualInput     = false,
                    MySQLUserID          = string.Empty,
                    MySQLUserPassword    = string.Empty,
                }
            }
            ;

            _googleCSESearchOption = new ObjectSerializer <GoogleCSESearchOption>().Deserialize(AppSetting.GoogleOption);

            if (_googleCSESearchOption == null)
            {
                GoogleCSESearchOption = GoogleCSESearchOption.GetDefault();
            }

            _twitterSearchOption = new ObjectSerializer <TwitterSearchOption>().Deserialize(AppSetting.TwitterOption);

            if (_twitterSearchOption == null)
            {
                TwitterSearchOption = TwitterSearchOption.GetDefault();
            }

            _youtubeSearchOption = new ObjectSerializer <YoutubeSearchOption>().Deserialize(AppSetting.YoutubeOption);

            if (_youtubeSearchOption == null)
            {
                YoutubeSearchOption = YoutubeSearchOption.GetDefault();
            }

            _tutorialView = AppSetting.TutorialView;

            if (AppSetting.GoogleCredentials.IsNullOrEmpty())
            {
                AppSetting.GoogleCredentials = "//";
                AppSetting.Save();
            }

            string[] gocredentials = AppSetting.GoogleCredentials.Split("//");

            _googleCredentials = new Pair <string, VerifyType, string, VerifyType>()
            {
                Item1 = gocredentials[0],
                Item2 = AppSetting.GoogleKeyVertified,
                Item3 = gocredentials[1],
                Item4 = AppSetting.GoogleIDVertified,
            };

            if (AppSetting.TwitterCredentials.IsNullOrEmpty())
            {
                AppSetting.TwitterCredentials = "//";
                AppSetting.Save();
            }

            string[] twcredentials = AppSetting.TwitterCredentials.Split("//");

            _twitterCredentials = new Pair <string, string>()
            {
                Item1 = twcredentials[0],
                Item2 = twcredentials[1],
            };


            _youtubeCredentials = new Pair <string, VerifyType>()
            {
                Item1 = AppSetting.YoutubeCredentials,
                Item2 = AppSetting.YoutubeVertified,
            };


            if (AppSetting.EngineUsage.IsNullOrEmpty())
            {
                AppSetting.EngineUsage = "False|False|False";
                AppSetting.Save();
            }

            IEnumerable <bool> engineBools = AppSetting.Default.EngineUsage.Split("|")
                                             .Select(i => Convert.ToBoolean(i));

            _engineUsage = new Pair <bool, bool, bool>()
            {
                Item1 = engineBools.ElementAt(0),
                Item2 = engineBools.ElementAt(1),
                Item3 = engineBools.ElementAt(2),
            };

            // End Of Load

            ExportOptionSetting.PropertyChanged   += ExportOptionSetting_PropertyChanged;
            GoogleCSESearchOption.PropertyChanged += GoogleCSESearchOption_PropertyChanged;
            TwitterSearchOption.PropertyChanged   += TwitterSearchOption_PropertyChanged;
            EngineUsage.PropertyChanged           += EngineUsage_PropertyChanged;
            GoogleCredentials.PropertyChanged     += GoogleCredentials_PropertyChanged;
            TwitterCredentials.PropertyChanged    += TwitterCredentials_PropertyChanged;
            YoutubeCredentials.PropertyChanged    += YoutubeCredentials_PropertyChanged;
            YoutubeSearchOption.PropertyChanged   += YoutubeSearchOption_PropertyChanged;
        }