Ejemplo n.º 1
0
 public static Search SearchForVappGroup(Grouping grouping, object parent, object v)
 {
     return(new Search(new Query(new QueryScope(ObjectTypes.VM), grouping.GetSubquery(parent, v)),
                       grouping.GetSubgrouping(v), false, grouping.GetGroupName(v), "", false));
 }
Ejemplo n.º 2
0
        public static Search SearchFor(IEnumerable <IXenObject> objects)
        {
            if (objects == null)
            {
                return(SearchFor((IXenObject)null));
            }

            List <IXenObject> objectList = new List <IXenObject>(objects);

            if (objectList.Count == 0)
            {
                return(SearchFor((IXenObject)null));
            }
            else if (objectList.Count == 1)
            {
                return(SearchFor(objectList[0]));
            }
            else
            {
                bool containsHost = false;
                bool containsPool = false;

                List <QueryFilter> queryFilters = new List <QueryFilter>();
                foreach (IXenObject obj in objects)
                {
                    Pool poolAncestor = obj != null?Helpers.GetPool(obj.Connection) : null;

                    if (poolAncestor != null)
                    {
                        containsPool = true;
                        QueryFilter uuidQuery = new StringPropertyQuery(PropertyNames.uuid, Helpers.GetUuid(poolAncestor), StringPropertyQuery.PropertyQueryType.exactmatch, true);
                        queryFilters.Add(new RecursiveXMOPropertyQuery <Pool>(PropertyNames.pool, uuidQuery));
                    }
                    else
                    {
                        Host hostAncestor = Helpers.GetHostAncestor(obj);
                        if (hostAncestor != null)
                        {
                            containsHost = true;
                            QueryFilter uuidQuery = new StringPropertyQuery(PropertyNames.uuid, Helpers.GetUuid(hostAncestor), StringPropertyQuery.PropertyQueryType.exactmatch, true);
                            queryFilters.Add(new RecursiveXMOListPropertyQuery <Host>(PropertyNames.host, uuidQuery));
                        }
                    }
                }
                Grouping grouping = null;
                if (containsPool)
                {
                    Grouping hostGrouping = new XenModelObjectPropertyGrouping <Host>(PropertyNames.host, null);
                    grouping = new XenModelObjectPropertyGrouping <Pool>(PropertyNames.pool, hostGrouping);
                }
                else if (containsHost)
                {
                    grouping = new XenModelObjectPropertyGrouping <Host>(PropertyNames.host, null);
                }

                GroupQuery groupQuery = new GroupQuery(queryFilters.ToArray(), GroupQuery.GroupQueryType.Or);
                Query      query      = new Query(GetOverviewScope(), groupQuery);

                return(new Search(query, grouping, false, Messages.SEARCH_TITLE_OVERVIEW, null, false));
            }
        }
Ejemplo n.º 3
0
 public Search(Query query, Grouping grouping, bool showSearch, String name,
               String uuid, bool defaultSearch)
     : this(query, grouping, showSearch, name, uuid, null, new Sort[] { })
 {
     this.defaultSearch = defaultSearch;
 }
Ejemplo n.º 4
0
 public AllCustomFieldsGrouping(Grouping subgrouping)
     : base(subgrouping)
 {
 }
Ejemplo n.º 5
0
 protected Grouping(Grouping subgrouping)
 {
     this.subgrouping = subgrouping;
 }
Ejemplo n.º 6
0
 public XenModelObjectPropertyGrouping(PropertyNames property, Grouping subgrouping)
     : base(property, subgrouping)
 {
 }
Ejemplo n.º 7
0
 public CustomFieldGrouping(CustomFieldDefinition definition, Grouping subgrouping)
     : base(subgrouping)
 {
     this.definition = definition;
 }
Ejemplo n.º 8
0
 public BoolGrouping(PropertyNames property, Grouping subgrouping)
     : base(property, subgrouping)
 {
     this.i18nfalse = PropertyAccessors.PropertyNames_i18n_false[property];
 }
Ejemplo n.º 9
0
 public FolderGrouping(Grouping subgrouping)
     : base(subgrouping)
 {
 }
Ejemplo n.º 10
0
 public FolderGroup(Search search, Grouping grouping)
     : base(search, grouping)
 {
 }
