Exemple #1
0
        private static void ShowSearchExp(SearchExp node, string indent)
        {
            string sb = "";

            if (node.property != null)
            {
                sb += node.property + " " + node.op + "=";
                if (node.propertyClass != null)
                {
                    sb += node.propertyClass;
                }
                else
                {
                    sb += node.val;
                }

                Console.WriteLine(indent + indent.Length + ":" + sb);
            }

            bool first = true;

            foreach (SearchExp child in node.children)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.WriteLine(indent + indent.Length + ":" + node.logOp);
                }
                ShowSearchExp(child, indent + " ");
            }
        }
Exemple #2
0
            public override void EnterRelExp(UPnPParser.RelExpContext context)
            {
                SearchExp searchExp = new SearchExp();

                searchExp.parent = node;

                node.children.Add(searchExp);

                node = searchExp;
            }
Exemple #3
0
            public override void ExitRelExp(UPnPParser.RelExpContext context)
            {
                if (node.property == Property.CLASS)
                {
                    node.propertyClass = ParsePropertyClass(val);
                }
                else
                {
                    node.val = val;
                }

                node = node.parent;
            }
Exemple #4
0
        public static SearchExp Parse(string text)
        {
            UPnPLexer         lexer  = new UPnPLexer(new AntlrInputStream(text));
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            UPnPParser        parser = new UPnPParser(tokens);

            parser.AddErrorListener(new SearchErrorListener());

            SearchExp root = new SearchExp();

            parser.AddParseListener(new SearchParseListener(root));

            parser.searchCrit();
            //ShowSearchExp(text, root);

            return(root);
        }
Exemple #5
0
        public static IFilter Convert(SearchExp exp, ICollection <Guid> types)
        {
            if (exp.property == Property.CLASS)
            {
                // Container property classes cause title searches to change attribute (see later)
                if (exp.op == Op.DERIVED_FROM && exp.propertyClass == PropertyClass.AUDIO_ITEM)
                {
                    types.Add(AudioAspect.ASPECT_ID);
                    return(null);
                }
                else if (exp.op == Op.EQUALS && exp.propertyClass == PropertyClass.MUSIC_ALBUM)
                {
                    types.Add(AudioAspect.ASPECT_ID);
                    return(new PropertyClassFilter(exp.propertyClass.Value));
                }
                else if (exp.op == Op.EQUALS && exp.propertyClass == PropertyClass.MUSIC_ARTIST)
                {
                    types.Add(AudioAspect.ASPECT_ID);
                    return(new PropertyClassFilter(exp.propertyClass.Value));
                }
                else if (exp.op == Op.DERIVED_FROM && exp.propertyClass == PropertyClass.VIDEO_ITEM)
                {
                    types.Add(VideoAspect.ASPECT_ID);
                    return(null);
                }
                else if (exp.op == Op.DERIVED_FROM && exp.propertyClass == PropertyClass.PLAYLIST_CONTAINER)
                {
                    types.Add(VideoAspect.ASPECT_ID);
                    return(null);
                }
                else if (exp.op == Op.DERIVED_FROM && exp.propertyClass == PropertyClass.IMAGE_ITEM)
                {
                    types.Add(ImageAspect.ASPECT_ID);
                    return(null);
                }
                else
                {
                    throw new SearchException("Unable to convert property " + exp.op + " " + exp.propertyClass);
                }
            }
            else if (exp.property == Property.TITLE)
            {
                if (exp.op == Op.CONTAINS)
                {
                    return(new LikeFilter(MediaAspect.ATTR_TITLE, "%" + exp.val + "%", null));
                }
            }
            else if (exp.property == Property.CREATOR)
            {
                return(new LikeFilter(AudioAspect.ATTR_ARTISTS, "%" + exp.val + "%", null));
            }
            else if (exp.property == Property.ARTIST)
            {
                return(new LikeFilter(AudioAspect.ATTR_ARTISTS, "%" + exp.val + "%", null));
            }

            IList <IFilter> childFilters = exp.children.Select(childExp => Convert(childExp, types)).Where(filter => filter != null).ToList();

            // Now do the check for container property classes
            int index = 0;

            while (index < childFilters.Count)
            {
                PropertyClassFilter pcf = childFilters[index] as PropertyClassFilter;
                if (pcf != null)
                {
                    if (pcf.propertyClass == PropertyClass.MUSIC_ALBUM)
                    {
                        ChangeAttribute(childFilters, MediaAspect.ATTR_TITLE, AudioAspect.ATTR_ALBUM);
                    }
                    else if (pcf.propertyClass == PropertyClass.MUSIC_ARTIST)
                    {
                        ChangeAttribute(childFilters, MediaAspect.ATTR_TITLE, AudioAspect.ATTR_ARTISTS);
                    }
                    childFilters.RemoveAt(index);
                }
                else
                {
                    index++;
                }
            }

            if (childFilters.Count == 0)
            {
                return(null);
            }
            else if (childFilters.Count == 1)
            {
                return(childFilters[0]);
            }

            return(new BooleanCombinationFilter(exp.logOp == LogOp.AND ? BooleanOperator.And : BooleanOperator.Or, childFilters));
        }
Exemple #6
0
 public static void ShowSearchExp(string title, SearchExp node)
 {
     Console.WriteLine(title + ":");
     ShowSearchExp(node, "");
 }
Exemple #7
0
 public override void ExitInnerExp(UPnPParser.InnerExpContext context)
 {
     node = node.parent;
 }
Exemple #8
0
 public SearchParseListener(SearchExp root)
 {
     node = root;
 }