private async void Search(object param)
        {
            m_searchResults.Clear();
            m_searchContext  = null;
            IsFavouritesMode = false;
            Searching        = true;
            m_filteredResults.SortDescriptions.Clear();
            m_filteredResults.Refresh();

            try
            {
                ActionsCount++;
                AllDataSheetSearchResult result = await AllDataSheetPart.SearchAsync(m_searchField);

                m_searchContext = result.SearchContext;
                AddResults(result.Parts);
            }
            catch
            {
                Global.MessageBox(this, Global.GetStringResource("StringSearchError"), MessageBoxExPredefinedButtons.Ok);
            }
            finally
            {
                ActionsCount--;
            }

            Searching = false;
        }
Ejemplo n.º 2
0
        public static AllDataSheetSearchResult Search(string value)
        {
            string         url     = $"{SiteAddress}?Searchword={value}&sPage=1&sField=4";
            HttpWebRequest request = Requests.CreateDefaultRequest(url);
            string         result  = Requests.ReadResponseString(request);

            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(result);

            int totalPages;

            AllDataSheetSearchContext.SearchOption option;
            FilterSearchMode(document, out totalPages, out option);

            AllDataSheetSearchContext searchContext = new AllDataSheetSearchContext(value);

            searchContext.NextPage   = 1;
            searchContext.TotalPages = totalPages;
            if (option != AllDataSheetSearchContext.SearchOption.Match)
            {
                searchContext.UsedOptions.Add(AllDataSheetSearchContext.SearchOption.Match);
                searchContext.Option = option;
            }
            searchContext.Next(url);

            AllDataSheetSearchResult ret = new AllDataSheetSearchResult();

            ret.Parts         = FilterResults(document);
            ret.SearchContext = searchContext;

            return(ret);
        }
Ejemplo n.º 3
0
        public static AllDataSheetSearchResult Search(AllDataSheetSearchContext searchContext)
        {
            if (!searchContext.CanLoadMore)
            {
                AllDataSheetSearchResult ret = new AllDataSheetSearchResult();
                ret.Parts         = null;
                ret.SearchContext = searchContext;
                return(ret);
            }

            while (true)
            {
                string         url     = $"{SiteAddress}?Searchword={searchContext.SearchValue}&sPage={searchContext.NextPage}&sField={(int)searchContext.Option}";
                HttpWebRequest request = Requests.CreateDefaultRequest(url);
                request.Referer = searchContext.Referer;
                string result = Requests.ReadResponseString(request);

                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(result);

                if (searchContext.NextPage == 1)
                {
                    int totalPages;
                    AllDataSheetSearchContext.SearchOption option;
                    FilterSearchMode(document, out totalPages, out option);
                    searchContext.TotalPages = totalPages;
                    if (searchContext.Option != option)
                    {
                        if (!searchContext.UsedOptions.Contains(searchContext.Option))
                        {
                            searchContext.UsedOptions.Add(searchContext.Option);
                        }
                        searchContext.Option = option;
                    }
                }

                AllDataSheetSearchResult sret = new AllDataSheetSearchResult();
                if (searchContext.UsedOptions.Contains(searchContext.Option))
                {
                    sret.Parts = new List <AllDataSheetPart>();
                    if (searchContext.CanLoadMore)
                    {
                        searchContext.Next(url);
                        continue;
                    }
                }
                else
                {
                    sret.Parts = FilterResults(document);
                }

                sret.SearchContext = searchContext;
                searchContext.Next(url);

                return(sret);
            }
        }
        private async void LoadMoreResults(object param)
        {
            Searching = true;

            try
            {
                ActionsCount++;
                AllDataSheetSearchResult result = await AllDataSheetPart.SearchAsync(m_searchContext);

                m_searchContext = result.SearchContext;
                AddResults(result.Parts);
            }
            catch
            {
                Global.MessageBox(this, Global.GetStringResource("StringSearchError"), MessageBoxExPredefinedButtons.Ok);
            }
            finally
            {
                ActionsCount--;
            }

            Searching = false;
        }
Ejemplo n.º 5
0
        private async void LoadMoreResults(object param)
        {
            Searching = true;

            try
            {
                ActionsCount++;
                AllDataSheetSearchResult result = await AllDataSheetPart.SearchAsync(m_searchContext);
                m_searchContext = result.SearchContext;
                AddResults(result.Parts);
            }
            catch
            {
                Global.MessageBox(this, Global.GetStringResource("StringSearchError"), MessageBoxExPredefinedButtons.Ok);
            }
            finally
            {
                ActionsCount--;
            }

            Searching = false;
        }
Ejemplo n.º 6
0
        private async void Search(object param)
        {
            m_searchResults.Clear();
            m_searchContext = null;
            IsFavouritesMode = false;
            Searching = true;
            m_filteredResults.SortDescriptions.Clear();
            m_filteredResults.Refresh();

            try
            {
                ActionsCount++;
                AllDataSheetSearchResult result = await AllDataSheetPart.SearchAsync(m_searchField);
                m_searchContext = result.SearchContext;
                AddResults(result.Parts);
            }
            catch
            {
                Global.MessageBox(this, Global.GetStringResource("StringSearchError"), MessageBoxExPredefinedButtons.Ok);
            }
            finally
            {
                ActionsCount--;
            }

            Searching = false;
        }
