Example #1
0
    public SearchError(Image image, SearchEngineType source, string error)
        : base(image, source)
    {
        ArgumentValidator.NotNull(() => image, () => error);

        Error = error;
    }
Example #2
0
    protected SearchResult(Image image, SearchEngineType source)
    {
        ArgumentValidator.NotNull(() => image);

        Image  = image;
        Source = source;
    }
    private ISearchEngine CreateSearchEngine(SearchEngineType type)
    {
        var fabric       = _booruLoaderFabrics.SingleMaybe(x => x.ForType == type);
        var loaderFabric = fabric.SelectOrElse(x => x, () => throw new NotImplementedException());

        return(_booruSearchEngineFactory.Create(loaderFabric.Create(), type));
    }
Example #4
0
        public void FromXMLObject(XMLObject xmlObject)
        {
            SearchEngineResult result = GetSearchEngineResultFromXMLObject(xmlObject);

            this._searchEngine = result._searchEngine;
            this._searchUrl    = result._searchUrl;
            this._results      = result._results;
        }
Example #5
0
        public static ISearchEngineFactory GetFactory(this SearchEngineType seType)
        {
            if (_map.ContainsKey(seType))
            {
                return(_map[seType]);
            }

            throw new Exception(string.Format("Undefined factory of engine {0}", seType));
        }
Example #6
0
        /// <summary>
        /// Find all positions of a search item
        /// </summary>
        /// <param name="keyWords">List of key words to search for</param>
        /// <param name="searchItem">Search criteria (e.g. website URL)</param>
        /// <param name="type">Search engine type</param>
        /// <param name="maxSearchResults"></param>
        /// <returns>An array of numbers represnting positions of serch results matching your criteria</returns>
        public async Task <IEnumerable <int> > GetRatings(
            IEnumerable <string> keyWords,
            string searchItem,
            SearchEngineType type,
            int maxSearchResults = 100)
        {
            var searchScraper     = _searchScraperFactory.GetSearchScraperInstance(type);
            var searchResultItems = await searchScraper.Search(keyWords, maxSearchResults);

            return(GetSearchItemPositions(searchResultItems, searchItem));
        }
Example #7
0
 public BooruSearchEngine(
     IBooruAsyncLoader loader,
     SearchEngineType searchEngineType,
     IBooruPostConverter postConverter,
     ILogger <BooruSearchEngine> logger)
 {
     _postConverter   = postConverter;
     _logger          = logger;
     SearchEngineType = searchEngineType;
     _booruLoader     = loader;
 }
        public ISearchStrategy GetSearchStrategy(SearchEngineType searchEngineType, string searchEngineUrl)
        {
            switch (searchEngineType)
            {
            case SearchEngineType.InfoTrack:
                return(new InfoTrackSearchStrategy(searchEngineUrl));

            default:
                return(new InfoTrackSearchStrategy(searchEngineUrl));
            }
        }
Example #9
0
        public ISearchEngine Create(SearchEngineType searchEngineType)
        {
            switch (searchEngineType)
            {
            case SearchEngineType.EpiserverFind:
                return(new EpiserverFind());

            default:
                throw new NotImplementedException("This search type is unsupported");
            }
        }
Example #10
0
        public static IDatasetOptions GetDatasetOption(string engine)
        {
            SearchEngineType set = EnumUtils.StringToEnum(engine, SearchEngineType.Unknown);

            IDatasetOptions op = set.GetFactory().GetOptions();

            if (op == null)
            {
                throw new ArgumentException("It's not defined that how to get dataset option for search engine " + engine);
            }
            return(op);
        }
    private ISearchEngine GetSearchEngineFor(SearchEngineType type)
    {
        if (_searchEngineCache.TryGetValue(type, out var engine))
        {
            return(engine);
        }

        engine = CreateSearchEngine(type);
        _searchEngineCache.Add(type, engine);

        return(engine);
    }
Example #12
0
        public static ISearchEngineHandler Select(
            this IEnumerable <ISearchEngineHandler> searchEngineHandlers,
            SearchEngineType engineType)
        {
            var searchEngine = searchEngineHandlers.SingleOrDefault(seh => seh.EngineType == engineType);

            if (searchEngine == null)
            {
                throw new SearchEngineHandlerNotFound(engineType.ToString());
            }

            return(searchEngine);
        }
        public ISearchStrategy GetSearchStrategy(SearchEngineType searchEngineType, SearchConfiguration searchConfiguration)
        {
            switch (searchEngineType)
            {
            case SearchEngineType.Google:
                return(new GoogleSearchStrategy(searchConfiguration.GoogleSearchUrl, searchConfiguration.MaxSearchResult));

            case SearchEngineType.Bing:
                return(new BingSearchStrategy(searchConfiguration.BingSearchUrl, searchConfiguration.MaxSearchResult));

            default:
                return(new GoogleSearchStrategy(searchConfiguration.GoogleSearchUrl, searchConfiguration.MaxSearchResult));
            }
        }
        //Allow client to override the default if desired
        public static ISearchEngine Create(SearchEngineType type)
        {
            switch (type)
            {
            case SearchEngineType.StartPage:
                return(new StartPageEngine());

                break;

            default:
                return(new StartPageEngine());

                break;
            }
        }
Example #15
0
        public static void LoadFromFile(string fileName, BuildSummaryOptions result)
        {
            XElement root = XElement.Load(fileName);

            var engineNode = root.Element("SearchEngine");

            if (engineNode != null)
            {
                var engine           = engineNode.Value;
                SearchEngineType set = EnumUtils.StringToEnum(engine, SearchEngineType.Unknown);

                AbstractSummaryConfiguration conf;
                switch (set)
                {
                case SearchEngineType.Unknown:
                    throw new ArgumentException("Unknown search engine " + engine);

                case SearchEngineType.MASCOT:
                    conf = new MascotDatSummaryConfiguration("");
                    break;

                case SearchEngineType.SEQUEST:
                    conf = new SequestSummaryConfiguration("");
                    break;

                case SearchEngineType.XTandem:
                    conf = new XTandemXmlSummaryConfiguration("");
                    break;

                case SearchEngineType.PFind:
                    conf = new PFindSummaryConfiguration("");
                    break;

                //case SearchEngineType.PEPTIDEPHOPHET:
                //  op = new PeptideProphetDatasetOptions();
                //  break;
                default:
                    throw new ArgumentException("It's not defined that how to get SummaryConfiguration for search engine " + engine);
                }

                conf.LoadFromFile(fileName);
                conf.ConvertTo(result);
            }
            else
            {
                result.LoadFromFile(fileName);
            }
        }
        private void deactivateUser(SearchEngineType type)
        {
            AddUserBVT.AddUserInit(type);

            //在账户管理窗口的左侧用户列表中,选中一个谷歌用户,点击该用户下任一账户后面的Deactive
            Common.UITestFramework.UIMaps.AccountManagementCenterClasses.AccountManagementCenter accountManagementCenter = new Common.UITestFramework.UIMaps.AccountManagementCenterClasses.AccountManagementCenter();
            switch (type)
            {
                case SearchEngineType.Google:
                    accountManagementCenter.DeactivateGoogleUser();
                    break;
                case SearchEngineType.Adcenter:
                    accountManagementCenter.DeactivateAdcenterUser();
                    break;
                case SearchEngineType.Facebook:
                    accountManagementCenter.DeactivateFacebookUser();
                    break;
            }

            Common.UITestFramework.UIMaps.QuestionWindowClasses.QuestionWindow questionWindow = new Common.UITestFramework.UIMaps.QuestionWindowClasses.QuestionWindow();
            questionWindow.UIQuestionWindow.WaitForControlExist();
            questionWindow.ClickDeactivateButton();
            questionWindow.UIQuestionWindow.WaitForControlNotExist();

            switch (type)
            {
                case SearchEngineType.Google:
                    WinText uISynchronizeaccountsfText = accountManagementCenter.UIAccountManagementCenWindow.UILabel1Window.UISynchronizeaccountsfText;
                    uISynchronizeaccountsfText.WaitForControlNotExist();
                    accountManagementCenter.VerifyActivateGoogleUser();
                    break;
                case SearchEngineType.Adcenter:
                    WinText uISynchronizeaccountsfText1 = accountManagementCenter.UIAccountManagementCenWindow.UILabel1Window.UISynchronizeaccountsfText1;
                    uISynchronizeaccountsfText1.WaitForControlNotExist();
                    accountManagementCenter.VerifyActivateAdcenterUser();
                    break;
                case SearchEngineType.Facebook:
                    WinText uISynchronizeaccountsfText2 = accountManagementCenter.UIAccountManagementCenWindow.UILabel1Window.UISynchronizeaccountsfText2;
                    uISynchronizeaccountsfText2.WaitForControlNotExist();
                    accountManagementCenter.VerifyActivateFacebookUser();
                    break;
            }
            accountManagementCenter.ClickCloseWindowButton();
            accountManagementCenter.UIAccountManagementCenWindow.WaitForControlNotExist();

            Common.UITestFramework.UIMaps.MainWindowClasses.MainWindow mainWindow = new Common.UITestFramework.UIMaps.MainWindowClasses.MainWindow();
            mainWindow.VerifyNoAccount();
        }
    public Metadata(
        Image image,
        SearchEngineType source,
        bool isFound,
        IReadOnlyCollection <Tag> tags,
        IReadOnlyCollection <Note> notes,
        int?fileIdFromSource)
        : base(image, source)
    {
        ArgumentValidator.NotNull(() => image, () => tags, () => notes);

        IsFound          = isFound;
        Tags             = tags;
        Notes            = notes;
        FileIdFromSource = fileIdFromSource;
    }
