Beispiel #1
0
        /// <summary>
        /// Called when the reddit subreddit list should be updated.
        /// </summary>
        /// <param name="force">Forces the update</param>
        public bool Update(bool force = false)
        {
            TimeSpan timeSinceLastUpdate = DateTime.Now - LastUpdate;

            if (!force && timeSinceLastUpdate.TotalMinutes < 300 && SubredditList.Count > 0)
            {
                return(false);
            }

            lock (objectLock)
            {
                if (m_isUpdateRunning)
                {
                    return(false);
                }
                m_isUpdateRunning = true;
            }

            // Kick off an new task
            new Task(async() =>
            {
                try
                {
                    // Get the entire list of subreddits. We will give the helper a super high limit so it
                    // will return all it can find.
                    string baseUrl = m_baconMan.UserMan.IsUserSignedIn ? "/subreddits/mine.json" : "/subreddits/default.json";
                    int maxLimit   = m_baconMan.UserMan.IsUserSignedIn ? 99999 : 100;
                    RedditListHelper <Subreddit> listHelper = new RedditListHelper <Subreddit>(baseUrl, m_baconMan.NetworkMan);

                    // Get the list
                    List <Element <Subreddit> > elements = await listHelper.FetchElements(0, maxLimit);

                    // Create a json list from the wrappers.
                    List <Subreddit> subredditList = new List <Subreddit>();
                    foreach (Element <Subreddit> element in elements)
                    {
                        subredditList.Add(element.Data);
                    }

                    // Update the subreddit list
                    HandleSubredditsFromWeb(subredditList);
                    LastUpdate = DateTime.Now;
                }
                catch (Exception e)
                {
                    m_baconMan.MessageMan.DebugDia("Failed to get subreddit list", e);
                }

                // Indicate we aren't running anymore
                m_isUpdateRunning = false;
            }).Start();
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Called when the reddit subreddit list should be updated.
        /// </summary>
        /// <param name="force">Forces the update</param>
        public bool Update(bool force = false)
        {
            TimeSpan timeSinceLastUpdate = DateTime.Now - LastUpdate;
            if (!force && timeSinceLastUpdate.TotalMinutes < 300 && SubredditList.Count > 0)
            {
               return false;
            }

            lock(objectLock)
            {
                if(m_isUpdateRunning)
                {
                    return false;
                }
                m_isUpdateRunning = true;
            }

            // Kick off an new task
            new Task(async () =>
            {
                try
                {
                    // Get the entire list of subreddits. We will give the helper a super high limit so it
                    // will return all it can find.
                    string baseUrl = m_baconMan.UserMan.IsUserSignedIn ? "/subreddits/mine.json" : "/subreddits/default.json";
                    int maxLimit = m_baconMan.UserMan.IsUserSignedIn ? 99999 : 100;
                    RedditListHelper <Subreddit> listHelper = new RedditListHelper<Subreddit>(baseUrl, m_baconMan.NetworkMan);

                    // Get the list
                    List<Element<Subreddit>> elements = await listHelper.FetchElements(0, maxLimit);

                    // Create a json list from the wrappers.
                    List<Subreddit> subredditList = new List<Subreddit>();
                    foreach(Element<Subreddit> element in elements)
                    {
                        subredditList.Add(element.Data);
                    }

                    // Update the subreddit list
                    HandleSubredditsFromWeb(subredditList);
                    LastUpdate = DateTime.Now;
                }
                catch(Exception e)
                {
                    m_baconMan.MessageMan.DebugDia("Failed to get subreddit list", e);
                }

                // Indicate we aren't running anymore
                m_isUpdateRunning = false;
            }).Start();
            return true;
        }
Beispiel #3
0
 /// <summary>
 /// Sets up the list helper
 /// </summary>
 /// <param name="baseUrl"></param>
 /// <param name="hasEmptyArrrayRoot"></param>
 protected void InitListHelper(string baseUrl, bool hasEmptyArrrayRoot = false, bool takeFirstArrayRoot = false, string optionalGetArgs = "")
 {
     m_listHelper = new RedditListHelper <T>(baseUrl, m_baconMan.NetworkMan, hasEmptyArrrayRoot, takeFirstArrayRoot, optionalGetArgs);
 }