Пример #1
0
        public List <PhoneMessage> ApplyFilters()
        {
            if (settings != null)
            {
                Func <bool?, bool?, bool?, bool> combine =
                    (b1, b2, b3) => ((b1 ?? b2 ?? b3) == null) || (b1 ?? false) || (b2 ?? false) || (b3 ?? false);

                if (settings.AndCombined)
                {
                    combine = (b1, b2, b3) => (b1 ?? true) && (b2 ?? true) && (b3 ?? true);
                }

                List <PhoneMessage> filterMessages =
                    (from message in messages
                     where combine(settings.ContactSelected?.ToString().Equals(message.UserContact.GetContact()),
                                   string.IsNullOrWhiteSpace(settings.TextSearch)
                            ? (bool?)null
                            : message.Text.Contains(settings.TextSearch),
                                   settings.IsFrom || settings.IsTo
                            ? (!settings.IsFrom || message.ReceiveDateTime >= settings.FromDate) &&
                                   (!settings.IsTo || message.ReceiveDateTime <= settings.ToDate)
                            : (bool?)null)
                     select message).ToList();

                SetFormatting(settings.FormatNumber);
                foreach (var message in filterMessages)
                {
                    message.FormatText = Formatter?.Invoke(message) ?? message.Text;
                }

                return(filterMessages);
            }

            return(messages);
        }
Пример #2
0
 static void Print(FormatDelegate format, string str)
 {
     Console.WriteLine(format?.Invoke(str));
     Console.WriteLine(format(str));
 }