Пример #1
0
        private void MapQueueSpecificPropsToForm(QueueSettings s)
        {
            this.tabControl1.Tag = s; // for deserializing later

            this.txtUpvotes.Text = s.UpvoteThreshold.ToString();

            s.DeadUsers.Sort();
            this.txtAuthorsSpam.Text = String.Join("\r\n", s.DeadUsers);
            s.SpamDomains.Sort();
            this.txtDomainsSpam.Text = String.Join("\r\n", s.SpamDomains);
            s.SpamTitleRegexi.Sort();
            this.txtTitlesSpam.Text = String.Join("\r\n", s.SpamTitleRegexi);

            s.BlessedUsers.Sort();
            this.txtAuthorsGood.Text = String.Join("\r\n", s.BlessedUsers);
            s.BlessedDomains.Sort();
            this.txtDomainsGood.Text = String.Join("\r\n", s.BlessedDomains);
            s.BlessedTitleRegexi.Sort();
            this.txtTitlesGood.Text = String.Join("\r\n", s.BlessedTitleRegexi);

            this.chkDenyAllUsers.Checked    = s.UserRules.DenyAll;
            this.chkAllowAllUsers.Checked   = s.UserRules.AllowAll;
            this.chkDenyAllDomains.Checked  = s.DomainRules.DenyAll;
            this.chkAllowAllDomains.Checked = s.DomainRules.AllowAll;
            this.chkDenyAllTitles.Checked   = s.TitleRules.DenyAll;
            this.chkAllowAllTitles.Checked  = s.TitleRules.AllowAll;

            this.chkEnabled.Checked = s.Enabled;

            this.spamAgeTextBox.Text             = s.SpamAuthMaturity.Age.ToString();
            this.spamLinkKarmaTextBox.Text       = s.SpamAuthMaturity.LinkKarma.ToString();
            this.spamCommentKarmaTextBox.Text    = s.SpamAuthMaturity.CommentKarma.ToString();
            this.blessedAgeTextBox.Text          = s.BlessedAuthMaturity.Age.ToString();
            this.blessedLinkKarmaTextBox.Text    = s.BlessedAuthMaturity.LinkKarma.ToString();
            this.blessedCommentKarmaTextBox.Text = s.BlessedAuthMaturity.CommentKarma.ToString();

            orderableActions = s.OrderedActions
                               .ConvertAll(z => z.ToString())
                               .ConvertAll(SpacePascal);
            this.listBox1.DataSource = orderableActions;
        }
Пример #2
0
        private static void CleanConflictsFor(QueueSettings s)
        {
            var x1 = s.DeadUsers.Intersect(s.BlessedUsers);
            if (x1.Count()>0)
            {
                foreach (var x in x1)
                    s.DeadUsers.Remove(x);
            }
            // keep only unique items
            s.DeadUsers = s.DeadUsers.Distinct().ToList();
            s.BlessedUsers = s.BlessedUsers.Distinct().ToList();

            var x2 = s.SpamDomains.Intersect(s.BlessedDomains);
            if (x2.Count()>0)
            {
                foreach (var x in x2)
                    s.SpamDomains.Remove(x);
            }
            // keep only unique items
            s.SpamDomains = s.SpamDomains.Distinct().ToList();
            s.BlessedDomains = s.BlessedDomains.Distinct().ToList();
        }
Пример #3
0
        private bool ValidateAndPreserveSettingsForOneQueue()
        {
            // validate
            var spamUsers    = Splitto(this.txtAuthorsSpam.Text);
            var blessedUsers = Splitto(this.txtAuthorsGood.Text);
            var x1           = spamUsers.Intersect(blessedUsers);

            if (x1.Count() > 0)
            {
                // there is an overlap between spam and blessed users
                MarkInvalid(0);
                return(false);
            }
            var spamDomains    = Splitto(this.txtDomainsSpam.Text);
            var blessedDomains = Splitto(this.txtDomainsGood.Text);

            x1 = spamDomains.Intersect(blessedDomains);

            if (x1.Count() > 0)
            {
                // there is an overlap between spam and blessed domains
                MarkInvalid(1);
                return(false);
            }

            var blessedTitles = Splitto(this.txtTitlesGood.Text);
            var spamTitles    = Splitto(this.txtTitlesSpam.Text);

            // TODO: verify that the regexi are all valid.
            var groups = new List <String>[] { blessedTitles, spamTitles };

            for (int i = 0; i < groups.Length; i++)
            {
                List <String> group = groups[i];
                foreach (var regex in group)
                {
                    try
                    {
                        var re3 = new Regex(regex);
                    }
                    catch (System.Exception)
                    {
                        MarkInvalid(i + 2);
                        return(false);
                    }
                }
            }

            QueueSettings qs = this.tabControl1.Tag as QueueSettings;

            qs.Ordering =
                String.Join(",",
                            ((List <String>) this.listBox1.DataSource)
                            .ConvertAll(CollapsePascal));

            var getInt = new Func <TextBox, Int32, Int32>((tb, def) =>
            {
                int value = def;
                Int32.TryParse(tb.Text.Trim(), out value);
                return(value);
            });

            qs.UpvoteThreshold                  = getInt(this.txtUpvotes, 300);
            qs.SpamAuthMaturity.Age             = getInt(this.spamAgeTextBox, 0);
            qs.SpamAuthMaturity.LinkKarma       = getInt(this.spamLinkKarmaTextBox, 0);
            qs.SpamAuthMaturity.CommentKarma    = getInt(this.spamCommentKarmaTextBox, 0);
            qs.BlessedAuthMaturity.Age          = getInt(this.blessedAgeTextBox, -1);
            qs.BlessedAuthMaturity.LinkKarma    = getInt(this.blessedLinkKarmaTextBox, -1);
            qs.BlessedAuthMaturity.CommentKarma = getInt(this.blessedCommentKarmaTextBox, -1);

            qs.Enabled = this.chkEnabled.Checked;

            qs.DeadUsers          = spamUsers;
            qs.SpamDomains        = spamDomains;
            qs.SpamTitleRegexi    = spamTitles;
            qs.BlessedUsers       = blessedUsers;
            qs.BlessedDomains     = blessedDomains;
            qs.BlessedTitleRegexi = blessedTitles;

            qs.UserRules.DenyAll    = this.chkDenyAllUsers.Checked;
            qs.UserRules.AllowAll   = this.chkAllowAllUsers.Checked;
            qs.DomainRules.DenyAll  = this.chkDenyAllDomains.Checked;
            qs.DomainRules.AllowAll = this.chkAllowAllDomains.Checked;
            qs.TitleRules.DenyAll   = this.chkDenyAllTitles.Checked;
            qs.TitleRules.AllowAll  = this.chkAllowAllTitles.Checked;

            return(true);
        }