Example #18
0
        /// <summary>
        /// Gets SEO results for the following required headers:
        /// <param name="searchString"> STRING: The text to execute the search for - i.e. e-Settlements </param>
        /// <param name="targetUrl"> STRING: The URL to check matches for - i.e. sympli.com.au </param>
        /// <param name="resultsCount"> INTEGER: Defines the the top x results to check</param>
        /// <param name="engineTypeId"> INTEGER: From user selection, corresponds with SearchEngineType in enums</param>
        /// </summary>
        /// <returns>SEOSearchEntity with success true if a search has been made and checked, false with error message if not.</returns>
        public SEOSearchEntity Get()
        {
            var headers = Request?.Headers;

            if (headers != null && headers.Any() && headers.Count() == 4)
            {
                string           searchString = "";
                string           targetUrl    = "";
                int              resultsCount = 0;
                SearchEngineType engineType   = SearchEngineType.Unassigned;
                try
                {
                    searchString = headers["searchString"].FirstOrDefault();
                    targetUrl    = headers["targetUrl"].FirstOrDefault();
                    resultsCount = Int32.Parse(headers["resultsCount"].FirstOrDefault());
                    engineType   = (SearchEngineType)Int32.Parse(headers["engineTypeId"].FirstOrDefault());
                }
                catch (Exception e)
                {
                    return(new SEOSearchEntity()
                    {
                        EngineName = "UNSPECIFIED", Success = false, ErrorMessage = $"Missing or incorrectly formatted headers - {e.Message}"
                    });
                }

                //check if we have a mapping engine set up for this engine type (should always be the case since the selection will be a drop down box of the ones we have defined)
                SearchEngineMapper mapper = EngineMappers.FirstOrDefault(t => t.Engine == engineType);
                if (mapper != null)
                {
                    return(GetSearchResults(mapper, searchString, targetUrl, resultsCount));
                }
                else
                {
                    return(new SEOSearchEntity()
                    {
                        EngineName = Enum.GetName(typeof(SearchEngineType), engineType), Success = false, ErrorMessage = "No Mapping for Search Engine Found"
                    });
                }
            }
            else
            {
                return(new SEOSearchEntity()
                {
                    EngineName = "UNSPECIFIED", Success = false, ErrorMessage = "Header Data missing from request"
                });
            }
        }
    public static MetadataSource GetMetadataSource(this SearchEngineType searchEngineType)
    {
        switch (searchEngineType)
        {
        case SearchEngineType.Yandere:
            return(MetadataSource.Yandere);

        case SearchEngineType.Danbooru:
            return(MetadataSource.Danbooru);

        case SearchEngineType.Sankaku:
            return(MetadataSource.Sankaku);

        default:
            throw new ArgumentOutOfRangeException(nameof(searchEngineType), searchEngineType, null);
        }
    }
        private string GetParsingValue(SearchEngineType searchEngineType)
        {
            var parsedValue = string.Empty;

            switch (searchEngineType)
            {
            case SearchEngineType.Google:
                parsedValue = "div class=\"ZINbbc xpd O9g5cc uUPGi\"";
                break;

            case SearchEngineType.Bing:
                parsedValue = "li class=\"b_algo\"";
                break;
            }

            return(parsedValue);
        }
