コード例 #1
0
        /// <summary>
        /// Creates a new collector and starts a search.
        /// </summary>
        /// <param name="searchTerm"></param>
        private void DoPostSearch(string searchTerm)
        {
            // Get all of the filters.
            PostSearchSorts sort            = GetCurrentPostSort();
            PostSearchTimes times           = GetCurrentPostTime();
            string          subredditFilter = ui_postSubreddit.Text;
            string          authorFilter    = ui_postUserName.Text;
            string          websiteFilter   = ui_postWebsite.Text;
            string          selftextFilter  = ui_postSelfText.Text;
            string          isSelfPost      = ui_postIsSelf.SelectedIndex == 0 ? String.Empty : (ui_postIsSelf.SelectedIndex == 1 ? "yes" : "no");
            string          isNsfw          = ui_postIsNsfw.SelectedIndex == 0 ? String.Empty : (ui_postIsNsfw.SelectedIndex == 1 ? "yes" : "no");

            lock (this)
            {
                m_currentPostCollector = new SearchPostCollector(App.BaconMan, searchTerm, sort, times, subredditFilter, authorFilter, websiteFilter, selftextFilter, isSelfPost, isNsfw);
                m_currentPostCollector.OnCollectionUpdated    += CurrentPostCollector_OnCollectionUpdated;
                m_currentPostCollector.OnCollectorStateChange += CurrentPostCollector_OnCollectorStateChange;
                m_currentPostCollector.Update(true);
            }
        }
コード例 #2
0
        public static string PostTimeToString(PostSearchTimes time)
        {
            switch (time)
            {
            default:
            case PostSearchTimes.AllTime:
                return("all");

            case PostSearchTimes.PastHour:
                return("hour");

            case PostSearchTimes.PastDay:
                return("day");

            case PostSearchTimes.PastWeek:
                return("week");

            case PostSearchTimes.PastMonth:
                return("month");

            case PostSearchTimes.PastYear:
                return("year");
            }
        }
コード例 #3
0
        public SearchPostCollector(BaconManager baconMan, string searchTerm, PostSearchSorts sort = PostSearchSorts.Relevance, PostSearchTimes time = PostSearchTimes.AllTime, string subreddit = null,
                                   string authorFilter = null, string websiteFilter = null, string selftextFilter = null, string isSelfPost = null, string isNsfw = null) :
            base(baconMan, "SearchSubredditCollector")
        {
            m_baconMan = baconMan;

            // Add the subreddit if needed
            if (!String.IsNullOrWhiteSpace(subreddit))
            {
                searchTerm += $" subreddit:{subreddit}";
            }
            // Add the author if needed
            if (!String.IsNullOrWhiteSpace(authorFilter))
            {
                searchTerm += $" author:{authorFilter}";
            }
            // Add the website if needed
            if (!String.IsNullOrWhiteSpace(websiteFilter))
            {
                searchTerm += $" site:{websiteFilter}";
            }
            // Add the selftext if needed
            if (!String.IsNullOrWhiteSpace(selftextFilter))
            {
                searchTerm += $" selftext:{selftextFilter}";
            }
            // Add the is self if needed
            if (!String.IsNullOrWhiteSpace(isSelfPost))
            {
                searchTerm += $" self:{isSelfPost}";
            }
            // Add the nsfw if needed
            if (!String.IsNullOrWhiteSpace(isNsfw))
            {
                searchTerm += $" nsfw:{isNsfw}";
            }

            // Encode the query
            searchTerm = WebUtility.UrlEncode(searchTerm);

            string sortString = PostSortToString(sort);
            string timeString = PostTimeToString(time);

            // Set up the list helper
            InitListHelper($"/search.json", false, false, $"q={searchTerm}&sort={sortString}&t={timeString}");
        }