Ejemplo n.º 11
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"));

            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, name, uuid, columns, sorting));
        }
Ejemplo n.º 12
0
        private void AddGrouped(IXenObject o, Object group)
        {
            // We sometimes need to apply the query to the group. For example, suppose VM 1
            // is connected to Network 1 and Network 2. Then "VMs grouped by Network" will
            // show
            //
            // -- Network 1
            //    -- VM 1
            // -- Network 2
            //    -- VM 1
            //
            // So far so good. Now consider "VMs connected to Network 1 grouped by Network".
            // Without the following piece of code, that would show exactly the same thing:
            // because the second VM 1 is connected to Network 1, and is correctly grouped
            // in Network 2. But what the user presumably wanted to see was just Network 1
            // with its VMs under it: and that is achieved by applying the filter to the
            // networks.
            //
            // The consequence when adding new searches is that a search that returns a
            // XenObject of type T must return (T)o rather than null when o is a T,
            // otherwise if you both group and filter by that type, the group will fail
            // to match the filter and you'll get no results.
            //
            IXenObject groupModelObject = group as IXenObject;

            if (groupModelObject != null && XenAdminConfigManager.Provider.ObjectIsHidden(groupModelObject.opaque_ref))
            {
                return;
            }

            if (search.Query != null && groupModelObject != null)
            {
                QueryFilter subquery = grouping.GetRelevantGroupQuery(search);
                if (subquery != null && subquery.Match(groupModelObject) == false)
                {
                    return;
                }
            }

            Group nextGroup;

            // Some types of grouping can add several levels to the hierarchy.
            // This should not be confused with the IList in Add(IXenObject o):
            // that adds the item to several groups, whereas this adds it to a
            // single group several levels deep. In order to reach here,
            // grouping.GetGroup(o) must return a list of arrays.
            //
            // NB We don't do the GetRelevantGroupQuery() check as above for the
            // groups added in this way because we never need it: but if we ever
            // add it, we should probably do a first pass to check all the groups
            // first before adding any.
            Array groups = group as Array;

            if (groups != null)
            {
                nextGroup = this;
                for (int i = 0; i < groups.Length; ++i)
                {
                    Grouping gr = (i == groups.Length - 1 ? grouping.subgrouping : grouping);
                    nextGroup = (nextGroup as AbstractNodeGroup).FindOrAddSubgroup(grouping, groups.GetValue(i), gr);
                }
            }
            else
            {
                nextGroup = FindOrAddSubgroup(grouping, group, grouping.subgrouping);
            }

            nextGroup.Add(o);
        }
Ejemplo n.º 13
0
 public NodeGroup(Search search, Grouping grouping)
     : base(search, grouping)
 {
 }
Ejemplo n.º 14
0
 protected AbstractNodeGroup(Search search, Grouping grouping)
     : base(search)
 {
     this.grouped  = new Dictionary <GroupKey, Group>();
     this.grouping = grouping;
 }
Ejemplo n.º 15
0
 public GroupKey(Grouping grouping, object key)
 {
     this.grouping = grouping;
     this.key      = key;
 }
Ejemplo n.º 16
0
        /// <param name="includeFolders">
        /// Normally exclude folders even if in search: CA-27260
        /// </param>
        private static Search OrgViewSearch(Search search, bool includeFolders, QueryFilter addFilter, Grouping grouping)
        {
            QueryFilter filter;
            ObjectTypes types;

            if (search == null || search.Query == null || search.Query.QueryScope == null)
            {
                types = includeFolders ? ObjectTypes.AllIncFolders : ObjectTypes.AllExcFolders;
            }
            else
            {
                types = includeFolders
                            ? search.Query.QueryScope.ObjectTypes
                            : (search.Query.QueryScope.ObjectTypes & ~ObjectTypes.Folder);
            }

            QueryScope scope = new QueryScope(types);

            if (search == null || search.Query == null || search.Query.QueryFilter == null)
            {
                filter = addFilter;
            }
            else if (addFilter == null)
            {
                filter = search.Query.QueryFilter;
            }
            else
            {
                filter = new GroupQuery(new QueryFilter[] { search.Query.QueryFilter, addFilter }, GroupQuery.GroupQueryType.And);
            }

            return(new Search(new Query(scope, filter), grouping, false, "", null, null, new Sort[] { }));
        }