Esempio n. 1
0
        internal AsyncTranslateState(
            LanguagePair languagePair,
            ReadOnlyServiceSettingCollection translatorsSettings,
            string phrase,
            AsyncOperation asyncOp,
            EventHandler <TranslateProgressChangedEventArgs> progressChangedHandler,
            EventHandler <TranslateCompletedEventArgs> translateCompletedHandler)
        {
            if (translatorsSettings == null)
            {
                throw new ArgumentNullException("translatorsSettings");
            }

            this.phrase              = phrase;
            this.asyncOperation      = asyncOp;
            this.translatorsSettings = translatorsSettings;
            this.languagePair        = languagePair;
            count = translatorsSettings.Count;

            ProgressChanged    += progressChangedHandler;
            TranslateCompleted += translateCompletedHandler;
        }
Esempio n. 2
0
        public static AsyncTranslateState TranslateAsync(LanguagePair languagePair, string phrase, ReadOnlyServiceSettingCollection translatorsSettings, EventHandler <TranslateProgressChangedEventArgs> progressChangedHandler, EventHandler <TranslateCompletedEventArgs> translateCompletedHandler)
        {
            AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(DateTime.Now.Ticks);

            AsyncTranslateState state = new AsyncTranslateState(languagePair, translatorsSettings, phrase, asyncOp, progressChangedHandler, translateCompletedHandler);

            state.Run();

            return(state);
        }
Esempio n. 3
0
        void LoadServices(bool phraseChanged)
        {
            if (selection == null || ignoreServicesLoading)
            {
                return;
            }
            if (serviceItemsSettings == null || !phraseChanged)
            {
                lock (serviceItemsContainers)
                {
                    serviceItemsSettings = profile.GetServiceSettings(phrase, selection);
                    lvServicesEnabled.Items.Clear();
                    lvServicesDisabled.Items.Clear();
                    lvServicesDisabledByUser.Items.Clear();
                    serviceItemsContainers.Clear();
                    enabledLVItems.Clear();
                    disabledLVItems.Clear();
                    disabledByUserLVItems.Clear();
                    bool showLanguage = selection.From == Language.Any || selection.To == Language.Any;
                    foreach (ServiceItemSetting ss in serviceItemsSettings)
                    {
                        ServiceSettingsContainer sc = new ServiceSettingsContainer(ss, showLanguage);
                        sc.DisabledByUser = !profile.IsServiceEnabled(ss.ServiceItem.FullName, ss.LanguagePair, ss.Subject);
                        serviceItemsContainers.Add(sc);
                    }
                }
            }

            try
            {
                tpServices.SuspendLayout();
                lvServicesEnabled.SuspendLayout();
                lvServicesEnabled.BeginUpdate();
                lvServicesDisabled.SuspendLayout();
                lvServicesDisabled.BeginUpdate();
                lvServicesDisabledByUser.SuspendLayout();
                lvServicesDisabledByUser.BeginUpdate();

                lvServicesEnabled.FocusedItem        = null;
                lvServicesDisabled.FocusedItem       = null;
                lvServicesDisabledByUser.FocusedItem = null;

                lock (serviceItemsContainers)
                {
                    PrepareAddingServicesBatch();
                    foreach (ServiceSettingsContainer sc in serviceItemsContainers)
                    {
                        AddListViewItem(sc, true);
                    }
                    ApplyAddingServicesBatch();
                }
                CalcServicesSizes();
                try
                {                 //try to avoid unrepeatable bug
                    if (lvServicesEnabled.Items.Count > 0)
                    {
                        lvServicesEnabled.Items[0].Focused  = true;
                        lvServicesEnabled.Items[0].Selected = true;
                    }
                    else if (lvServicesDisabled.Items.Count > 0)
                    {
                        lvServicesDisabled.Items[0].Focused  = true;
                        lvServicesDisabled.Items[0].Selected = true;
                    }
                    else if (lvServicesDisabledByUser.Items.Count > 0)
                    {
                        lvServicesDisabledByUser.Items[0].Focused  = true;
                        lvServicesDisabledByUser.Items[0].Selected = true;
                    }
                }
                catch
                {
                    try
                    {
                        if (lvServicesEnabled.Items.Count > 0)
                        {
                            lvServicesEnabled.Items[0].Focused  = true;
                            lvServicesEnabled.Items[0].Selected = true;
                        }
                        else if (lvServicesDisabled.Items.Count > 0)
                        {
                            lvServicesDisabled.Items[0].Focused  = true;
                            lvServicesDisabled.Items[0].Selected = true;
                        }
                        else if (lvServicesDisabledByUser.Items.Count > 0)
                        {
                            lvServicesDisabledByUser.Items[0].Focused  = true;
                            lvServicesDisabledByUser.Items[0].Selected = true;
                        }
                    }
                    catch
                    {
                    }
                }
            }
            finally
            {
                lvServicesEnabled.EndUpdate();
                lvServicesEnabled.ResumeLayout();
                lvServicesDisabled.EndUpdate();
                lvServicesDisabled.ResumeLayout();
                lvServicesDisabledByUser.EndUpdate();
                lvServicesDisabledByUser.ResumeLayout();
                tpServices.ResumeLayout();
                Refresh();
            }
        }
Esempio n. 4
0
        string BuildQuery(string phrase, ReadOnlyServiceSettingCollection settings, ReadOnlyResultCollection results)
        {
            if (phrase == null || settings == null)
            {
                return("");
            }
            else
            {
                string result;

                if (wBrowser.Width > 740)
                {
                    result = "w=728&h=90";
                }
                else if (wBrowser.Width > 480)
                {
                    result = "w=468&h=60";
                }
                else if (wBrowser.Width > 246)
                {
                    result = "w=234&h=60";
                }
                else if (wBrowser.Width > 137)
                {
                    result = "w=125&h=125";
                }
                else
                {
                    return(null);
                }

                //selecting words from query and result
                List <string> phrasewords = StringParser.SplitToParts(phrase.Replace("́", ""));
                int           count       = ExtractAdWords(phrasewords, 25);

                string resultstr = "";
                foreach (Result r in results)
                {
                    resultstr += GetResultString(r);
                }

                List <string> resultwords = StringParser.SplitToParts(resultstr.Replace("́", ""));
                count = ExtractAdWords(resultwords, 60 - count);

                if (phrasewords.Count + resultwords.Count == 0)
                {
                    return(null);
                }

                string phraseStr = "";
                foreach (string s in resultwords)
                {
                    phraseStr += s + " ";
                }

                foreach (string s in phrasewords)
                {
                    if (!resultwords.Contains(s))
                    {
                        phraseStr += s + " ";
                    }
                }

                phraseStr = phraseStr.Substring(0, phraseStr.Length - 1);

                result += "&s=" + HttpUtility.UrlEncode(phraseStr);

                List <string> subjects = new List <string>();
                foreach (ServiceItemSetting ss in settings)
                {
                    if (ss.Subject != SubjectConstants.Common && !subjects.Contains(ss.Subject))
                    {
                        subjects.Add(ss.Subject);
                    }
                }

                int idx = 0;
                foreach (string sub in subjects)
                {
                    result += "&sub" + idx.ToString(CultureInfo.InvariantCulture) + "=" + HttpUtility.UrlEncode(sub);
                    idx++;
                }
                return(result);
            }
        }