Example #21
0
        private void deleteUser(SearchEngineType type)
        {
            AddUserBVT.AddUserInit(type);

            Common.UITestFramework.UIMaps.AccountManagementCenterClasses.AccountManagementCenter accountManagementCenter = new Common.UITestFramework.UIMaps.AccountManagementCenterClasses.AccountManagementCenter();
            accountManagementCenter.DeleteUser();

            Common.UITestFramework.UIMaps.QuestionWindowClasses.QuestionWindow questionWindow = new Common.UITestFramework.UIMaps.QuestionWindowClasses.QuestionWindow();
            questionWindow.UIQuestionWindow.WaitForControlExist();
            questionWindow.ClickDeactivateButton();
            questionWindow.UIQuestionWindow.WaitForControlNotExist();

            accountManagementCenter.ClickCloseWindowButton();
            accountManagementCenter.UIAccountManagementCenWindow.WaitForControlNotExist();

            Common.UITestFramework.UIMaps.MainWindowClasses.MainWindow mainWindow = new Common.UITestFramework.UIMaps.MainWindowClasses.MainWindow();
            mainWindow.VerifyNoAccount();
        }
Example #22
0
    private async Task ConsumeInternal(DateTimeOffset lastProcessedNoteUpdateAt, SearchEngineType searchEngineType)
    {
        _logger.LogTrace(
            "Note history requested after {LastProcessedNoteUpdate} in {SearchEngine}",
            lastProcessedNoteUpdateAt,
            searchEngineType);

        var(changedPostIds, lastNoteUpdateDate) = await _arachneSearchService.LoadChangesForNotesSince(
            lastProcessedNoteUpdateAt,
            searchEngineType);

        var command = new
        {
            SourceId           = (int)searchEngineType,
            PostIds            = changedPostIds,
            LastNoteUpdateDate = lastNoteUpdateDate
        };

        await _bus.Send <INotesUpdatedCommand>(command);
    }
Example #23
0
    private async Task ConsumeInternal(int lastProcessedTagHistoryId, SearchEngineType searchEngineType)
    {
        _logger.LogInformation(
            "Tag history requested from history id {HistoryId} in {SearchEngine}",
            lastProcessedTagHistoryId,
            searchEngineType);

        var(changedPostIds, lastHistoryId) = await _arachneSearchService.LoadChangesForTagsSinceHistoryId(
            lastProcessedTagHistoryId,
            searchEngineType);

        var command = new
        {
            SourceId      = (int)searchEngineType,
            PostIds       = changedPostIds,
            LastHistoryId = lastHistoryId
        };

        await _bus.Send <ITagsUpdatedCommand>(command);
    }
Example #24
0
        public KeywordSearcher(SearchEngineType searchEngine, string searchText)
        {
            ISearchResultsOrganiser organiser;

            if (searchEngine == SearchEngineType.Google)
            {
                string html = GetWebsite.GetHtml(googleBaseUrl, (googleSearchParamName, searchText), ("num", "99"));
                organiser = new GoogleSearchResultsOrganiser(html);
            }
            else if (searchEngine == SearchEngineType.Bing)
            {
                string html = GetWebsite.GetHtml(bingBaseUrl, (bingSearchParamName, searchText), ("count", "100"));
                organiser = new BingSearchResultsOrganiser(html);
            }
            else
            {
                throw new Exception("No Search Engine Selected");
            }
            searchResultFinder = new FinderOfKeywordsInSearchResults(organiser, searchText);
        }
        public ISearchScraper GetSearchScraperInstance(SearchEngineType type)
        {
            switch (type)
            {
            case SearchEngineType.Google:
                return(new GoogleSearchScraper(_downloadService));

            case SearchEngineType.Bing:
                return(new BingSearchScraper(_downloadService));

            case SearchEngineType.Unknown:
                throw new ApplicationException(
                          string.Format(
                              $"{type} is not a valid scraper type "));

            default:
                throw new NotImplementedException(
                          string.Format(
                              $"Scraper of type {type} has not been implented"));
            }
        }
    public SearchResult Convert(
        Post post,
        Image image,
        SearchEngineType searchEngineType)
    {
        var metadataParsingDto = ToMetadataParsingResults(post);

        var metaTags = metadataParsingDto
                       .GetMetaTags()
                       .Select(x => new Tag(x.TagType, x.Tag, x.Value));
        var postTags = metadataParsingDto
                       .Tags
                       .Select(x => new Tag(x.TagType, x.Tag, x.Value, x.Synonyms));

        return(new Metadata(
                   image,
                   searchEngineType,
                   true,
                   metaTags.Union(postTags).ToArray(),
                   metadataParsingDto.Notes,
                   post.PostId));
    }
