Beispiel #1
0
        public override async Task <AutoHintItems> GetAutoHintItemsAsync(SearchPara para, CancellationToken token)
        {
            var list = new AutoHintItems();
            var net  = new NetOperator(Settings);

            switch (SiteType)
            {
            case SiteTypeEnum.Xml:
                var xml = await net.GetXmlAsync(GetHintQuery(para), token);

                if (xml == null)
                {
                    return(list);
                }
                var root = xml.SelectSingleNode("tags");
                if (root?.ChildNodes == null)
                {
                    return(list);
                }
                foreach (XmlElement child in root.ChildNodes)
                {
                    list.Add(new AutoHintItem
                    {
                        Word  = child.GetAttribute("name"),
                        Count = child.GetAttribute("count")
                    });
                }

                return(list);

            case SiteTypeEnum.Json:
                var json = await net.GetJsonAsync(GetHintQuery(para), token);

                foreach (var item in Extend.GetList(json))
                {
                    list.Add(new AutoHintItem
                    {
                        Word  = $"{item.name}",
                        Count = $"{item.post_count}"
                    });
                }
                return(list);
            }

            return(list);
        }