Пример #4
0
        private void MapQueueSpecificPropsToForm(QueueSettings s)
        {
            this.tabControl1.Tag = s; // for deserializing later

            this.txtUpvotes.Text = s.UpvoteThreshold.ToString();

            s.DeadUsers.Sort();
            this.txtAuthorsSpam.Text = String.Join("\r\n", s.DeadUsers);
            s.SpamDomains.Sort();
            this.txtDomainsSpam.Text = String.Join("\r\n", s.SpamDomains);
            s.SpamTitleRegexi.Sort();
            this.txtTitlesSpam.Text = String.Join("\r\n", s.SpamTitleRegexi);

            s.BlessedUsers.Sort();
            this.txtAuthorsGood.Text = String.Join("\r\n", s.BlessedUsers);
            s.BlessedDomains.Sort();
            this.txtDomainsGood.Text = String.Join("\r\n", s.BlessedDomains);
            s.BlessedTitleRegexi.Sort();
            this.txtTitlesGood.Text = String.Join("\r\n", s.BlessedTitleRegexi);

            this.chkDenyAllUsers.Checked = s.UserRules.DenyAll;
            this.chkAllowAllUsers.Checked = s.UserRules.AllowAll;
            this.chkDenyAllDomains.Checked = s.DomainRules.DenyAll;
            this.chkAllowAllDomains.Checked = s.DomainRules.AllowAll;
            this.chkDenyAllTitles.Checked = s.TitleRules.DenyAll;
            this.chkAllowAllTitles.Checked = s.TitleRules.AllowAll;

            this.chkEnabled.Checked = s.Enabled;

            this.spamAgeTextBox.Text = s.SpamAuthMaturity.Age.ToString();
            this.spamLinkKarmaTextBox.Text = s.SpamAuthMaturity.LinkKarma.ToString();
            this.spamCommentKarmaTextBox.Text = s.SpamAuthMaturity.CommentKarma.ToString();
            this.blessedAgeTextBox.Text = s.BlessedAuthMaturity.Age.ToString();
            this.blessedLinkKarmaTextBox.Text = s.BlessedAuthMaturity.LinkKarma.ToString();
            this.blessedCommentKarmaTextBox.Text = s.BlessedAuthMaturity.CommentKarma.ToString();

            orderableActions = s.OrderedActions
                .ConvertAll(z => z.ToString())
                .ConvertAll(SpacePascal);
            this.listBox1.DataSource = orderableActions;
        }
Пример #5
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!this.Enabled) return;
            if (fillingForm) return;
            var cmb = this.comboBox1;
            QueueSettings settings = null;

            if (!ValidateAndPreserveSettingsForOneQueue())
            {
                cmb.SelectedIndex = oldIndex; // revert
                return;
            }

            var queueName = cmb.Items[cmb.SelectedIndex].ToString();
            oldIndex = cmb.SelectedIndex;

            if (queueName == "modqueue")   // special case
            {
                settings = this.Settings;
                MapQueueSpecificPropsToForm(settings);
            }
            else
            {
                var parts = queueName.Split(' ');
                var z = this.Settings.OtherQueues
                    .Where(x => ((x.Name == parts[0]) &&
                                 ((x.WatchNewQueue && parts[1] == "(new)") ||
                                  (!x.WatchNewQueue && parts[1] == "(mod)"))))
                    .Select(x => x);

                if (z.Count() == 1)
                {
                    settings = z.First();
                    MapQueueSpecificPropsToForm(settings);
                }
                else
                {
                    // cons new
                    settings = new QueueSettings {
                        Name = parts[0],
                        WatchNewQueue = (parts[1]=="(new)")
                    };
                    this.Settings.OtherQueues.Add(settings);
                    MapQueueSpecificPropsToForm(settings);
                }
            }
        }