Exemplo n.º 1
0
        private void OnReorder()
        {
            isReordering = true;

            ConditionGroups.ForEachSafe(grp =>
            {
                if (!grp.IsExclude)
                {
                    if (ConditionGroups.Before(grp).Any(cg => cg.IsExclude))
                    {
                        ConditionGroups.Remove(grp);
                        int count = ConditionGroups.Count(cg => !cg.IsExclude);
                        ConditionGroups.Insert(count, grp);
                    }
                }
                else                 // grp.IsExclude
                {
                    if (ConditionGroups.After(grp).Any(cg => !cg.IsExclude))
                    {
                        ConditionGroups.Remove(grp);
                        ConditionGroups.Add(grp);
                    }
                }
            });

            ConditionGroups.ForEach(cg => cg.ReorderCommand.Execute());

            isReordering = false;
        }
Exemplo n.º 2
0
        private void OnCreateConditionGroup()
        {
            FilterConditionGroupViewModel cg = new FilterConditionGroupViewModel(this);

            cg.CreateConditionCommand.Execute();
            ConditionGroups.Add(cg);
        }
Exemplo n.º 3
0
        public void LoadFromString(string data)
        {
            isLoading = true;

            ConditionGroups.Clear();
            IEnumerable <string> lines      = data.Split('\n').Select(s => s.Trim('\r'));
            List <string>        lineBuffer = new List <string>();
            bool lineBufferIsExclude        = false;
            bool lineBufferIsEnabled        = true;
            bool haveName = false;

            foreach (string line in lines)
            {
                if (!haveName)
                {
                    // The first line contains the "quick filter" flag and filter name
                    string[] chunks = line.Split(new char[] { ',' }, 2);
                    if (chunks[0] == "qf")
                    {
                        QuickModifiedTime = DateTime.UtcNow.AddYears(-1);
                    }
                    DisplayName = chunks[1];
                    haveName    = true;
                }
                else
                {
                    string[] chunks = line.Split(new char[] { ',' }, 3);
                    if (chunks[0] == "or" || chunks[0] == "and not")
                    {
                        // New condition group starts
                        if (lineBuffer.Count > 0)
                        {
                            // Create condition group from buffer of previous lines
                            FilterConditionGroupViewModel grp = new FilterConditionGroupViewModel(this);
                            grp.LoadFromString(lineBuffer);
                            grp.IsExclude = lineBufferIsExclude;
                            grp.IsEnabled = lineBufferIsEnabled;
                            ConditionGroups.Add(grp);
                            lineBuffer.Clear();
                        }
                        // Remember type for the upcoming condition group
                        lineBufferIsExclude = chunks[0] == "and not";
                        lineBufferIsEnabled = chunks[1] == "on";
                    }
                    // Save line to buffer
                    lineBuffer.Add(line);
                }
            }
            // Create last condition group from buffer of previous lines
            FilterConditionGroupViewModel grp2 = new FilterConditionGroupViewModel(this);

            grp2.LoadFromString(lineBuffer);
            grp2.IsExclude = lineBufferIsExclude;
            grp2.IsEnabled = lineBufferIsEnabled;
            ConditionGroups.Add(grp2);

            isLoading = false;
        }
Exemplo n.º 4
0
 public string SaveToString()
 {
     if (!ConditionGroups.Any())
     {
         return(null);                                      // Intermediate state, should not be saved
     }
     return((IsQuickFilter ? "qf" : "") + "," + DisplayName + Environment.NewLine +
            ConditionGroups.Select(c => c.SaveToString()).Aggregate((a, b) => a + Environment.NewLine + b));
 }
Exemplo n.º 5
0
 public List<KeyValuePair<string, object>> GetParameterValues()
 {
     var values = new List<KeyValuePair<string, object>>();
     ConditionGroups.ForEach(m => values.AddRange(m.GetKeyAndValue()));
     Conditions.Where(m => m.Value != null).Each(m =>
     {
         var keyvalue = m.GetKeyAndValue();
         if (keyvalue.Key.IsNotNullAndWhiteSpace())
         {
             values.Add(keyvalue);
         }
     });
     return values;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Determines whether the specified item matches any condition group of this filter.
        /// </summary>
        /// <param name="item">The item to evaluate.</param>
        /// <returns></returns>
        public bool IsMatch(object item)
        {
            // Don't even start thinking if this is the "Show all" filter.
            if (AcceptAll)
            {
                return(true);
            }

            // Do not consider condition groups that are either disabled entirely or that do not
            // contain any condition that is enabled.
            var ActiveConditionGroups = ConditionGroups.Where(cg => cg.IsEnabled && cg.Conditions.Any(c => c.IsEnabled));

            // The item matches if it matches any non-excluding condition group or there are no
            // non-excluding condition groups at all, and only if it does not match any excluding
            // condition group.
            return(ActiveConditionGroups.Where(cg => !cg.IsExclude).AnyOrTrue(c => c.IsMatch(item)) &&
                   !ActiveConditionGroups.Where(cg => cg.IsExclude).Any(c => c.IsMatch(item)));
        }
Exemplo n.º 7
0
        public FilterViewModel GetDuplicate()
        {
            FilterViewModel newFilter = new FilterViewModel();

            newFilter.DisplayName     = this.DisplayName + " (copy)";
            newFilter.ConditionGroups = new ObservableCollection <FilterConditionGroupViewModel>(ConditionGroups.Select(cg => cg.GetDuplicate(newFilter)));
            return(newFilter);
        }