Example #27
0
            private bool FindSearchEngineResult(QueryResult queryResult, SearchEngineType targetType, out SearchEngineResult searchEngineResult)
            {
                bool hasFound = false;

                searchEngineResult = null;
                if (queryResult != null)
                {
                    if (queryResult.SearchEngineResultItems != null)
                    {
                        foreach (SearchEngineResult resultItem in queryResult.SearchEngineResultItems)
                        {
                            if (resultItem != null && resultItem.SearchEngineType == targetType)
                            {
                                searchEngineResult = resultItem;
                                hasFound           = true;
                                break;
                            }
                        }
                    }
                }
                return(hasFound);
            }
Example #28
0
        public void AddUserInit(SearchEngineType type)
        {
            Common.UITestFramework.UIMaps.AddUsersClasses.AddUsers addUser = new UITestFramework.UIMaps.AddUsersClasses.AddUsers();
            Common.UITestFramework.UIMaps.AccountManagementCenterClasses.AccountManagementCenter accountManagementCenter = new Common.UITestFramework.UIMaps.AccountManagementCenterClasses.AccountManagementCenter();

            switch (type)
            {
                case SearchEngineType.Google:
                    addUser.AddGoogleUser();
                    addUser.UIAddUserWindow.WaitForControlNotExist();
                    accountManagementCenter.VerifyActiveGoogleAccount();
                    accountManagementCenter.ActivateGoogleUser();
                    break;
                case SearchEngineType.Adcenter:
                    addUser.AddAdcenterUser();
                    addUser.UIAddUserWindow.WaitForControlNotExist();
                    accountManagementCenter.VerifyActiveAdcenterAccount();
                    accountManagementCenter.ActivateAdcenterUser();
                    break;
                case SearchEngineType.Facebook:
                    //Click Add New User
                    addUser.AddFacebookUser();

                    //Wait Facebook Login Windows Exist
                    Common.UITestFramework.UIMaps.FacebookLoginClasses.FacebookLogin facbookLogin = new Common.UITestFramework.UIMaps.FacebookLoginClasses.FacebookLogin();
                    facbookLogin.UIFacebookLoginWindow.WaitForControlExist();

                    //facbookLogin.Login();
                    Common.UITestFramework.UIMaps.LoginWindow loginWindow = new UITestFramework.UIMaps.LoginWindow();
                    loginWindow.Login(
                        ConfigurationManager.AppSettings["Email"],
                        ConfigurationManager.AppSettings["Password"]);

                    addUser.UIAddUserWindow.WaitForControlNotExist();
                    accountManagementCenter.VerifyActiveFacebookAccount();
                    accountManagementCenter.ActivateFacebookUser();
                    break;
            }
        }
Example #29
0
            private bool FindSearchEngineResult(QueryResult queryResult, SearchEngineType targetType, out SearchEngineResult searchEngineResult)
            {
                bool hasFound = false;
                searchEngineResult = null;
                if (queryResult != null)
                {

                    if ( queryResult.SearchEngineResultItems != null )
                    {

                        foreach ( SearchEngineResult resultItem in queryResult.SearchEngineResultItems )
                        {
                            if (resultItem != null && resultItem.SearchEngineType == targetType)
                            {
                                searchEngineResult = resultItem;
                                hasFound = true;
                                break;
                            }
                        }
                    }
                }
                return hasFound;
            }
 public void FromXMLObject(XMLObject xmlObject)
 {
     SearchEngineResult result = GetSearchEngineResultFromXMLObject(xmlObject);
     this._searchEngine = result._searchEngine;
     this._searchUrl = result._searchUrl;
     this._results = result._results;
 }
 public AbstractSequestFactory(SearchEngineType set) : base(set)
 {
 }
