Ejemplo n.º 1
0
        public override void Apply()
        {
            bool changed = IsChanged();

            current.UseEQATECMonitor = rbAllow.Checked;
            if (changed)
            {
                if (TranslateOptions.Instance.UseEQATECMonitor)
                {
                    AnalyticsMonitor.Start();
                }
                else
                {
                    AnalyticsMonitor.Stop();
                }
            }
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            //if(MonoHelper.IsUnix)
            //	Environment.SetEnvironmentVariable ("MONO_BROWSER_ENGINE", "webkit");

            if (CommandLineHelper.IsCommandSwitchSet("gen_list"))
            {
                try
                {
                    WebUI.ResultsWebServer.UnhandledException += OnUnhandledExceptionEvent;
                    WebUI.ResultsWebServer.Start();

                    ServicesListHtmlGenerator.Generate();
                }
                catch (Exception e)
                {
                    Application.OnThreadException(e);
                }
                return;
            }

            try
            {
                Application.ExceptionsLog += GlobalEventsLogException;
                ResultsCache.UseCache      = true;
                GuessResultsCache.UseCache = true;

                UpdatesManager.Init();
                Application.ShowSplashForm(null);

                Application.OptionsForm = new OptionsForm();
                Application.BaseOptions = new TranslateOptions();
                Application.AboutForm   = new AboutForm();

                OptionsControlsManager.RegisterOptionControl(typeof(StartupOptionsControl), "General", 0, "Startup", 1);
                OptionsControlsManager.RegisterOptionControl(typeof(TrayOptionsControl), "General", 0, "Tray", 2);
                OptionsControlsManager.RegisterOptionControl(typeof(ResultWindowOptionControl), "General", 0, "Result view", 3);
                OptionsControlsManager.RegisterOptionControl(typeof(GuesserOptionsControl), "General", 0, "Language detection", 4);

                if (!MonoHelper.IsUnix)                //monobug - don't work with DataSource
                {
                    OptionsControlsManager.RegisterOptionControl(typeof(KeyboardLayoutControl), "General", 0, "Keyboard layouts", 5);
                }


                OptionsControlsManager.RegisterOptionControl(typeof(UpdatesOptionsControl), "General", 0, "Updates", 6);
                OptionsControlsManager.RegisterOptionControl(typeof(HotkeysOptionsControl), "General", 0, "Hotkeys", 7);

                OptionsControlsManager.RegisterOptionControl(typeof(InputFontOptionsControl), "Fonts", 1, "Input text", 0);
                OptionsControlsManager.RegisterOptionControl(typeof(ResultViewFontOptionsControl), "Fonts", 1, "Result view", 1);
                OptionsControlsManager.RegisterOptionControl(typeof(ToolbarsFontOptionsControl), "Fonts", 1, "Toolbars", 2);

                OptionsControlsManager.RegisterOptionControl(typeof(GeneralNetworkOptionsControl), "Network", 2, "Common", 0);

                OptionsControlsManager.RegisterOptionControl(typeof(CustomProfilesControl), "Profiles", 3, "List", 4);
                OptionsControlsManager.RegisterOptionControl(typeof(AnalyticsOptionsControl), "Usage information collecting", 4, "Usage information collecting", 4);

                Application.Initialize();

                if (TranslateOptions.Instance.SingleInstance && ProcessHelper.IsOtherInstanceAlreadyStarted())
                {
                    ProcessHelper.ActivateOtherInstance(ApplicationInfo.ProductName);
                    return;
                }

                UpdatesManager.CheckNewVersion();

                WebUI.ResultsWebServer.UnhandledException += OnUnhandledExceptionEvent;
                try
                {
                    WebUI.ResultsWebServer.Start();
                }
                catch (System.Reflection.TargetInvocationException e)
                {
                    if (e.InnerException != null && e.InnerException.GetType() == typeof(System.Security.VerificationException))
                    {
                        MessageBox.Show(LangPack.TranslateString("Running from network share not supported.\nTool can work only when started from local drive under appropriate user's rights."),
                                        Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        throw;
                    }
                }

                AnalyticsMonitor.Start();
                Application.Run(new TranslateMainForm());
                WebUI.ResultsWebServer.Stop();
            }
            catch (Exception e)
            {
                Application.OnThreadException(e);
            }
        }
Ejemplo n.º 3
0
 static void GlobalEventsLogException(object sender, System.Threading.ThreadExceptionEventArgs e)
 {
     AnalyticsMonitor.OnThreadException(e.Exception);
 }
Ejemplo n.º 4
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());
        }