Example #1
0
        private void ParseSponsors(SponsorPage page)
        {
            if (page != null)
            {
                foreach (Sponsor sponsor in page.Items)
                {
                    if (!this.Sponsors.ContainsKey(sponsor.SponsorSnippet.ChannelId))
                    {
                        this.Sponsors.Add(sponsor.SponsorSnippet.ChannelId, sponsor.SponsorSnippet);
                        this.showNotification("New sponsor " + sponsor.SponsorSnippet.SponsorDetails.DisplayName + "!");
                    }
                }

                this.fetchPageToken = page.NextPageToken;
            }
        }
Example #2
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            this.StartButton.Enabled = false;
            if (bootstrapped)
            {
                this.StopButton.Enabled = true;
                this.QueryTimer.Start();
                return;
            }

            if (IOManager.Instance.LoadLocalCookie(ref this.Subscribers, ref this.Sponsors))
            {
                log("Loaded from local storage.");
                this.StopButton.Enabled = true;
                this.QueryTimer.Start();
                bootstrapped = true;
                return;
            }

            global::SubscriberFeed.Properties.Settings.Default.Code = null;
            global::SubscriberFeed.Properties.Settings.Default.RefreshToken = null;
            global::SubscriberFeed.Properties.Settings.Default.Token = null;

            if (APICommunicationManager.Instance.Authorize())
            {
                this.StopButton.Enabled = true;
                log("Got user token. " + global::SubscriberFeed.Properties.Settings.Default.Code);
                if (!APICommunicationManager.Instance.getAccessToken())
                {
                    log("Error getting user's token");
                    this.StartButton.Enabled = true;
                    return;
                }

                // get, initially, all recent subs and sponsors
                try
                {
                    log("Initializing subscribers");
                    SubscriberPage page = new SubscriberPage();
                    page.NextPageToken = null;
                    do
                    {
                        page = APICommunicationManager.Instance.FetchNewSubscribers(25, page.NextPageToken);

                        ParseSubscribers(page);

                    } while (page != null && page.NextPageToken != null);

                    log("Subscribers loaded.");
                }
                catch (Exception ex)
                {
                    log("Unable to load subscribers.", Color.Red);
                    log(ex.Message, Color.Red);
                    this.StartButton.Enabled = true;
                    this.StopButton.Enabled = false;
                    return;
                }

                try
                {
                    log("Initializing sponsors");
                    SponsorPage pageSponsor = new SponsorPage();
                    pageSponsor.NextPageToken = null;
                    do
                    {
                        pageSponsor = APICommunicationManager.Instance.FetchNewSponsors(25, pageSponsor.NextPageToken);

                        ParseSponsors(pageSponsor);

                    } while (pageSponsor != null && pageSponsor.NextPageToken != null);

                    log("Sponsors loaded.");
                }
                catch (Exception ex)
                {
                    log("Unable to load sponsors.", Color.Red);
                    log(ex.Message, Color.Red);
                    this.StartButton.Enabled = true;
                    this.StopButton.Enabled = false;
                    return;
                }

                log("Started queries");
                bootstrapped = true;
                this.QueryTimer.Start();
            }
            else {
                log("Error getting user's token");
                this.StartButton.Enabled = true;
                this.StopButton.Enabled = false;
                return;
            }
        }