public ProcessorForTranslate(Sentence sentence, string word, string masked, string codeFrom, string codeTo, WaitingUIObjectWithFinish waitingUiObject) { m_word = word; m_maskedWord = masked; Sentence = sentence; m_codeTo = codeTo; m_codeFrom = codeFrom; this.waitingUiObject = waitingUiObject; Thread thread = new Thread(new ThreadStart(TranslateCurrentSentence)); thread.Name = string.Format("TranslateCurrentSentence or '{0}'", word); thread.Start(); }
public AsyncProvider(string text, LangPair langPair, DictionaryProvider provider, WaitingUIObjectWithFinish waitingUiObject, Dictionary <string, string> containerCollection, string keyForResult) { m_text = text; m_langPair = langPair; m_provider = provider; m_waitingUiObject = waitingUiObject; m_containerCollection = containerCollection; m_keyForResult = keyForResult; this.m_thread = new Thread(new ThreadStart(Translate)); this.m_thread.Name = string.Format("Getting from: '{0}' data: '{1}'", provider.Title, text); if (provider.IsDoFullLoading) { this.m_thread.SetApartmentState(ApartmentState.STA); } this.m_thread.Start(); }
void CallTranslate(string word, string maskedText) { // word maybe equal null this.translatedText.AssignText(""); // возможно уже и ожидание надо включать?? //if (updateTranslatedText == null) updateTranslatedText = new MethodInvoker(delegate { AssignTransatedText(this.Sentence); }); if (waitObject == null) { waitObject = new WaitingUIObjectWithFinish(this, this.pictureBoxWating, updateTranslatedText); } new ProcessorForTranslate( this.Sentence, word, maskedText, this.LangDir.From, this.LangDir.To, waitObject); }
//private void btSearch_Click(object sender, EventArgs e) //{ // DoSearching(); //} private void DoSearching() { ToolStripItem lastDictionary = this.LastUsedDict; if (lastDictionary != null) { //this.pictureBoxWating.Visible = true; //MethodDelegate md = new MethodDelegate(DictCollection.Dict_Click); //this.BeginInvoke(md, lastDictionary, EventArgs.Empty); DictCollection.Dict_Click(lastDictionary, EventArgs.Empty); } else { // DictCollection.Dict_Click(lastDictionary, EventArgs.Empty); string[] langPairs = LangDirection.Split(CurrentLangInfo.PairSeparator); WaitingUIObjectWithFinish waitingUIObject = new WaitingUIObjectWithFinish(this, this.pictureBoxWating, null); new Gator.GatorStarter(this.Word, langPairs[0], langPairs[1], waitingUIObject); // bool f = (new Gator()).ShowArticles(this.Word, langPairs[0], langPairs[1], this); } OnAfterSearchClick(); }
// "<table><tr><td class=\"topForArticle\"><a href=\"{0}\" title=\"{1}\">{2} ({3})</a></td></tr></table>"; /* * .topForArticle * { * background-color: #C0C0C0; padding-right: 50px; padding-left: 50px; * } * * static readonly string TopForArticleTemplate = "{0}\r\n<table><tr>{0}</tr></table>\r\n"; */ #endregion public static void Dict_Click(object sender, EventArgs e) { RunDictContent dictContent = ((ToolStripItem)sender).Tag as RunDictContent; if (dictContent == null) { return; } string word = dictContent.TextWithSelection.CurrentLowerWord; if (string.IsNullOrEmpty(word)) { string message = "A word is not specified"; // if (Application.ProductName == DictionaryBlend message += " (Drag-n-drop supported)." // "You must type a word MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { LangPair lp = dictContent.TextWithSelection.LangDir; if (dictContent.UITarget != null) { #region for async calling WaitingUIObjectWithFinish waitObject = null; //if ((dictContent.Providers.Count == 1) && !(dictContent.Providers[0] is FavoritProvider)) if (dictContent.TextWithSelection is ITextWithSelectionAndWaiting) { MethodInvoker onFinish = new MethodInvoker(AssignTextToControl); waitObject = new WaitingUIObjectWithFinish(((ITextWithSelectionAndWaiting)dictContent.TextWithSelection).Control, ((ITextWithSelectionAndWaiting)dictContent.TextWithSelection).Picture, onFinish); lastUITarget = dictContent.UITarget; foreach (AsyncProvider provider in currentRequests) { if (provider.CurrentThread.IsAlive) { provider.CurrentThread.Abort(); } } currentRequests.Clear(); lock (resultContainer) resultContainer.Clear(); } #endregion using (new WaitCursor(waitObject == null)) { // System.Threading.Thread.Sleep(3000); string dictBodies = ""; foreach (DictionaryProvider provider in dictContent.Providers) { //if (provider is FavoritProvider) //{ // new Gator.GatorStarter(word, lp.From, lp.To, null); // waitingUIObject // dictBodies = "See result in an external window"; //} //else { if (!provider.IsSupport(lp.ToString())) { continue; } string url = provider.GetPublicUrl(word, lp); string providerTitle = provider.Title; if (provider.GetType().Name.ToLower().Contains("google")) { providerTitle = "Google " + providerTitle; } string title = string.Format(topForArticleTemplate, url, providerTitle, provider.Copyright); if (waitObject != null) { currentRequests.Add(new AsyncProvider(word, lp, provider, waitObject, resultContainer, title)); } else { dictBodies += title; string content = provider.GetContent(word, lp); dictBodies += content; } } } if (waitObject == null) { dictContent.UITarget.TempContent = dictBodies; } dictContent.UITarget.AssignText(dictBodies); } } else // here just working with urls and external browser { #region Runner.OpenURL foreach (DictionaryProvider provider in dictContent.Providers) { if (provider is FavoritProvider) { new Gator.GatorStarter(word, lp.From, lp.To, null); // waitingUIObject } else { if (!provider.IsSupport(lp.ToString())) { continue; } Runner.OpenURL(provider.GetPublicUrl(word, lp)); } } #endregion } } }