Esempio n. 1
0
        public void UpdateDynamicNodeGeneric() {
            // grab list of possible values
            HashSet<string> possibleValues = DBManager.GetAllValues(BasicFilteringField, BasicFilteringRelation, GetFilteredItems());

            // build lookup for subnodes and build list of nodes to remove
            List<DBNode<T>> toRemove = new List<DBNode<T>>();
            Dictionary<string, DBNode<T>> nodeLookup = new Dictionary<string, DBNode<T>>();
            foreach (DBNode<T> currSubNode in Children) {
                try {
                    if (!currSubNode.AutoGenerated)
                        continue;

                    if (currSubNode.Filter == null || currSubNode.Filter.Criteria == null || currSubNode.Filter.Criteria.Count == 0 ||
                        !possibleValues.Contains(currSubNode.Filter.Criteria[0].Value.ToString()))

                        toRemove.Add(currSubNode);
                    else
                        nodeLookup[currSubNode.Filter.Criteria[0].Value.ToString()] = currSubNode;
                }
                catch (Exception e) {
                    logger.ErrorException("Unexpected error updating dynamic node.", e);
                }
            }

            // remove subnodes that are no longer valid
            foreach (DBNode<T> currSubNode in toRemove) {
                Children.Remove(currSubNode);
                currSubNode.Delete();
            }

            // add subnodes that are missing
            foreach (string currValue in possibleValues) {
                if (nodeLookup.ContainsKey(currValue))
                    continue;

                DBNode<T> newSubNode = new DBNode<T>();
                newSubNode.Name = currValue;
                newSubNode.AutoGenerated = true;

                DBFilter<T> newFilter = new DBFilter<T>();
                DBCriteria<T> newCriteria = new DBCriteria<T>();
                newCriteria.Field = BasicFilteringField;
                newCriteria.Relation = BasicFilteringRelation;
                newCriteria.Operator = DBCriteria<T>.OperatorEnum.EQUAL;
                newCriteria.Value = currValue;

                newFilter.Criteria.Add(newCriteria);
                newSubNode.Filter = newFilter;

                Children.Add(newSubNode);
                newSubNode.Parent = this;
            }
        }
Esempio n. 2
0
        public HashSet<IFilter<T>> GetAllFilters() {
            HashSet<IFilter<T>> results = new HashSet<IFilter<T>>();

            // get the filters for all parent nodes
            DBNode<T> currNode = this;
            while (currNode != null) {
                if (currNode.Filter != null)
                    results.Add(currNode.Filter);
                currNode = currNode.Parent;
            }

            return results;
        }
Esempio n. 3
0
        public static bool MoveDown <T>(this List <DBNode <T> > list, DBNode <T> item, bool commit) where T : DatabaseTable
        {
            int index = list.IndexOf(item);

            if (index >= list.Count - 1 || index < 0)
            {
                return(false);
            }

            list.Reverse(index, 2);
            list.Normalize(commit);

            return(true);
        }
Esempio n. 4
0
 public static bool MoveDown <T>(this List <DBNode <T> > list, DBNode <T> item) where T : DatabaseTable
 {
     return(list.MoveDown(item, false));
 }