public string HiLite(object word)
        {
            string marked = string.Empty;

            string original = word.ToString();
            string seq = SearchStr.ToLower();
            marked = original;
            int len = seq.Length;
            string style = "<span class=\"dictionary-partial-match\">";

            if (!BContains)  //only higlight if it begins with sequence 
            {
                if (original.ToLower().StartsWith(seq))
                {
                    marked = marked.Insert(len, "</span>");
                    marked = marked.Insert(0, style);
                }
            }
            else
            {
                int pos = original.ToLower().IndexOf(seq, 0);
                if (pos > -1)
                {
                    marked = marked.Insert(pos + len, "</span>");
                    marked = marked.Insert(pos, style);
                }
            }

            return marked;
        }
Пример #2
0
        /// <summary>
        /// 转义URL字符串为对应的数据
        /// </summary>
        /// <param name="URL">URL string</param>
        /// <param name="IsRouteMode">is simply Route Mode,simply MVG mode</param>
        public void Parse(string URL, Boolean IsRouteMode = false)
        {
            //清空原数据
            Protocol  = "";
            Domain    = "";
            Path      = "";
            File      = "";
            SearchStr = "";
            Anchor    = "";
            URLParam.Clear();
            Is_Route_Mode = Is_Route_Mode || IsRouteMode;

            Regex           regExp;
            MatchCollection matchResult;

            string[] params_T;
            regExp      = new Regex(@"^(?<protocol>(https|http|ftp|file)(:\/{2,4}))?(?<domain>[^\s\/\\]+)?(?<path>[\/][^?#]*)?(?<searchStrOrAnchor>(\?[^#]*))?(?<anchor>#[^#]*)?");
            matchResult = regExp.Matches(URL);
            if (matchResult.Count > 0)
            {
                Protocol  = matchResult[0].Groups["protocol"].Value;
                Domain    = matchResult[0].Groups["domain"].Value;
                Path      = matchResult[0].Groups["path"].Value;
                File      = Path.Substring(Path.LastIndexOf("/") > 0 ? Path.LastIndexOf("/") + 1 : 0);
                Path      = Path.Substring(0, Path.LastIndexOf("/") == Path.Length ? Path.Length + 1 : Path.LastIndexOf("/") + 1);
                SearchStr = matchResult[0].Groups["searchStrOrAnchor"].Value;
                if (SearchStr.Substring(0, 1) == "#")
                {
                    Anchor    = SearchStr;
                    SearchStr = "";
                }
                else
                {
                    Anchor = matchResult[0].Groups["anchor"].Value;
                }
                if (SearchStr != "")
                {
                    params_T = SearchStr.Replace("?", "").Split('&');
                    foreach (var p in params_T)
                    {
                        var tt = p.Split('=');
                        URLParam.Add(tt[0], tt.Length > 1 ? tt[1] : "");
                    }
                }
            }
            Controller = "";
            Method     = "";
            if (Is_Route_Mode)
            {
                string          tSStr = Path;
                Regex           regExp1;
                MatchCollection matchResult1;
                regExp1      = new Regex(@"(?<controller>[^\/]+)\/(?<method>[^\/]+)");
                matchResult1 = regExp1.Matches(tSStr);
                Controller   = matchResult1[0].Groups["controller"].Value;
                Method       = matchResult1[0].Groups["method"].Value;
            }
        }
