Ejemplo n.º 1
0
 public static async Task Search(string input)
 {
     if (string.IsNullOrEmpty(input)) return;
     state = EnumSearchState.Started;
     notifyState();
     ISearchProvider provider=null;
     var re_source=new Regex(@"(from:\s*(\w+))");
     var m = re_source.Match(input);
     if (m.Success) {
         var type=m.Groups[2].Value.ToLower();
         switch (type)
         {
             case "baidu": provider = new BaiduSearchProvider(); break;
             case "xiami": provider = new XiamiSearchProvider(); break;
             case "douban": provider = new DoubanSearchProvider(); break;
             default:
                 break;
         }
         input = re_source.Replace(input, "");
     }
     if (provider == null)
         provider = new XiamiSearchProvider();
     state = EnumSearchState.Working;
     var sr=await provider.Search(input);
     if (sr != null && state != EnumSearchState.Cancelling)
     {
         MessageBus.Instance.Publish(sr);
         notifyState(sr);
     }
     state = EnumSearchState.Finished;
     notifyState();
 }  
Ejemplo n.º 2
0
        public static async Task Search(string input, EnumSearchType t = EnumSearchType.all)
        {
            if (string.IsNullOrEmpty(input))
            {
                return;
            }
            state = EnumSearchState.Started;
            var searchInfo = new SearchResult {
                Keyword = input, SearchType = t
            };

            notifyState(searchInfo);
            ISearchProvider provider  = null;
            var             re_source = new Regex(@"(source:\s*(\w+))");
            var             m         = re_source.Match(input);

            if (m.Success)
            {
                var type = m.Groups[2].Value.ToLower();
                switch (type)
                {
                case "baidu": provider = new BaiduSearchProvider(); break;

                case "xiami": provider = new XiamiSearchProvider(); break;

                case "douban": provider = new DoubanSearchProvider(); break;

                default:
                    break;
                }
                input = re_source.Replace(input, "");
            }
            if (provider == null)
            {
                provider = new XiamiSearchProvider();
            }
            state = EnumSearchState.Working;
            try
            {
                var sr = await provider.Search(input, t);

                if (sr != null && state != EnumSearchState.Cancelling)
                {
                    MessageBus.Instance.Publish(sr);
                    notifyState(sr);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
            state = EnumSearchState.Finished;
            notifyState(searchInfo);
        }