Example #32
0
        private void AddUser(SearchEngineType type)
        {
            //在账户管理窗口中点击 Add New User,弹出添加用户窗口,online Media 选择 Google,输入用户名、密码、token ,点击OK。
            Common.UITestFramework.UIMaps.AddUsersClasses.AddUsers addUser = new UITestFramework.UIMaps.AddUsersClasses.AddUsers();
            switch (type)
            {
                case SearchEngineType.Google:
                    addUser.AddGoogleUser();
                    break;
                case SearchEngineType.Adcenter:
                    addUser.AddAdcenterUser();
                    break;
                case SearchEngineType.Facebook:
                    ////Click Add New User
                    addUser.AddFacebookUser();

                    ////Wait Facebook Login Windows Exist
                    Common.UITestFramework.UIMaps.FacebookLoginClasses.FacebookLogin facbookLogin = new Common.UITestFramework.UIMaps.FacebookLoginClasses.FacebookLogin();
                    facbookLogin.UIFacebookLoginWindow.WaitForControlExist();

                    ////facbookLogin.Login();
                    Common.UITestFramework.UIMaps.LoginWindow loginWindow = new UITestFramework.UIMaps.LoginWindow();
                    loginWindow.Login(
                        ConfigurationManager.AppSettings["Email"],
                        ConfigurationManager.AppSettings["Password"]);

                    break;
            }
            addUser.UIAddUserWindow.WaitForControlNotExist();

            //添加用户成功,可以看到新添加的用户出现在左侧的用户列表中
            Common.UITestFramework.UIMaps.AccountManagementCenterClasses.AccountManagementCenter accountManagementCenter = new Common.UITestFramework.UIMaps.AccountManagementCenterClasses.AccountManagementCenter();
            switch (type)
            {
                case SearchEngineType.Google:
                    accountManagementCenter.VerifyActiveGoogleAccount();
                    break;
                case SearchEngineType.Adcenter:
                    accountManagementCenter.VerifyActiveAdcenterAccount();
                    break;
                case SearchEngineType.Facebook:
                    accountManagementCenter.VerifyActiveFacebookAccount();
                    break;
            }

            //关闭账户管理窗口
            accountManagementCenter.ClickCloseWindowButton();
            accountManagementCenter.UIAccountManagementCenWindow.WaitForControlNotExist();

            //在account view中看不到新添加用户下的账户
            Common.UITestFramework.UIMaps.MainWindowClasses.MainWindow mainWindow = new Common.UITestFramework.UIMaps.MainWindowClasses.MainWindow();
            mainWindow.VerifyNoAccount();

            Common.UITestFramework.UIMaps.MainWindowClasses.UIRibbonToolBar2 ribbonToolBar = mainWindow.UIAdSageforPerformanceWindow.UIRibbonToolBar2;

            //再次打开账户管理窗口,在左侧用户列表中,选中刚刚添加的用户,在其下属账户后点击 Active按钮
            WinButton manageAccountsButton = ribbonToolBar.UIManageAccountsButton;
            Mouse.Click(manageAccountsButton);

            accountManagementCenter.UIAccountManagementCenWindow.WaitForControlExist();
            switch (type)
            {
                case SearchEngineType.Google:
                    WinText uISynchronizeaccountsfText = accountManagementCenter.UIAccountManagementCenWindow.UILabel1Window.UISynchronizeaccountsfText;
                    uISynchronizeaccountsfText.WaitForControlNotExist();
                    accountManagementCenter.ActivateGoogleUser();
                    break;
                case SearchEngineType.Adcenter:
                    WinText uISynchronizeaccountsfText1 = accountManagementCenter.UIAccountManagementCenWindow.UILabel1Window.UISynchronizeaccountsfText1;
                    uISynchronizeaccountsfText1.WaitForControlNotExist();
                    accountManagementCenter.ActivateAdcenterUser();
                    break;
                case SearchEngineType.Facebook:
                    WinText uISynchronizeaccountsfText2 = accountManagementCenter.UIAccountManagementCenWindow.UILabel1Window.UISynchronizeaccountsfText2;
                    uISynchronizeaccountsfText2.WaitForControlNotExist();
                    accountManagementCenter.ActivateFacebookUser();
                    break;
            }
            accountManagementCenter.UIAccountManagementCenWindow.WaitForControlReady();

            //账户激活成功,账户后面的active按钮变为deactive按钮
            switch (type)
            {
                case SearchEngineType.Google:
                    accountManagementCenter.VerifyDeactivateGoogleUser();
                    break;
                case SearchEngineType.Adcenter:
                    accountManagementCenter.VerifyDeactivateAdcenterUser();
                    break;
                case SearchEngineType.Facebook:
                    break;
            }

            //关闭账户管理窗口,新添加用户下的账户出现在account view中
            Thread.Sleep(5 * 1000);
            accountManagementCenter.ClickCloseWindowButton();
            accountManagementCenter.UIAccountManagementCenWindow.WaitForControlNotExist();

            Common.UITestFramework.UIMaps.QuestionWindowClasses.QuestionWindow questionWindow = new Common.UITestFramework.UIMaps.QuestionWindowClasses.QuestionWindow();
            questionWindow.UIQuestionWindow.WaitForControlExist();
            questionWindow.ClickNoButton();
            questionWindow.UIQuestionWindow.WaitForControlNotExist();

            //被激活的账户出现在account view中
            mainWindow.ExpandAccountsView();
            switch (type)
            {
                case SearchEngineType.Google:
                    mainWindow.VerifyGoogleAccountTree();
                    break;
                case SearchEngineType.Adcenter:
                    mainWindow.VerifyAdcenterAccountTree();
                    break;
                case SearchEngineType.Facebook:
                    break;
            }
        }