Ejemplo n.º 7
0
 public static Task <AllDataSheetSearchResult> SearchAsync(AllDataSheetSearchContext searchContext)
 {
     return(Task.Run(() => Search(searchContext)));
 }
        public static AllDataSheetSearchResult Search(string value)
        {
            string url = SiteAddress + "?" + "Searchword=" + value + "&sPage=1&sField=4";
            HttpWebRequest request = Requests.CreateDefaultRequest(url);
            string result = Requests.ReadResponseString(request);

            HtmlDocument document = new HtmlDocument();
            document.LoadHtml(result);

            int totalPages;
            AllDataSheetSearchContext.SearchOption option;
            FilterSearchMode(document, out totalPages, out option);

            AllDataSheetSearchContext searchContext = new AllDataSheetSearchContext(value);
            searchContext.NextPage = 1;
            searchContext.TotalPages = totalPages;
            if (option != AllDataSheetSearchContext.SearchOption.Match)
            {
                searchContext.UsedOptions.Add(AllDataSheetSearchContext.SearchOption.Match);
                searchContext.Option = option;
            }
            searchContext.Next(url);

            AllDataSheetSearchResult ret = new AllDataSheetSearchResult();
            ret.Parts = FilterResults(document);
            ret.SearchContext = searchContext;

            return ret;
        }
        private static void FilterSearchMode(HtmlDocument document, out int totalPages, out AllDataSheetSearchContext.SearchOption option)
        {
            var matchingTables = from node in document.DocumentNode.Descendants("table")
                                 where IsAttributeValueLike(node, "width", "95%") && IsAttributeValueLike(node, "border", "0") &&
                                       IsAttributeValueLike(node, "cellpadding", "0") && IsAttributeValueLike(node, "cellspacing", "0") &&
                                       IsAttributeValueLike(node, "class", "main") && IsAttributeValueLike(node, "align", "center")
                                 select node;

            HtmlNode tdNode = matchingTables.ElementAt(1).Element("tr").Element("td");
            List<char> text = tdNode.InnerText.Substring(tdNode.InnerText.LastIndexOf('(')).ToList();
            text.RemoveAll(x => !char.IsDigit(x) && x != '/');
            string pages = string.Concat(text); // current/total
            string[] tokens = pages.Split('/');

            totalPages = int.Parse(tokens[1]);
            string upperInnerText = tdNode.InnerText.ToUpper();
            option = AllDataSheetSearchContext.SearchOption.Match;
            if (upperInnerText.Contains("START")) option = AllDataSheetSearchContext.SearchOption.StartsWith;
            else if (upperInnerText.Contains("END")) option = AllDataSheetSearchContext.SearchOption.EndsWith;
            else if (upperInnerText.Contains("INCLUDED")) option = AllDataSheetSearchContext.SearchOption.Included;
        }
 public static Task<AllDataSheetSearchResult> SearchAsync(AllDataSheetSearchContext searchContext)
 {
     return Task.Run(() => Search(searchContext));
 }
        public static AllDataSheetSearchResult Search(AllDataSheetSearchContext searchContext)
        {
            if (!searchContext.CanLoadMore)
            {
                AllDataSheetSearchResult ret = new AllDataSheetSearchResult();
                ret.Parts = null;
                ret.SearchContext = searchContext;
                return ret;
            }

            while (true)
            {
                string url = SiteAddress + "?" + "Searchword=" + searchContext.SearchValue + "&sPage=" + searchContext.NextPage + "&sField=" + (int)searchContext.Option;
                HttpWebRequest request = Requests.CreateDefaultRequest(url);
                request.Referer = searchContext.Referer;
                string result = Requests.ReadResponseString(request);

                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(result);

                if (searchContext.NextPage == 1)
                {
                    int totalPages;
                    AllDataSheetSearchContext.SearchOption option;
                    FilterSearchMode(document, out totalPages, out option);
                    searchContext.TotalPages = totalPages;
                    if (searchContext.Option != option)
                    {
                        if (!searchContext.UsedOptions.Contains(searchContext.Option)) searchContext.UsedOptions.Add(searchContext.Option);
                        searchContext.Option = option;
                    }
                }

                AllDataSheetSearchResult sret = new AllDataSheetSearchResult();
                if (searchContext.UsedOptions.Contains(searchContext.Option))
                {
                    sret.Parts = new List<AllDataSheetPart>();
                    if (searchContext.CanLoadMore)
                    {
                        searchContext.Next(url);
                        continue;
                    }
                }
                else
                {
                    sret.Parts = FilterResults(document);
                }

                sret.SearchContext = searchContext;
                searchContext.Next(url);

                return sret;
            }
        }