Esempio n. 1
0
        public async Task <IEnumerable <TiltifyDonation> > GetCampaignDonations(TiltifyCampaign campaign)
        {
            List <TiltifyDonation> results = new List <TiltifyDonation>();

            try
            {
                TiltifyResultArray result = await this.GetAsync <TiltifyResultArray>("campaigns/" + campaign.ID.ToString() + "/donations");

                foreach (JToken token in result.Data)
                {
                    results.Add(token.ToObject <TiltifyDonation>());
                }
            }
            catch (Exception ex) { Logger.Log(ex); }
            return(results);
        }
Esempio n. 2
0
        private async Task BackgroundDonationCheck(CancellationToken token)
        {
            if (ChannelSession.Settings.TiltifyCampaign != currentCampaign)
            {
                currentCampaign = ChannelSession.Settings.TiltifyCampaign;
                donationsReceived.Clear();

                IEnumerable <TiltifyCampaign> campaigns = await this.GetUserCampaigns(this.user);

                campaign = campaigns.FirstOrDefault(c => c.ID.Equals(currentCampaign));
                if (campaign == null)
                {
                    List <TiltifyCampaign> teamCampaigns = new List <TiltifyCampaign>();
                    foreach (TiltifyTeam team in await ChannelSession.Services.Tiltify.GetUserTeams(user))
                    {
                        teamCampaigns.AddRange(await ChannelSession.Services.Tiltify.GetTeamCampaigns(team));
                    }
                    campaign = teamCampaigns.FirstOrDefault(c => c.ID.Equals(currentCampaign));
                }

                if (campaign != null)
                {
                    foreach (TiltifyDonation donation in await this.GetCampaignDonations(campaign))
                    {
                        donationsReceived[donation.ID] = donation;
                    }
                }
            }

            if (campaign != null)
            {
                foreach (TiltifyDonation tDonation in await this.GetCampaignDonations(campaign))
                {
                    if (!donationsReceived.ContainsKey(tDonation.ID))
                    {
                        donationsReceived[tDonation.ID] = tDonation;
                        await EventService.ProcessDonationEvent(EventTypeEnum.TiltifyDonation, tDonation.ToGenericDonation());
                    }
                }
            }
        }