/// <summary>
        /// 
        /// </summary>
        /// <param name="searchItem"></param>
        /// <param name="seachLocation"></param>
        /// <returns></returns>
        public void AnalyzeSearch(string searchItem, string seachLocation)
        {
            Handlers.EventHandlers.SearchAnalysisStartingEventArgs _ea = new Handlers.EventHandlers.SearchAnalysisStartingEventArgs();
            InvokeEventSearchAnalysisStarting(_ea);
            if(!_ea.cancel)
            {
                _DirectoryProviderRoutineStage = DirectoryProviderRoutineStageEnum.SearchAnalysisStarting;
                new Thread(() =>
                            {
                                this.ForceStopSearchAnalysis = false;
                                this._IsBusy = true;

                                string _htmlDoc = string.Empty;
                                bool _resultIsError = false;

                                if(this._SearchItem == null) this._SearchItem = new SearchItem();
                                if(!string.IsNullOrEmpty(searchItem) && !string.IsNullOrEmpty(seachLocation))
                                {
                                    this._SearchItem.searchItem = searchItem;
                                    this._SearchItem.searchLocation = seachLocation;
                                }

                                _htmlDoc = this.GenerateSearchResultPageCallback(ref _resultIsError);

                                if(_resultIsError)
                                    throw new Exception(string.Format("The search page generated contains error: {0}", _htmlDoc));

                                if(this.ForceStopSearchAnalysis) return;

                                if(!string.IsNullOrEmpty(_htmlDoc)) AnalyzeSearch(_htmlDoc);

                            })
                            {
                                IsBackground = true
                            }
                            .Start();
            }
        }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {

            //Define the directorySettings to be used
            DirectoryProviderSetting.DirectoryProviderSettings _dirSettings = new DirectoryProviderSetting.DirectoryProviderSettings();
            DirectoryProviderSetting _dirSet = _dirSettings.Where(p => p.ServicedCountry == ServicedCountryEnum.Australia).FirstOrDefault();

            //Proceed if setting for Canada exist
            if(_dirSet != null)
            {

                //Define the item to be searched...
                SearchItem _searchItem = new SearchItem()
                {
                    /*
                     searchItem = "lawyers",
                    searchLocation = "sydney",
                     */
                    searchItem = "software company",
                    searchLocation = "sydney",
                    pagesToProcess = 2
                };

                Console.WriteLine(string.Format("Initializing search parameters for YP {0}: \r\nSearching {1} in {2}\r\nProcessing {3}.",
                                    _dirSet.ServicedCountry.ToString(),
                                    _searchItem.searchItem,
                                    _searchItem.searchLocation,
                                    !_searchItem.pagesToProcess.HasValue ? "all of the pages" : _searchItem.pagesToProcess.ToString() + " pages only."));

                //Select the provider to execute this search
                IDirectoryProvider _dirProvider = null;
                switch(_dirSet.ServicedCountry)
                {
                    case ServicedCountryEnum.Canada:
                        _dirProvider = new DirectoryProviderCanada(_dirSet);
                        break;
                    case ServicedCountryEnum.Australia:
                        _dirProvider = new DirectoryProviderAustralia(_dirSet);
                        break;
                }

                _dirProvider.SearchItem = _searchItem;
                _dirProvider.OnSearchAnalysisStarting += new Core.Handlers.EventHandlers.SearchAnalysisStartingEventHandler(_dirProvider_OnSearchAnalysisStarting);
                _dirProvider.OnSearchAnalysisFinished += new Core.Handlers.EventHandlers.SearchAnalysisFinishedEventHandler(_dirProvider_OnSearchAnalysisFinished);
                //Start or Invoke method StartSearchResultProcess() when OnSearchAnalysisFinished

                _dirProvider.OnProcessStarting += new Core.Handlers.EventHandlers.ProcessStartingEventHandler(_dirProvider_OnProcessStarting);
                _dirProvider.OnProcessFinished += new Core.Handlers.EventHandlers.ProcessFinishedEventHandler(_dirProvider_OnProcessFinished);
                _dirProvider.OnUrlPointerProcessed += new Core.Handlers.EventHandlers.UrlPointerProcessedEventHandler(_dirProvider_OnUrlPointerProcessed);
                _dirProvider.OnAdExtracted += new Core.Handlers.EventHandlers.AdExtractedEventHandler(_dirProvider_OnAdExtracted);
                _dirProvider.OnFrameworkException += new Core.Handlers.EventHandlers.FrameworkExceptionEventHandler(_dirProvider_OnFrameworkException);

                _dirProvider.AnalyzeSearch();

                new Thread(() =>
                    {
                        lock(typeof(Program))
                        {
                            while(true)
                            {
                                Thread.Sleep(1000);
                                Console.Write(@".");

                                if(_finished)
                                {
                                    Console.WriteLine("Press ENTER to exit!");
                                    break;
                                }
                            }
                        }
                    }) { IsBackground = true }
                    .Start();

                Console.ReadLine();
                _finished = true;
            }
        }
Пример #3
0
 public SearchAnalysisFinishedEventArgs(SearchItem SearchResult, TimeSpan Elapsed)
 {
     this.SearchResult = SearchResult;
     this.Elapsed = Elapsed;
 }