BzReader.BrowseForm.Web_UrlRequested C# (CSharp) Метод

Web_UrlRequested() приватный Метод

Gets called whenever the browser control requests a URL from the web server
private Web_UrlRequested ( object sender, UrlRequestedEventArgs e ) : void
sender object Web server instance
e UrlRequestedEventArgs Request parameters
Результат void
        private void Web_UrlRequested(object sender, UrlRequestedEventArgs e)
        {
            string response = "Not found";
            string redirect = String.Empty;

            if (!String.IsNullOrEmpty(e.TeXEquation))
            {
                return;
            }

            string topic = e.TopicName.Replace('_', ' ').Trim();

            if (topic.Contains("#"))
            {
                topic = topic.Substring(0, topic.IndexOf('#')).Trim();
            }

            PageInfo page = hitsBox.SelectedItem as PageInfo;

            if (page != null &&
                topic.Equals(page.Name, StringComparison.InvariantCultureIgnoreCase) &&
                e.IndexName.Equals(page.Indexer.File, StringComparison.InvariantCultureIgnoreCase) &&
                !IsCircularRedirect(page))
            {
                response = page.GetFormattedContent();
                redirect = page.RedirectToTopic;
            }
            else
            {
                List<Indexer> searchArea = new List<Indexer>();

                // This is an internal link

                if (String.IsNullOrEmpty(e.IndexName))
                {
                    if (page != null)
                    {
                        searchArea.Add(page.Indexer);
                    }
                    else
                    {
                        foreach (Indexer ixr in indexes.Values)
                        {
                            searchArea.Add(ixr);
                        }
                    }
                }
                else
                {
                    foreach (Indexer ixr in indexes.Values)
                    {
                        if (ixr.File.Equals(e.IndexName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            searchArea.Add(ixr);

                            break;
                        }
                    }
                }

                if (searchArea.Count > 0)
                {
                    HitCollection hits = Indexer.Search(topic, searchArea, 100);

                    bool exactTopicLocated = false;

                    foreach (PageInfo pi in hits)
                    {
                        if (pi.Name.Trim().Equals(topic, StringComparison.InvariantCultureIgnoreCase) &&
                            !IsCircularRedirect(pi))
                        {
                            response = pi.GetFormattedContent();
                            redirect = pi.RedirectToTopic;

                            exactTopicLocated = true;

                            break;
                        }
                    }

                    if (hits.Count > 0 &&
                        !exactTopicLocated)
                    {
                        foreach (PageInfo pi in hits)
                        {
                            if (String.IsNullOrEmpty(pi.RedirectToTopic))
                            {
                                response = pi.GetFormattedContent();
                                redirect = pi.RedirectToTopic;

                                exactTopicLocated = true;

                                break;
                            }
                        }

                        if (!exactTopicLocated)
                        {
                            foreach (PageInfo pi in hits)
                            {
                                if (!IsCircularRedirect(pi))
                                {
                                    response = pi.GetFormattedContent();
                                    redirect = pi.RedirectToTopic;

                                    break;
                                }
                            }
                        }
                    }
                }
            }

            e.Redirect = !String.IsNullOrEmpty(redirect);
            e.RedirectTarget = redirect;
            e.Response = Encoding.UTF8.GetBytes(response);
            e.MimeType = "text/html";

            if (String.IsNullOrEmpty(redirect))
            {
                autoRedirects.Clear();
            }
            else
            {
                autoRedirects.Push(redirect);
            }
        }