Example #33
0
        public async Task <ActionResult> GetSearchResults(string searchTerm, string resultNumber, SearchEngineType searchEngine, string searchURL)
        {
            using (ServerResponse _response = new ServerResponse())
            {
                try
                {
                    var searchResults = new SEOResponse();
                    searchResults = await _seoControllerProxy.GetSearchResults(searchTerm, resultNumber, searchEngine, searchURL);

                    _response.Result = true;
                    _response.Data   = searchResults;
                }
                catch (Exception ex)
                {
                    _response.ErrorMessages = new Domain.Entities.Error {
                        Message = ex.Message
                    };
                    _logger.Error("Something went wrong getting search results for the following values: search terms - {searchTerm}, search url - {searchURL}, exception - {ex}", searchTerm, searchURL, ex);
                }
                return(Json(_response, JsonRequestBehavior.AllowGet));
            }
        }
        public Task <SEOResponse> GetSearchResults(string searchTerm, string resultNumber, SearchEngineType searchEngine, string searchURL)
        {
            var           searchResults       = string.Empty;
            List <string> result              = new List <string>();
            var           formattedSearchTerm = searchTerm.Replace(' ', '+');
            string        url = string.Format("https://www.{0}/search?num={1}&q={2}", EnumMapper.From(searchEngine), resultNumber, formattedSearchTerm);

            try
            {
                using (HttpResponseMessage response = _client.GetAsync(url).Result)
                {
                    using (HttpContent content = response.Content)
                    {
                        searchResults = content.ReadAsStringAsync().Result;
                    }
                }
                if (searchResults != null)
                {
                    var formattedSearchURL = FormatSearchURL(searchURL);
                    result = AdvancedScraper(searchResults, formattedSearchURL, searchEngine);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Something went wrong getting search results.");
                throw new ArgumentException();
            }

            return(Task.FromResult(new SEOResponse {
                Result = result
            }));
        }
 public ISearchEngine Get(SearchEngineType searchEngineType)
 => GetSearchEngineFor(searchEngineType);
        private List <string> AdvancedScraper(string searchResults, string searchURL, SearchEngineType searchEngine)
        {
            List <string> searchPositions = new List <string>();
            var           parseTerm       = GetParsingValue(searchEngine);

            string[] values = searchResults.Split(new string[] { parseTerm }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < values.Length; i++)
            {
                foreach (Match m in Regex.Matches(values[i], @"" + searchURL + ""))
                {
                    searchPositions.Add(i.ToString());
                    break;
                }
            }

            return(searchPositions);
        }