コード例 #1
0
ファイル: FiltersClassTest.cs プロジェクト: rhenium/OpenTween
        public void NameTest()
        {
            var filter = new FiltersClass();
            PostClass post;

            filter.NameFilter = "hoge";
            post = new PostClass { ScreenName = "hoge", Text = "test" };
            Assert.That(filter.IsHit(post), Is.EqualTo(MyCommon.HITRESULT.CopyAndMark));

            filter.NameFilter = "hoge";
            post = new PostClass { ScreenName = "foo", Text = "test" };
            Assert.That(filter.IsHit(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // NameFilter は RetweetedBy にもマッチする
            filter.NameFilter = "hoge";
            post = new PostClass { ScreenName = "foo", Text = "test", RetweetedBy = "hoge" };
            Assert.That(filter.IsHit(post), Is.EqualTo(MyCommon.HITRESULT.CopyAndMark));

            filter.NameFilter = "hoge";
            post = new PostClass { ScreenName = "foo", Text = "test", RetweetedBy = "bar" };
            Assert.That(filter.IsHit(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // NameFilter は部分一致ではない
            filter.NameFilter = "hoge";
            post = new PostClass { ScreenName = "hogehoge", Text = "test" };
            Assert.That(filter.IsHit(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // 大小文字を区別しないオプション
            filter.NameFilter = "hoge";
            filter.CaseSensitive = false;
            post = new PostClass { ScreenName = "Hoge", Text = "test" };
            Assert.That(filter.IsHit(post), Is.EqualTo(MyCommon.HITRESULT.CopyAndMark));
        }
コード例 #2
0
        public void DeserializeTest()
        {
            var oldVersion = new FiltersClass
            {
                NameFilter = "name",
                ExNameFilter = "exname",
                BodyFilterArray = new[] { "body1", "body2" },
                ExBodyFilterArray = new[] { "exbody1", "exbody2" },
                SearchBoth = true,
                ExSearchBoth = true,
                MoveFrom = true,
                SetMark = true,
                SearchUrl = true,
                ExSearchUrl = true,
                CaseSensitive = true,
                ExCaseSensitive = true,
                UseLambda = true,
                ExUseLambda = true,
                UseRegex = true,
                ExUseRegex = true,
                IsRt = true,
                IsExRt = true,
                Source = "source",
                ExSource = "exsource",
            };

            PostFilterRule newVersion;

            using (var stream = new MemoryStream())
            {
                var oldSerializer = new XmlSerializer(typeof(FiltersClass));
                oldSerializer.Serialize(stream, oldVersion);

                stream.Seek(0, SeekOrigin.Begin);

                var newSerializer = new XmlSerializer(typeof(PostFilterRule));
                newVersion = (PostFilterRule)newSerializer.Deserialize(stream);
            }

            Assert.That(newVersion.FilterName, Is.EqualTo(oldVersion.NameFilter));
            Assert.That(newVersion.ExFilterName, Is.EqualTo(oldVersion.ExNameFilter));
            Assert.That(newVersion.FilterBody, Is.EqualTo(oldVersion.BodyFilterArray));
            Assert.That(newVersion.ExFilterBody, Is.EqualTo(oldVersion.ExBodyFilterArray));
            Assert.That(newVersion.UseNameField, Is.EqualTo(oldVersion.SearchBoth));
            Assert.That(newVersion.ExUseNameField, Is.EqualTo(oldVersion.ExSearchBoth));
            Assert.That(newVersion.MoveMatches, Is.EqualTo(oldVersion.MoveFrom));
            Assert.That(newVersion.MarkMatches, Is.EqualTo(oldVersion.SetMark));
            Assert.That(newVersion.FilterByUrl, Is.EqualTo(oldVersion.SearchUrl));
            Assert.That(newVersion.ExFilterByUrl, Is.EqualTo(oldVersion.ExSearchUrl));
            Assert.That(newVersion.CaseSensitive, Is.EqualTo(oldVersion.CaseSensitive));
            Assert.That(newVersion.ExCaseSensitive, Is.EqualTo(oldVersion.ExCaseSensitive));
            Assert.That(newVersion.UseLambda, Is.EqualTo(oldVersion.UseLambda));
            Assert.That(newVersion.ExUseLambda, Is.EqualTo(oldVersion.ExUseLambda));
            Assert.That(newVersion.UseRegex, Is.EqualTo(oldVersion.UseRegex));
            Assert.That(newVersion.ExUseRegex, Is.EqualTo(oldVersion.ExUseRegex));
            Assert.That(newVersion.FilterRt, Is.EqualTo(oldVersion.IsRt));
            Assert.That(newVersion.ExFilterRt, Is.EqualTo(oldVersion.IsExRt));
            Assert.That(newVersion.FilterSource, Is.EqualTo(oldVersion.Source));
            Assert.That(newVersion.ExFilterSource, Is.EqualTo(oldVersion.ExSource));
        }
コード例 #3
0
ファイル: Tween.cs プロジェクト: lupeeloveee/OpenTween
        private void IDRuleMenuItem_Click(object sender, EventArgs e)
        {
            string tabName = "";

            //未選択なら処理終了
            if (_curList.SelectedIndices.Count == 0) return;

            //タブ選択(or追加)
            if (!SelectTab(ref tabName)) return;

            bool mv = false;
            bool mk = false;
            MoveOrCopy(ref mv, ref mk);

            List<string> ids = new List<string>();
            foreach (int idx in _curList.SelectedIndices)
            {
                PostClass post = _statuses[_curTab.Text, idx];
                if (!ids.Contains(post.ScreenName))
                {
                    FiltersClass fc = new FiltersClass();
                    ids.Add(post.ScreenName);
                    if (post.RetweetedId == 0)
                    {
                        fc.NameFilter = post.ScreenName;
                    }
                    else
                    {
                        fc.NameFilter = post.RetweetedBy;
                    }
                    fc.SearchBoth = true;
                    fc.MoveFrom = mv;
                    fc.SetMark = mk;
                    fc.UseRegex = false;
                    fc.SearchUrl = false;
                    _statuses.Tabs[tabName].AddFilter(fc);
                }
            }
            if (ids.Count != 0)
            {
                List<string> atids = new List<string>();
                foreach (string id in ids)
                {
                    atids.Add("@" + id);
                }
                int cnt = AtIdSupl.ItemCount;
                AtIdSupl.AddRangeItem(atids.ToArray());
                if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
            }

            try
            {
                this.Cursor = Cursors.WaitCursor;
                _itemCache = null;
                _postCache = null;
                _curPost = null;
                _curItemIndex = -1;
                _statuses.FilterAll();
                foreach (TabPage tb in ListTab.TabPages)
                {
                    ((DetailsListView)tb.Tag).VirtualListSize = _statuses.Tabs[tb.Text].AllCount;
                    if (_statuses.ContainsTab(tb.Text))
                    {
                        if (_statuses.Tabs[tb.Text].UnreadCount > 0)
                        {
                            if (SettingDialog.TabIconDisp)
                                tb.ImageIndex = 0;
                        }
                        else
                        {
                            if (SettingDialog.TabIconDisp)
                                tb.ImageIndex = -1;
                        }
                    }
                }
                if (!SettingDialog.TabIconDisp) ListTab.Refresh();
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
            SaveConfigsTabs();
        }
コード例 #4
0
ファイル: Tween.cs プロジェクト: lupeeloveee/OpenTween
        private void IdFilterAddMenuItem_Click(object sender, EventArgs e)
        {
            string name = GetUserId();
            if (name != null)
            {
                string tabName = "";

                //未選択なら処理終了
                if (_curList.SelectedIndices.Count == 0) return;

                //タブ選択(or追加)
                if (!SelectTab(ref tabName)) return;

                bool mv = false;
                bool mk = false;
                MoveOrCopy(ref mv, ref mk);

                FiltersClass fc = new FiltersClass();
                fc.NameFilter = name;
                fc.SearchBoth = true;
                fc.MoveFrom = mv;
                fc.SetMark = mk;
                fc.UseRegex = false;
                fc.SearchUrl = false;
                _statuses.Tabs[tabName].AddFilter(fc);

                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    _itemCache = null;
                    _postCache = null;
                    _curPost = null;
                    _curItemIndex = -1;
                    _statuses.FilterAll();
                    foreach (TabPage tb in ListTab.TabPages)
                    {
                        ((DetailsListView)tb.Tag).VirtualListSize = _statuses.Tabs[tb.Text].AllCount;
                        if (_statuses.Tabs[tb.Text].UnreadCount > 0)
                        {
                            if (SettingDialog.TabIconDisp)
                                tb.ImageIndex = 0;
                        }
                        else
                        {
                            if (SettingDialog.TabIconDisp)
                                tb.ImageIndex = -1;
                        }
                    }
                    if (!SettingDialog.TabIconDisp) ListTab.Refresh();
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
                SaveConfigsTabs();
            }
        }
コード例 #5
0
ファイル: FilterDialog.cs プロジェクト: shobotch/OpenTween
        private void ButtonOK_Click(object sender, EventArgs e)
        {
            bool isBlankMatch = false;
            bool isBlankExclude = false;

            //入力チェック
            if (!CheckMatchRule(out isBlankMatch) || !CheckExcludeRule(out isBlankExclude))
            {
                return;
            }
            if (isBlankMatch && isBlankExclude)
            {
                MessageBox.Show(Properties.Resources.ButtonOK_ClickText1, Properties.Resources.ButtonOK_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            int i = ListFilters.SelectedIndex;
            FiltersClass ft;

            ft = new FiltersClass();

            ft.MoveFrom = OptMove.Checked;
            ft.SetMark = CheckMark.Checked;

            string bdy = "";
            if (RadioAND.Checked)
            {
                ft.NameFilter = UID.Text;
                TweenMain owner = (TweenMain)this.Owner;
                int cnt = owner.AtIdSupl.ItemCount;
                owner.AtIdSupl.AddItem("@" + ft.NameFilter);
                if (cnt != owner.AtIdSupl.ItemCount)
                {
                    owner.ModifySettingAtId = true;
                }
                ft.SearchBoth = true;
                bdy = MSG1.Text;
            }
            else
            {
                ft.NameFilter = "";
                ft.SearchBoth = false;
                bdy = MSG2.Text;
            }
            ft.Source = TextSource.Text.Trim();

            if (CheckRegex.Checked || CheckLambda.Checked)
            {
                ft.BodyFilter.Add(bdy);
            }
            else
            {
                string[] bf = bdy.Trim().Split((char)32);
                foreach (string bfs in bf)
                {
                    if (!string.IsNullOrEmpty(bfs)) ft.BodyFilter.Add(bfs.Trim());
                }
            }

            ft.UseRegex = CheckRegex.Checked;
            ft.SearchUrl = CheckURL.Checked;
            ft.CaseSensitive = CheckCaseSensitive.Checked;
            ft.IsRt = CheckRetweet.Checked;
            ft.UseLambda = CheckLambda.Checked;

            bdy = "";
            if (RadioExAnd.Checked)
            {
                ft.ExNameFilter = ExUID.Text;
                ft.ExSearchBoth = true;
                bdy = ExMSG1.Text;
            }
            else
            {
                ft.ExNameFilter = "";
                ft.ExSearchBoth = false;
                bdy = ExMSG2.Text;
            }
            ft.ExSource = TextExSource.Text.Trim();

            if (CheckExRegex.Checked || CheckExLambDa.Checked)
            {
                ft.ExBodyFilter.Add(bdy);
            }
            else
            {
                string[] bf = bdy.Trim().Split((char)32);
                foreach (string bfs in bf)
                {
                    if (!string.IsNullOrEmpty(bfs)) ft.ExBodyFilter.Add(bfs.Trim());
                }
            }

            ft.ExUseRegex = CheckExRegex.Checked;
            ft.ExSearchUrl = CheckExURL.Checked;
            ft.ExCaseSensitive = CheckExCaseSensitive.Checked;
            ft.IsExRt = CheckExRetweet.Checked;
            ft.ExUseLambda = CheckExLambDa.Checked;

            if (_mode == EDITMODE.AddNew)
            {
                if (!_sts.Tabs[ListTabs.SelectedItem.ToString()].AddFilter(ft))
                    MessageBox.Show(Properties.Resources.ButtonOK_ClickText4, Properties.Resources.ButtonOK_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                _sts.Tabs[ListTabs.SelectedItem.ToString()].EditFilter((FiltersClass)ListFilters.SelectedItem, ft);
            }

            SetFilters(ListTabs.SelectedItem.ToString());
            ListFilters.SelectedIndex = -1;
            if (_mode == EDITMODE.AddNew)
            {
                ListFilters.SelectedIndex = ListFilters.Items.Count - 1;
            }
            else
            {
                ListFilters.SelectedIndex = i;
            }
            _mode = EDITMODE.None;

            if (_directAdd)
            {
                this.Close();
            }
        }
コード例 #6
0
ファイル: TabClass.cs プロジェクト: t-ashula/hoehoe2
 public void RemoveFilter(FiltersClass filter)
 {
     lock (_lockObj)
     {
         _filters.Remove(filter);
         FilterModified = true;
     }
 }
コード例 #7
0
ファイル: TabClass.cs プロジェクト: t-ashula/hoehoe2
 public void EditFilter(FiltersClass original, FiltersClass modified)
 {
     original.BodyFilter = modified.BodyFilter;
     original.NameFilter = modified.NameFilter;
     original.SearchBoth = modified.SearchBoth;
     original.SearchUrl = modified.SearchUrl;
     original.UseRegex = modified.UseRegex;
     original.CaseSensitive = modified.CaseSensitive;
     original.IsRt = modified.IsRt;
     original.UseLambda = modified.UseLambda;
     original.Source = modified.Source;
     original.ExBodyFilter = modified.ExBodyFilter;
     original.ExNameFilter = modified.ExNameFilter;
     original.ExSearchBoth = modified.ExSearchBoth;
     original.ExSearchUrl = modified.ExSearchUrl;
     original.ExUseRegex = modified.ExUseRegex;
     original.ExCaseSensitive = modified.ExCaseSensitive;
     original.IsExRt = modified.IsExRt;
     original.ExUseLambda = modified.ExUseLambda;
     original.ExSource = modified.ExSource;
     original.MoveFrom = modified.MoveFrom;
     original.SetMark = modified.SetMark;
     FilterModified = true;
 }
コード例 #8
0
ファイル: TabClass.cs プロジェクト: t-ashula/hoehoe2
        public bool AddFilter(FiltersClass filter)
        {
            lock (_lockObj)
            {
                if (_filters.Contains(filter))
                {
                    return false;
                }

                _filters.Add(filter);
                FilterModified = true;
                return true;
            }
        }
コード例 #9
0
        private void ShowDetail()
        {
            if (_directAdd)
            {
                return;
            }

            if (ListFilters.SelectedIndex > -1)
            {
                FiltersClass fc = (FiltersClass)ListFilters.SelectedItem;
                if (fc.SearchBoth)
                {
                    RadioAND.Checked  = true;
                    RadioPLUS.Checked = false;
                    UID.Enabled       = true;
                    MSG1.Enabled      = true;
                    MSG2.Enabled      = false;
                    UID.Text          = fc.NameFilter;
                    UID.SelectAll();
                    MSG1.Text = "";
                    MSG2.Text = "";
                    foreach (string bf in fc.BodyFilter)
                    {
                        MSG1.Text += bf + " ";
                    }
                    MSG1.Text = MSG1.Text.Trim();
                    MSG1.SelectAll();
                }
                else
                {
                    RadioPLUS.Checked = true;
                    RadioAND.Checked  = false;
                    UID.Enabled       = false;
                    MSG1.Enabled      = false;
                    MSG2.Enabled      = true;
                    UID.Text          = "";
                    MSG1.Text         = "";
                    MSG2.Text         = "";
                    foreach (string bf in fc.BodyFilter)
                    {
                        MSG2.Text += bf + " ";
                    }
                    MSG2.Text = MSG2.Text.Trim();
                    MSG2.SelectAll();
                }
                TextSource.Text            = fc.Source;
                CheckRegex.Checked         = fc.UseRegex;
                CheckURL.Checked           = fc.SearchUrl;
                CheckCaseSensitive.Checked = fc.CaseSensitive;
                CheckRetweet.Checked       = fc.IsRt;
                CheckLambda.Checked        = fc.UseLambda;

                if (fc.ExSearchBoth)
                {
                    RadioExAnd.Checked  = true;
                    RadioExPLUS.Checked = false;
                    ExUID.Enabled       = true;
                    ExMSG1.Enabled      = true;
                    ExMSG2.Enabled      = false;
                    ExUID.Text          = fc.ExNameFilter;
                    ExUID.SelectAll();
                    ExMSG1.Text = "";
                    ExMSG2.Text = "";
                    foreach (string bf in fc.ExBodyFilter)
                    {
                        ExMSG1.Text += bf + " ";
                    }
                    ExMSG1.Text = ExMSG1.Text.Trim();
                    ExMSG1.SelectAll();
                }
                else
                {
                    RadioExPLUS.Checked = true;
                    RadioExAnd.Checked  = false;
                    ExUID.Enabled       = false;
                    ExMSG1.Enabled      = false;
                    ExMSG2.Enabled      = true;
                    ExUID.Text          = "";
                    ExMSG1.Text         = "";
                    ExMSG2.Text         = "";
                    foreach (string bf in fc.ExBodyFilter)
                    {
                        ExMSG2.Text += bf + " ";
                    }
                    ExMSG2.Text = ExMSG2.Text.Trim();
                    ExMSG2.SelectAll();
                }
                TextExSource.Text            = fc.ExSource;
                CheckExRegex.Checked         = fc.ExUseRegex;
                CheckExURL.Checked           = fc.ExSearchUrl;
                CheckExCaseSensitive.Checked = fc.ExCaseSensitive;
                CheckExRetweet.Checked       = fc.IsExRt;
                CheckExLambDa.Checked        = fc.ExUseLambda;

                if (fc.MoveFrom)
                {
                    OptMove.Checked = true;
                }
                else
                {
                    OptCopy.Checked = true;
                }
                CheckMark.Checked = fc.SetMark;

                ButtonEdit.Enabled     = true;
                ButtonDelete.Enabled   = true;
                ButtonRuleUp.Enabled   = true;
                ButtonRuleDown.Enabled = true;
                ButtonRuleCopy.Enabled = true;
                ButtonRuleMove.Enabled = true;
            }
            else
            {
                RadioAND.Checked           = true;
                RadioPLUS.Checked          = false;
                UID.Enabled                = true;
                MSG1.Enabled               = true;
                MSG2.Enabled               = false;
                UID.Text                   = "";
                MSG1.Text                  = "";
                MSG2.Text                  = "";
                TextSource.Text            = "";
                CheckRegex.Checked         = false;
                CheckURL.Checked           = false;
                CheckCaseSensitive.Checked = false;
                CheckRetweet.Checked       = false;
                CheckLambda.Checked        = false;

                RadioExAnd.Checked           = true;
                RadioExPLUS.Checked          = false;
                ExUID.Enabled                = true;
                ExMSG1.Enabled               = true;
                ExMSG2.Enabled               = false;
                ExUID.Text                   = "";
                ExMSG1.Text                  = "";
                ExMSG2.Text                  = "";
                TextExSource.Text            = "";
                CheckExRegex.Checked         = false;
                CheckExURL.Checked           = false;
                CheckExCaseSensitive.Checked = false;
                CheckExRetweet.Checked       = false;
                CheckExLambDa.Checked        = false;

                OptCopy.Checked   = true;
                CheckMark.Checked = true;

                ButtonEdit.Enabled     = false;
                ButtonDelete.Enabled   = false;
                ButtonRuleUp.Enabled   = false;
                ButtonRuleDown.Enabled = false;
                ButtonRuleCopy.Enabled = false;
                ButtonRuleMove.Enabled = false;
            }
        }
コード例 #10
0
ファイル: FilterDialog.cs プロジェクト: t-ashula/hoehoe2
        private void ButtonOK_ClickExtracted()
        {
            bool isBlankMatch;
            bool isBlankExclude;

            // 入力チェック
            if (!CheckMatchRule(out isBlankMatch) || !CheckExcludeRule(out isBlankExclude))
            {
                return;
            }

            if (isBlankMatch && isBlankExclude)
            {
                MessageBox.Show(R.ButtonOK_ClickText1, R.ButtonOK_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            int prevSelectedIndex = ListFilters.SelectedIndex;
            var ft = new FiltersClass { MoveFrom = OptMove.Checked, SetMark = CheckMark.Checked };

            string bdy;
            if (RadioAND.Checked)
            {
                ft.NameFilter = UID.Text;
                TwMain.AddAtIdSuplItem("@" + ft.NameFilter);
                ft.SearchBoth = true;
                bdy = MSG1.Text;
            }
            else
            {
                ft.NameFilter = string.Empty;
                ft.SearchBoth = false;
                bdy = MSG2.Text;
            }

            ft.Source = TextSource.Text.Trim();

            if (CheckRegex.Checked || CheckLambda.Checked)
            {
                ft.BodyFilter.Add(bdy);
            }
            else
            {
                string[] bf = bdy.Trim().Split(' ');
                foreach (string bfs in bf)
                {
                    if (!string.IsNullOrEmpty(bfs))
                    {
                        ft.BodyFilter.Add(bfs.Trim());
                    }
                }
            }

            ft.UseRegex = CheckRegex.Checked;
            ft.SearchUrl = CheckURL.Checked;
            ft.CaseSensitive = CheckCaseSensitive.Checked;
            ft.IsRt = CheckRetweet.Checked;
            ft.UseLambda = CheckLambda.Checked;

            if (RadioExAnd.Checked)
            {
                ft.ExNameFilter = ExUID.Text;
                ft.ExSearchBoth = true;
                bdy = ExMSG1.Text;
            }
            else
            {
                ft.ExNameFilter = string.Empty;
                ft.ExSearchBoth = false;
                bdy = ExMSG2.Text;
            }

            ft.ExSource = TextExSource.Text.Trim();

            if (CheckExRegex.Checked || CheckExLambDa.Checked)
            {
                ft.ExBodyFilter.Add(bdy);
            }
            else
            {
                string[] bf = bdy.Trim().Split(' ');
                foreach (string bfs in bf)
                {
                    if (!string.IsNullOrEmpty(bfs))
                    {
                        ft.ExBodyFilter.Add(bfs.Trim());
                    }
                }
            }

            ft.ExUseRegex = CheckExRegex.Checked;
            ft.ExSearchUrl = CheckExURL.Checked;
            ft.ExCaseSensitive = CheckExCaseSensitive.Checked;
            ft.IsExRt = CheckExRetweet.Checked;
            ft.ExUseLambda = CheckExLambDa.Checked;

            if (_editMode == EDITMODE.AddNew)
            {
                if (!_sts.Tabs[ListTabs.SelectedItem.ToString()].AddFilter(ft))
                {
                    MessageBox.Show(R.ButtonOK_ClickText4, R.ButtonOK_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                _sts.Tabs[ListTabs.SelectedItem.ToString()].EditFilter((FiltersClass)ListFilters.SelectedItem, ft);
            }

            SetFilters(ListTabs.SelectedItem.ToString());
            ListFilters.SelectedIndex = -1;
            ListFilters.SelectedIndex = _editMode == EDITMODE.AddNew ? ListFilters.Items.Count - 1 : prevSelectedIndex;
            _editMode = EDITMODE.None;
            if (_isDirectAdd)
            {
                Close();
            }
        }