Пример #3
0
 public void Search(List <string> strings)
 {
     foreach (string s in strings)
     {
         if (s.Contains(StrTemplate))
         {
             SearchStr?.Invoke(s);
         }
     }
 }
        private void LoadData()
        {
            DictionaryAppManager _dictionaryAppManager = new DictionaryAppManager();

            SearchType searchType = SearchType.Begins;
            if (BContains)
                searchType = SearchType.Contains;

            DictionarySearchResultCollection resultCollection = null;

            // Translate page number into offset.
            // One less than the current page number (with sanity check), times the page size
            // translates from a "first page is 1" page number to a "first record is zero" offset into the
            // list of results.
            int offset = ((CurrentPageIndex > 0 ? CurrentPageIndex : 1) - 1) * PageSize;

            if (!String.IsNullOrEmpty(SearchStr)) // SearchString provided, do a term search
            {
                SearchStr = Sanitizer.GetSafeHtmlFragment(SearchStr);
                resultCollection = _dictionaryAppManager.Search(SearchStr, searchType, offset, PageSize, NCI.Web.Dictionary.DictionaryType.drug, PageAssemblyContext.Current.PageAssemblyInstruction.Language);
            }

            if (resultCollection != null && resultCollection.Count() > 0)
            {
                //if there is only 1 record - go directly to definition view
                //check if expand equals "A", as this is the default value
                if (resultCollection.ResultsCount == 1)
                {
                    // Get the first (only) item so we can redirect to it specifically
                    IEnumerator<DictionarySearchResult> itemPtr = resultCollection.GetEnumerator();
                    itemPtr.MoveNext();

                    string urlItem = GetFriendlyName(itemPtr.Current.ID.ToString());

                    string itemDefinitionUrl = this.DictionaryRouter.GetDefinitionUrl() + urlItem;
                    Page.Response.Redirect(itemDefinitionUrl);
                }
                else
                {
                    resultListView.DataSource = resultCollection;
                    resultListView.DataBind();
                    NumResults = resultCollection.ResultsCount;
                    lblWord.Text = SearchStr.Replace("[[]", "[");
                    lblNumResults.Text = NumResults.ToString();
                    if (NumResults == 0)
                    {
                        RenderNoResults();
                    }
                }
            }
            else
            {
                RenderNoResults();
            }
        }
        private void LoadData()
        {
            DictionaryAppManager _dictionaryAppManager = new DictionaryAppManager();

            SearchType searchType = SearchType.Begins;

            if (BContains)
            {
                searchType = SearchType.Contains;
            }

            DictionarySearchResultCollection resultCollection = null;

            if (!String.IsNullOrEmpty(SearchStr)) // SearchString provided, do a term search
            {
                SearchStr = Sanitizer.GetSafeHtmlFragment(SearchStr);

                resultCollection = _dictionaryAppManager.Search(SearchStr, searchType, 0, int.MaxValue, NCI.Web.Dictionary.DictionaryType.term, PageAssemblyContext.Current.PageAssemblyInstruction.Language);
            }

            if (resultCollection != null && resultCollection.Count() > 0)
            {
                //if there is only 1 record - go directly to definition view
                if (resultCollection.ResultsCount == 1)
                {
                    // Get the first (only) item so we can redirect to it specifically
                    IEnumerator <DictionarySearchResult> itemPtr = resultCollection.GetEnumerator();
                    itemPtr.MoveNext();

                    string urlItem = GetFriendlyName(itemPtr.Current.ID.ToString());

                    string itemDefinitionUrl = this.DictionaryRouter.GetDefinitionUrl() + urlItem;

                    Page.Response.Redirect(itemDefinitionUrl);
                }
                else
                {
                    resultListView.DataSource = resultCollection;
                    resultListView.DataBind();
                    NumResults         = resultCollection.ResultsCount;
                    lblWord.Text       = SearchStr.Replace("[[]", "[");
                    lblNumResults.Text = NumResults.ToString();
                    if (NumResults == 0)
                    {
                        RenderNoResults();
                    }
                }
            }
            else
            {
                RenderNoResults();
            }
        }
        /// <summary>
        /// Turn a term's list of aliases into a semi-colon separated list.
        /// </summary>
        /// <param name="word">A DictionarySearchResult object containing a Term data structure.</param>
        /// <returns> A semi-colon separated list of term aliases, enclosed in square brackets.
        /// <remarks>
        /// Only returns those aliases which met the search criteria.
        /// Returns an empty string if an Expand search was performed.</remarks>
        /// </returns>
        public string GetTermAliasList(object termSearchResult)
        {
            string aliases = String.Empty;

            DictionarySearchResult termInfo = termSearchResult as DictionarySearchResult;

            if (termInfo != null      // Don't do this unless there are aliases to list.
                && termInfo.Term.Aliases.Length > 0
            )
            {
                StringBuilder sb = new StringBuilder();

                // Get the original search string, forcing it to be non-null and removing any
                // leading/trailing spaces.
                string searchstr = Strings.Clean(Request.Params["q"]) ?? String.Empty;
                searchstr = SearchStr.Trim().ToLower();

                // Handle the possibility that two alias types might have the same value
                // (e.g. US Brand Name and Foreign Brand Name)
                IEnumerable<Alias> uniqueAliases = termInfo.Term.Aliases.Distinct();

                // Roll up the list of terms.
                foreach (Alias alias in uniqueAliases)
                {
                    if (alias.Name != null)
                    {
                        // Mimic legacy logic for choosing which aliases to display.
                        string name = HiLite(alias.Name.Trim());
                        string compareName = alias.Name.Trim().ToLower();

                        // name contains the search string
                        if (BContains && compareName.Contains(searchstr))
                            sb.AppendFormat("{0}; ", name);
                        // name starts with the search string
                        else if (!BContains && compareName.StartsWith(searchstr))
                            sb.AppendFormat("{0}; ", name);
                        // else -- not a match.
                    }
                }

                // If terms were found, trim off the final semicolon and space before
                // wrapping the whole thing in square brackets.
                aliases = sb.ToString();
                if (!String.IsNullOrEmpty(aliases))
                    aliases = String.Format("[ {0} ]", aliases.TrimEnd(' ', ';'));
            }

            return aliases;
        }
        public async void Search(string method)
        {
            if (method == "search")
            {
                searchOffset = 0;
            }
            else if (method == "searchNext")
            {
                searchOffset += Global.Settings.SearchNum;
            }
            else if (method == "searchPre")
            {
                searchOffset -= Global.Settings.SearchNum;
                if (searchOffset < 0)
                {
                    searchOffset = 0;
                }
            }

            if (SearchStr.IsBlank())
            {
                Growl.Error(Language.Get("strmsgSearchStringIsEmpty"), Global.TOKEN_MAIN);
                return;
            }

            ShowWait = true;

            (string msg, eType type, object data) = await Client.Get(Global.CommonKey, SearchStr, eType.NONE, Global.Settings.SearchNum, Global.Settings.IncludeEP, false, searchOffset);

            if (msg.IsNotBlank() || data == null)
            {
                Growl.Error(Language.Get("strmsgSearchErr") + msg, Global.TOKEN_MAIN);
            }
            else if (type == eType.SEARCH)
            {
                SearchResult = (SearchResult)data;
                ShowDetail   = false;
                ShowList     = true;
            }
            else
            {
                Detail     = Detail.Creat(data, type);
                ShowDetail = true;
                ShowList   = false;
            }

            ShowWait = false;
        }
        public async void Search()
        {
            if (InSearch)
            {
                return;
            }
            if (SearchStr.IsBlank())
            {
                Errlabel = "Search String is Empty!";
                return;
            }

            //Search
            InSearch = true;
            eObjectType SearchType = eObjectType.None;
            object      SearchObj  = await Task.Run(() => { return(TidalTool.tryGet(SearchStr, out SearchType)); });

            InSearch = false;

            if (SearchType == eObjectType.None)
            {
                Errlabel = "Search Err!";
                return;
            }
            if (SearchType == Tidal.eObjectType.SEARCH)
            {
                VMSearch.Load((Tidal.SearchResult)SearchObj);
                Manager.ShowDialog(VMSearch);
                SearchType = VMSearch.ResultType;
                SearchObj  = VMSearch.ResultObject;
                if (SearchType == eObjectType.None)
                {
                    return;
                }
            }

            SearchObj = VMInfo.Load(SearchObj);
            Manager.ShowDialog(VMInfo);
            if (VMInfo.Result)
            {
                MainListItemViewModel newNode = new MainListItemViewModel(SearchObj, ItemList);
                ItemList.Add(newNode);
                newNode.StartWork();
            }
        }
        /// <summary>
        /// Search Func
        /// </summary>
        public void Search()
        {
            Errlabel = "";
            if (SearchStr.IsBlank())
            {
                Errlabel = "Search String is Err!";
            }
            if (SearchTread != null)
            {
                Errlabel = "Somethig is in Searching!";
            }
            if (Errlabel.IsNotBlank())
            {
                ShowErrlabel = true;
                return;
            }

            SearchTread = ThreadHelper.Start(ThreadFuncSearch);
            ShowWaitView(ThreadSearchClose);
        }
