コード例 #1
0
        private void EntryMethodTypeComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            this.CommandEntryGrid.Visibility  = Visibility.Collapsed;
            this.DonationEntryGrid.Visibility = Visibility.Collapsed;

            if (this.EntryMethodTypeComboBox.SelectedIndex >= 0)
            {
                GiveawayEntryTypeEnum entryType = EnumHelper.GetEnumValueFromString <GiveawayEntryTypeEnum>((string)this.EntryMethodTypeComboBox.SelectedItem);
                if (entryType == GiveawayEntryTypeEnum.Command)
                {
                    this.CommandEntryGrid.Visibility = Visibility.Visible;
                }
                else
                {
                    this.DonationEntryGrid.Visibility = Visibility.Visible;
                }
            }
        }
コード例 #2
0
        private async void EnableGiveawayButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this.ItemTextBox.Text))
            {
                await MessageBoxHelper.ShowMessageDialog("An item to give away must be specified");

                return;
            }

            this.timeLeft = 0;
            if (string.IsNullOrEmpty(this.TimerTextBox.Text) || !int.TryParse(this.TimerTextBox.Text, out this.timeLeft) || this.timeLeft <= 0)
            {
                await MessageBoxHelper.ShowMessageDialog("Timer must be greater than 0");

                return;
            }

            this.reminder = 0;
            if (string.IsNullOrEmpty(this.ReminderTextBox.Text) || !int.TryParse(this.ReminderTextBox.Text, out this.reminder) || this.reminder <= 0)
            {
                await MessageBoxHelper.ShowMessageDialog("Reminder must be greater than 0");

                return;
            }

            if (this.EntryMethodTypeComboBox.SelectedIndex < 0)
            {
                await MessageBoxHelper.ShowMessageDialog("An entry method must be selected");

                return;
            }

            GiveawayEntryTypeEnum entryType = EnumHelper.GetEnumValueFromString <GiveawayEntryTypeEnum>((string)this.EntryMethodTypeComboBox.SelectedItem);

            if (entryType == GiveawayEntryTypeEnum.Command)
            {
                if (string.IsNullOrEmpty(this.CommandTextBox.Text))
                {
                    await MessageBoxHelper.ShowMessageDialog("Giveaway command must be specified");

                    return;
                }

                if (this.CommandTextBox.Text.Any(c => !Char.IsLetterOrDigit(c)))
                {
                    await MessageBoxHelper.ShowMessageDialog("Giveaway Command can only contain letters and numbers");

                    return;
                }

                if (!await this.Requirements.Validate())
                {
                    return;
                }

                ChannelSession.Settings.GiveawayCommand                = this.CommandTextBox.Text.ToLower();
                ChannelSession.Settings.GiveawayRequirements           = this.Requirements.GetRequirements();
                ChannelSession.Settings.GiveawayGawkBoxTrigger         = false;
                ChannelSession.Settings.GiveawayStreamlabsTrigger      = false;
                ChannelSession.Settings.GiveawayDonationRequiredAmount = false;
                ChannelSession.Settings.GiveawayDonationAmount         = 0.0;
            }
            else
            {
                if (this.DonationEntryQualifierComboBox.SelectedIndex < 0)
                {
                    await MessageBoxHelper.ShowMessageDialog("An entry method must be selected");

                    return;
                }

                double donationAmount = 0.0;
                GiveawayDonationEntryQualificationTypeEnum qualificationType = EnumHelper.GetEnumValueFromString <GiveawayDonationEntryQualificationTypeEnum>((string)this.DonationEntryQualifierComboBox.SelectedItem);
                if (qualificationType == GiveawayDonationEntryQualificationTypeEnum.MinimumAmountRequired || qualificationType == GiveawayDonationEntryQualificationTypeEnum.OneEntryPerAmount)
                {
                    if (string.IsNullOrEmpty(this.DonationEntryQualifierAmountTextBox.Text) || !double.TryParse(this.DonationEntryQualifierAmountTextBox.Text, out donationAmount) || donationAmount <= 0.0)
                    {
                        await MessageBoxHelper.ShowMessageDialog("A validation tip amount must be entered");

                        return;
                    }

                    donationAmount = Math.Round(donationAmount, 2);
                }

                ChannelSession.Settings.GiveawayCommand                = null;
                ChannelSession.Settings.GiveawayGawkBoxTrigger         = (entryType == GiveawayEntryTypeEnum.GawkBox);
                ChannelSession.Settings.GiveawayStreamlabsTrigger      = (entryType == GiveawayEntryTypeEnum.Streamlabs);
                ChannelSession.Settings.GiveawayTiltifyTrigger         = (entryType == GiveawayEntryTypeEnum.Tiltify);
                ChannelSession.Settings.GiveawayDonationRequiredAmount = (qualificationType == GiveawayDonationEntryQualificationTypeEnum.MinimumAmountRequired);
                ChannelSession.Settings.GiveawayDonationAmount         = donationAmount;
            }

            ChannelSession.Settings.GiveawayTimer            = this.timeLeft;
            ChannelSession.Settings.GiveawayReminderInterval = this.reminder;
            ChannelSession.Settings.GiveawayRequireClaim     = this.RequireClaimCheckBox.IsChecked.GetValueOrDefault();
            await ChannelSession.SaveSettings();

            this.timeLeft = this.timeLeft * 60;
            this.reminder = this.reminder * 60;

            this.giveawayEnabled = true;
            this.giveawayItem    = this.ItemTextBox.Text;

            this.enteredUsersDictionary.Clear();
            this.enteredUsers.Clear();

            this.WinnerTextBlock.Text             = "";
            this.EnableGiveawayButton.Visibility  = Visibility.Collapsed;
            this.DisableGiveawayButton.Visibility = Visibility.Visible;

            this.GiveawayBasicsGrid.IsEnabled = this.GiveawayTimersGrid.IsEnabled = this.GiveawayRequireClaimGrid.IsEnabled = this.CommandEntryGrid.IsEnabled = this.DonationEntryGrid.IsEnabled = false;

            await ChannelSession.Chat.SendMessage(string.Format("A giveaway for {0} has started! {1} in the next {2} minute(s)", this.giveawayItem, this.GetEntryInstructions(), ChannelSession.Settings.GiveawayTimer));

            this.backgroundThreadCancellationTokenSource = new CancellationTokenSource();
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Task.Run(async() => { await this.GiveawayTimerBackground(); }, this.backgroundThreadCancellationTokenSource.Token);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }