Beispiel #1
0
        private static Sort[] LoadSorting(XmlNode sortingNode)
        {
            Sort[] sorting = new Sort[sortingNode.ChildNodes.Count];

            int i = 0;
            foreach (XmlNode childNode in sortingNode.ChildNodes)
                sorting[i++] = new Sort(childNode);

            return sorting;
        }
Beispiel #2
0
        public static Search LoadSearch(XmlNode node)
        {
            String uuid = Helpers.GetXmlAttribute(node, "uuid");
            String name = Helpers.GetXmlAttribute(node, "name");
            int major_version = int.Parse(Helpers.GetXmlAttribute(node, "major_version"));
            //int minor_version = int.Parse(Helpers.GetXmlAttribute(node, "minor_version"));

            XmlAttribute expanded = node.Attributes["show_expanded"];
            if (expanded == null)
            {
                // Backwards compat.
                expanded = node.Attributes["showsearch"];
            }
            bool showQuery = expanded == null ? false : ParseBool(expanded.Value);

            if (major_version > CURRENT_SEARCH_MAJOR_VERSION)
                throw new SearchVersionException(major_version, CURRENT_SEARCH_MAJOR_VERSION);

            Query query;
            Object q = FromXmlNode(node.ChildNodes[0]);
            switch (major_version)
            {
                case 0:
                case 1:
                    QueryFilter filter = q as QueryFilter;
                    if (filter == null)
                        throw new I18NException(I18NExceptionType.XmlInvalid, node.OuterXml);
                    query = new Query(null, filter);
                    break;
                default:
                    query = q as Query;
                    if (query == null || query.QueryScope == null)  // query.QueryFilter == null is allowed
                        throw new I18NException(I18NExceptionType.XmlInvalid, node.OuterXml);
                    break;
            }

            Grouping grouping = null;
            Sort[] sorting = new Sort[] { };
            List<KeyValuePair<String, int>> columns = null;
            int i = 0;
            foreach (XmlNode child in node.ChildNodes)
            {
                if (i != 0)
                {
                    if (child.Name == "columns")
                    {
                        columns = LoadColumns(child);
                    }
                    else if (child.Name == "sorting")
                    {
                        sorting = LoadSorting(child);
                    }
                    else
                    {
                        grouping = (Grouping)FromXmlNode(child);
                    }
                }

                i++;
            }

            return new Search(query, grouping, showQuery, name, uuid, columns, sorting);
        }