Example #1
0
 static void GlobalEventsLogException(object sender, System.Threading.ThreadExceptionEventArgs e)
 {
     AnalyticsMonitor.OnThreadException(e.Exception);
 }
Example #2
0
        string GetResultHtml(Result result, double indent)
        {
            StringBuilder htmlString = new StringBuilder();

            if (result.Error == null || result.ResultNotFound)
            {
                if (!string.IsNullOrEmpty(result.EditArticleUrl))
                {
                    string link_f = "<a href=\"{0}\" title=\"{0}\">{1} \"{2}\"</a><br><br>";
                    htmlString.AppendFormat(link_f, result.EditArticleUrl,
                                            result.ResultNotFound ?
                                            LangPack.TranslateString("Create article") :
                                            LangPack.TranslateString("Open article"),
                                            result.Phrase);
                }
            }

            if (result.Error == null)
            {
                if (result.Childs.Count != 0)
                {
                    //we has childs list
                    if (result.Translations.Count > 0 && !string.IsNullOrEmpty(result.Translations[0]))
                    {
                        htmlString.AppendFormat("<b>{0}</b>  ",
                                                HttpUtility.HtmlEncode(result.Translations[0]));
                    }

                    if (!string.IsNullOrEmpty(result.Abbreviation))
                    {
                        htmlString.Append(" " + HttpUtility.HtmlEncode(result.Abbreviation) + " ");
                    }

                    if (result.Translations.Count > 0 || !string.IsNullOrEmpty(result.Abbreviation))
                    {
                        htmlString.Append("<br>");
                    }

                    foreach (Result child in result.Childs)
                    {
                        if (/*r.Phrase != result.Phrase && */ !string.IsNullOrEmpty(child.Phrase))
                        {
                            if (!child.Phrase.StartsWith("html!"))
                            {
                                if (indent != 0)
                                {
                                    htmlString.Append(GetParagraphFormat(indent, result));
                                }

                                if (string.IsNullOrEmpty(child.ArticleUrl))
                                {
                                    htmlString.AppendFormat("<b>{0}</b> ",
                                                            HttpUtility.HtmlEncode(child.Phrase.Replace('\u00A0', ' ')));
                                }
                                else
                                {                                 //integrate url
                                    string icon = "";
                                    if (child.HasAudio)
                                    {
                                        icon = " " + string.Format(HtmlHelper.IconOfAudioFormat,
                                                                   LangPack.TranslateString("Pronunciation"));
                                    }
                                    htmlString.AppendFormat("<a href=\"{0}\" title=\"{0}\"><b>{1}</b>{2}</a> ",
                                                            child.ArticleUrl,
                                                            HttpUtility.HtmlEncode(child.Phrase.Replace('\u00A0', ' ')),
                                                            icon);
                                }
                                if (indent != 0)
                                {
                                    htmlString.Append("</p>");
                                }
                            }
                            else
                            {                              //append html directly
                                htmlString.Append(child.Phrase.Substring(5));
                            }
                        }

                        if (!string.IsNullOrEmpty(child.Abbreviation) && child.Childs.Count == 0)
                        {
                            htmlString.Append(" " + HttpUtility.HtmlEncode(child.Abbreviation) + " ");
                        }

                        if (/*r.Phrase != result.Phrase && */ indent > 0.5 && (!string.IsNullOrEmpty(child.Phrase) || !string.IsNullOrEmpty(child.Abbreviation)))
                        {
                            htmlString.Append("<br>");
                        }

                        htmlString.AppendFormat("{0}",
                                                GetResultHtml(child, indent + 0.5));
                    }
                    return(htmlString.ToString());
                }

                if (result.Parent == null)
                {                 //abreviations
                    if (!string.IsNullOrEmpty(result.Abbreviation))
                    {
                        htmlString.Append(" " + HttpUtility.HtmlEncode(result.Abbreviation) + " ");
                    }

                    if (result.Translations.Count > 0 || !string.IsNullOrEmpty(result.Abbreviation))
                    {
                        htmlString.Append("<br>");
                    }
                }
                string topPhrase;
                if (result.Parent != null)
                {
                    topPhrase = result.Parent.Phrase;
                }
                else
                {
                    topPhrase = result.Phrase;
                }
                topPhrase = topPhrase.ToLowerInvariant();

                foreach (string s in result.Translations)
                {
                    if (indent > 0)
                    {
                        htmlString.Append("<li>");
                    }

                    if (!s.StartsWith("html!"))
                    {
                        htmlString.Append(GetParagraphFormat(indent, result));

                        List <string> words = StringParser.SplitToParts(s);

                        foreach (string word in words)
                        {
                            if (string.IsNullOrEmpty(word))
                            {
                                continue;
                            }

                            bool IsDelimiter = false;
                            bool IsError     = word.Length > 1;
                            if (!IsError && word.Length == 1)
                            {
                                IsError     = StringParser.DelimiterCharsList.BinarySearch(word[0]) < 0;
                                IsDelimiter = true;
                            }
                            if (IsError)
                            {
                                IsError = topPhrase.IndexOf(word.ToLowerInvariant()) >= 0;
                            }

                            if (!IsDelimiter)
                            {
                                if (IsError)
                                {
                                    htmlString.AppendFormat("<span style=\"" + HtmlHelper.ErrorTextStyle + "\">{0}</span>", HttpUtility.HtmlEncode(word));
                                }
                                else
                                {
                                    htmlString.Append(HttpUtility.HtmlEncode(word));
                                }
                            }
                            else if (word[0] == '\u00A0')
                            {
                                htmlString.Append(' ');                                 //avoid adding &nbsp;
                            }
                            else if (word[0] == '\n')
                            {
                                htmlString.Append("<br />");
                            }
                            else
                            {
                                htmlString.Append(HttpUtility.HtmlEncode(word));
                            }
                        }
                        htmlString.Append("</p>");
                    }
                    else
                    {                     //append html directly
                        int allowedWidth = (int)((double)wBrowser.Width * .95) - 26;
                        if (vScrollBar.Visible)
                        {
                            allowedWidth += SystemInformation.VerticalScrollBarWidth;
                        }

                        htmlString.Append(s.Substring(5).Replace("{allowed_width}", allowedWidth.ToString()));
                    }

                    if (indent > 0)
                    {
                        htmlString.Append("</li>");
                    }
                }

                //Additional links
                if (result.RelatedLinks.Count > 0)
                {
                    if (indent > 0)
                    {
                        htmlString.Append("<li>");
                    }

                    htmlString.Append(GetParagraphFormat(indent, result));
                    htmlString.Append(LangPack.TranslateString("related links") + " : ");
                    bool first = true;
                    foreach (Link lnk in result.RelatedLinks)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            htmlString.Append(", ");
                        }
                        htmlString.AppendFormat("<a href=\"{0}\" title=\"{0}\">{1}</a>",
                                                lnk.Uri,
                                                HttpUtility.HtmlEncode(lnk.Text.Replace('\u00A0', ' ')));
                    }

                    htmlString.Append("</p>");
                    if (indent > 0)
                    {
                        htmlString.Append("</li>");
                    }
                }
            }
            else
            {
                htmlString.Append(HttpUtility.HtmlEncode(LangPack.TranslateString(result.Error.Message)));
                if (!result.ResultNotFound)
                {
                    string trackMessage = string.Format("Error on translating phrase : {0}, direction : {1}, subject : {2}, service : {3}", result.Phrase, result.LanguagePair.ToString(), result.Subject, result.ServiceItem.FullName);
                    AnalyticsMonitor.OnThreadException(result.Error, trackMessage);
                    Trace.TraceException(result.Error);
                }
            }
            return(htmlString.ToString());
        }