Пример #10
0
        /// <summary>
        /// 传入一个URL参数,若该参数的key存在,则 覆盖为新值,若不存在,将会新增加一个URl参数
        /// Pass into and set one urlparam,if the key exist,it's value will be covered,else if not exist,it (contains key and value) will be created
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public Boolean setParam(string key, string value)
        {
            key   = HttpUtility.UrlEncode(key);
            value = HttpUtility.UrlEncode(value);
            if (URLParam.ContainsKey(key))
            {
                URLParam[key] = value;
            }
            else
            {
                URLParam.Add(key, value);
            }
            SearchStr = "?";
            foreach (var item in URLParam)
            {
                SearchStr += item.Key + "=" + item.Value + "&";
            }

            if (SearchStr.LastIndexOf("&") == SearchStr.Length - 1)
            {
                SearchStr = SearchStr.Substring(0, SearchStr.Length - 1);
            }
            return(true);
        }
Пример #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            GetQueryParams();
            SetupCanonicalUrl(this.DictionaryRouter.GetBaseURL());
            SetDoNotIndex();

            if (!string.IsNullOrEmpty(SrcGroup))
            {
                BContains = Convert.ToBoolean(SrcGroup);
            }

            this.dictionarySearchBlock.SearchBoxInputVal = HttpUtility.HtmlEncode(SearchStr);

            if (BContains == true)
            {
                this.dictionarySearchBlock.CheckRadioStarts   = "";
                this.dictionarySearchBlock.CheckRadioContains = "checked=\"checked\"";
            }

            //For Genetics dictionary language is always English
            DictionaryLanguage = "en";

            DictionarySearchResultCollection resultCollection      = null;
            DictionaryAppManager             _dictionaryAppManager = new DictionaryAppManager();

            SearchType searchType = SearchType.Begins;

            if (BContains)
            {
                searchType = SearchType.Contains;
            }

            if (!String.IsNullOrEmpty(SearchStr)) // SearchString provided, do a term search
            {
                SearchStr        = Sanitizer.GetSafeHtmlFragment(SearchStr);
                resultCollection = _dictionaryAppManager.Search(SearchStr, searchType, 0, int.MaxValue, NCI.Web.Dictionary.DictionaryType.genetic, DictionaryLanguage);
            }

            if (resultCollection != null && resultCollection.Count() > 0)
            {
                //if there is only 1 record - go directly to definition view
                if (resultCollection.ResultsCount == 1)
                {
                    // Get the first (only) item so we can redirect to it specifically
                    IEnumerator <DictionarySearchResult> itemPtr = resultCollection.GetEnumerator();
                    itemPtr.MoveNext();

                    string urlItem = GetFriendlyName(itemPtr.Current.ID.ToString());

                    string itemDefinitionUrl = this.DictionaryRouter.GetDefinitionUrl() + urlItem;
                    Page.Response.Redirect(itemDefinitionUrl);
                }
                else
                {
                    resultListView.DataSource = resultCollection;
                    resultListView.DataBind();
                    NumResults = resultCollection.ResultsCount;
                    if (!string.IsNullOrEmpty(SearchStr))
                    {
                        lblWord.Text = SearchStr.Replace("[[]", "[");
                    }
                    lblNumResults.Text = NumResults.ToString();
                    if (NumResults == 0)
                    {
                        RenderNoResults();
                    }
                }
            }
            else
            {
                RenderNoResults();
            }
        }