Beispiel #1
0
        private FilterCondition GetCondition(int id)
        {
            foreach (FilterCondition condition in this.Conditions)
            {
                if (condition.Id == id)
                {
                    return(condition);
                }
            }

            FilterCondition newCondition = new FilterCondition(id);

            this.conditions.Add(newCondition);

            return(newCondition);
        }
Beispiel #2
0
        private void ParseConditions()
        {
            XmlDocument xml = new XmlDocument();

            if (filtersStr.StartsWith("{"))
            {
                xml.LoadXml(JSON.DeserializeXmlNode("{filters:" + filtersStr + "}").OuterXml);
            }
            else
            {
                xml.LoadXml("<filters>".ConcatWith(this.filtersStr, "</filters>"));
            }


            this.conditions = new FilterConditionCollection();

            foreach (XmlNode node in xml.SelectSingleNode("filters").ChildNodes)
            {
                string name = node.Name;

                int value;

                if (this.CheckPattern(fieldPattern, name, out value))
                {
                    FilterCondition condition = this.GetCondition(value);
                    condition.Name = node.InnerText;
                    continue;
                }

                if (this.CheckPattern(dataTypePattern, name, out value))
                {
                    FilterCondition condition = this.GetCondition(value);
                    condition.FilterType = (FilterType)Enum.Parse(typeof(FilterType), node.InnerText, true);
                    continue;
                }

                if (this.CheckPattern(dataComparisonPattern, name, out value))
                {
                    FilterCondition condition = this.GetCondition(value);
                    condition.Comparison = (Comparison)Enum.Parse(typeof(Comparison), node.InnerText, true);
                    continue;
                }

                if (this.CheckPattern(dataValuePattern, name, out value))
                {
                    FilterCondition condition = this.GetCondition(value);
                    condition.Value = node.InnerText;

                    continue;
                }
            }

            this.conditions.Sort(delegate(FilterCondition x, FilterCondition y)
            {
                if (x == null)
                {
                    return(y == null ? 0 : -1);
                }
                else
                {
                    return(y == null ? 1 : x.Id.CompareTo(y.Id));
                }
            });
        }