Exemple #1
0
        public static Search SearchForFolder(string path)
        {
            QueryScope  scope       = new QueryScope(ObjectTypes.AllIncFolders);
            QueryFilter innerFilter = new StringPropertyQuery(PropertyNames.uuid, path,
                                                              StringPropertyQuery.PropertyQueryType.exactmatch, true);
            QueryFilter filter   = new RecursiveXMOPropertyQuery <Folder>(PropertyNames.folder, innerFilter);
            Query       q        = new Query(scope, filter);
            Grouping    grouping = new FolderGrouping((Grouping)null);

            string[] pathParts = Folders.PointToPath(path);
            string   name      = ((pathParts.Length == 0 || (pathParts.Length == 1 && pathParts[pathParts.Length - 1] == String.Empty)) ?
                                  Messages.FOLDERS : pathParts[pathParts.Length - 1]);

            return(new Search(q, grouping, false, name, null, false));
        }
Exemple #2
0
        public override bool Equals(object obj)
        {
            if (!base.Equals(obj))
            {
                return(false);
            }

            StringPropertyQuery other = obj as StringPropertyQuery;

            if (other == null)
            {
                return(false);
            }

            return(other.caseSensitive == this.caseSensitive && other.query == this.query && other.type == this.type);
        }
Exemple #3
0
        public override bool?Match(IXenObject o)
        {
            String value = CustomFieldsManager.GetCustomFieldValue(o, definition) as String;

            if (value == null)
            {
                return(false);
            }

            if (query == null)
            {
                return(true);
            }

            return(StringPropertyQuery.MatchString(value, query.ToLower(), type, false));
        }
Exemple #4
0
        /// <summary>
        /// This gets the default search for the overview panel when an object in the tree is selected.
        /// Pass null as value and you'll get the default search (this could be the default overview or default treeview search,
        /// depending on the value of scope).
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Search SearchFor(IXenObject value, QueryScope scope)
        {
            if (value is Host)
            {
                Grouping hostGrouping = new XenModelObjectPropertyGrouping <Host>(PropertyNames.host, null);

                QueryFilter uuidQuery = new StringPropertyQuery(PropertyNames.uuid, Helpers.GetUuid(value), StringPropertyQuery.PropertyQueryType.exactmatch, true);
                QueryFilter hostQuery = new RecursiveXMOListPropertyQuery <Host>(PropertyNames.host, uuidQuery);

                Query query = new Query(scope, hostQuery);
                return(new Search(query, hostGrouping, false, String.Format(Messages.SEARCH_TITLE_HOST, Helpers.GetName(value)), null, false));
            }
            else if (value is Pool)
            {
                Grouping hostGrouping = new XenModelObjectPropertyGrouping <Host>(PropertyNames.host, null);
                Grouping poolGrouping = new XenModelObjectPropertyGrouping <Pool>(PropertyNames.pool, hostGrouping);

                QueryFilter uuidQuery = new StringPropertyQuery(PropertyNames.uuid, Helpers.GetUuid(value), StringPropertyQuery.PropertyQueryType.exactmatch, true);
                QueryFilter poolQuery = new RecursiveXMOPropertyQuery <Pool>(PropertyNames.pool, uuidQuery);

                Query query = new Query(scope, poolQuery);
                return(new Search(query, poolGrouping, false, String.Format(Messages.SEARCH_TITLE_POOL, Helpers.GetName(value)), null, false));
            }
            else if (value is Folder)
            {
                Folder folder = value as Folder;
                return(Search.SearchForFolder(folder.opaque_ref));
            }
            else
            {
                // This is the default search on the treeview

                //Grouping storageLinkPoolGrouping = new XenModelObjectPropertyGrouping<StorageLinkPool>(PropertyNames.storageLinkPool, (Grouping)null);
                //Grouping storageLinkSystemGrouping = new XenModelObjectPropertyGrouping<StorageLinkSystem>(PropertyNames.storageLinkSystem, storageLinkPoolGrouping);
                //Grouping storageLinkServerGrouping = new XenModelObjectPropertyGrouping<StorageLinkServer>(PropertyNames.storageLinkServer, storageLinkSystemGrouping);
                Grouping dockervmGrouping = new XenModelObjectPropertyGrouping <VM>(PropertyNames.dockervm, null);
                Grouping hostGrouping     = new XenModelObjectPropertyGrouping <Host>(PropertyNames.host, dockervmGrouping);
                Grouping poolGrouping     = new XenModelObjectPropertyGrouping <Pool>(PropertyNames.pool, hostGrouping);

                return(new Search(new Query(scope, null),
                                  poolGrouping, false, String.Format(Messages.SEARCH_TITLE_OVERVIEW), null, false));
            }
        }
Exemple #5
0
 protected override bool MatchItem(T value)
 {
     return(StringPropertyQuery.MatchString(Helpers.GetName(value), query, type, false));
 }
Exemple #6
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));
            }
        }