コード例 #1
0
        public async Task RefreshCampaigns()
        {
            this.Campaigns.Clear();

            TiltifyUser user = await ChannelSession.Services.Tiltify.GetUser();

            Dictionary <int, TiltifyCampaign> campaignDictionary = new Dictionary <int, TiltifyCampaign>();

            foreach (TiltifyCampaign campaign in await ChannelSession.Services.Tiltify.GetUserCampaigns(user))
            {
                campaignDictionary[campaign.ID] = campaign;
            }

            foreach (TiltifyTeam team in await ChannelSession.Services.Tiltify.GetUserTeams(user))
            {
                foreach (TiltifyCampaign campaign in await ChannelSession.Services.Tiltify.GetTeamCampaigns(team))
                {
                    campaignDictionary[campaign.ID] = campaign;
                }
            }

            foreach (TiltifyCampaign campaign in campaignDictionary.Values)
            {
                if (campaign.Ends > DateTimeOffset.Now)
                {
                    this.Campaigns.Add(campaign);
                }
            }
        }
コード例 #2
0
        private async Task InitializeInternal()
        {
            this.cancellationTokenSource = new CancellationTokenSource();

            this.user = await this.GetUser();

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Task.Run(this.BackgroundDonationCheck, this.cancellationTokenSource.Token);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
コード例 #3
0
        public async Task <IEnumerable <TiltifyCampaign> > GetCampaigns(TiltifyUser user)
        {
            List <TiltifyCampaign> results = new List <TiltifyCampaign>();

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

                foreach (JToken token in result.Data)
                {
                    results.Add(token.ToObject <TiltifyCampaign>());
                }
            }
            catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }
            return(results);
        }
コード例 #4
0
        private async Task BackgroundDonationCheck()
        {
            int             currentCampaign = 0;
            TiltifyCampaign campaign        = null;
            Dictionary <int, TiltifyDonation> donationsReceived = new Dictionary <int, TiltifyDonation>();

            while (!this.cancellationTokenSource.Token.IsCancellationRequested)
            {
                try
                {
                    if (ChannelSession.Settings.TiltifyCampaign != currentCampaign)
                    {
                        currentCampaign = ChannelSession.Settings.TiltifyCampaign;
                        donationsReceived.Clear();

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

                        campaign = campaigns.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;
                                UserDonationModel donation = tDonation.ToGenericDonation();
                                GlobalEvents.DonationOccurred(donation);

                                UserViewModel user = new UserViewModel(0, donation.UserName);

                                UserModel userModel = await ChannelSession.Connection.GetUser(user.UserName);

                                if (userModel != null)
                                {
                                    user = new UserViewModel(userModel);
                                }

                                EventCommand command = ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.TiltifyDonation));
                                if (command != null)
                                {
                                    command.AddSpecialIdentifier("donationsource", EnumHelper.GetEnumName(donation.Source));
                                    command.AddSpecialIdentifier("donationamount", donation.AmountText);
                                    command.AddSpecialIdentifier("donationmessage", donation.Message);
                                    command.AddSpecialIdentifier("donationimage", donation.ImageLink);
                                    await command.Perform(user);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }

                await Task.Delay(10000);
            }
        }