Example #1
0
        private bool FilterMessages(object item)
        {
            if (string.IsNullOrEmpty(SearchFilter))
            {
                return(true);
            }
            else
            {
                Message mes = item as Message;

                if (SearchFilter.Contains(':'))
                {
                    string[] split_filter = SearchFilter.Split(':');

                    if (split_filter.Length < 2 || !int.TryParse(split_filter[1], out int val))
                    {
                        return(true);
                    }

                    if (split_filter[0].ToLowerInvariant() == "msgid")
                    {
                        return(mes.MessageID == val);
                    }
                    else if (split_filter[0].ToLowerInvariant() == "index")
                    {
                        return(Messages.IndexOf(mes) == val);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    return(mes.Text.Replace("\n", " ").IndexOf(SearchFilter, StringComparison.OrdinalIgnoreCase) >= 0);
                }
            }
        }
Example #2
0
        private void Filter(object sender, FilterEventArgs e)
        {
            // see Notes on Filter Methods:
            var src = e.Item as Message;

            if (src == null)
            {
                e.Accepted = false;
            }

            else if (SearchFilter.Contains("itemid"))
            {
                string[] parsed = SearchFilter.Split(':');

                if (parsed.Count() >= 2)
                {
                    try
                    {
                        if (parsed[1] != "" && src.DisplayItemId != (ItemID)Convert.ToByte(parsed[1]))
                        {
                            e.Accepted = false;
                        }
                    }
                    catch (OverflowException ex)
                    {
                        SearchFilter = string.Format("itemid:{0}", 255);
                    }
                    catch (FormatException ex)
                    {
                        SearchFilter = string.Format("itemid:{0}", parsed[1].Remove(parsed[1].Length - 1));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(string.Format("Exception {0}!"), ex.ToString());
                    }
                }
            }

            else if (SearchFilter.Contains("msgid"))
            {
                string[] parsed = SearchFilter.Split(':');

                if (parsed.Count() >= 2)
                {
                    // Oh boy, parsing
                    try
                    {
                        if (parsed[1] != "" && Convert.ToInt32(src.MessageId) != Convert.ToInt32(parsed[1]))
                        {
                            e.Accepted = false;
                        }
                    }
                    // Something f****d up. Let's catch the exception
                    catch (OverflowException ex)
                    {
                        SearchFilter = string.Format("msgid:{0}", (int)(GetHighestID() - 1));
                    }
                    catch (FormatException ex)
                    {
                        SearchFilter = string.Format("msgid:{0}", parsed[1].Remove(parsed[1].Length - 1));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(string.Format("Exception {0}!"), ex.ToString());
                    }
                }
            }

            else if (SearchFilter.Contains("index"))
            {
                string[] parsed = SearchFilter.Split(':');

                if (parsed.Count() >= 2)
                {
                    try
                    {
                        if (parsed[1] != "" && Convert.ToInt32(src.Index) != Convert.ToInt32(parsed[1]))
                        {
                            e.Accepted = false;
                        }
                    }
                    // Something f****d up. Let's catch the exception
                    catch (OverflowException ex)
                    {
                        SearchFilter = string.Format("index:{0}", (int)(LoadedTextFile.MessageList.Count - 1));
                    }
                    catch (FormatException ex)
                    {
                        SearchFilter = string.Format("index:{0}", parsed[1].Remove(parsed[1].Length - 1));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(string.Format("Exception {0}!"), ex.ToString());
                    }
                }
            }

            else if (src.TextData != null && !src.TextData.Contains(SearchFilter))// here is FirstName a Property in my YourCollectionItem
            {
                e.Accepted = false;
            }
        }