private void btSearch_Click(object sender, EventArgs e) { ToolStripButton lastDictionary = null; foreach (ToolStripItem item in toolStripDictionary.Items) { if ((item is ToolStripButton) && ((ToolStripButton)item).Checked) { lastDictionary = (ToolStripButton)item; } } if (lastDictionary != null) { DictCollection.miDict_Click(lastDictionary, EventArgs.Empty); } else // using (WaitCursor wc = new WaitCursor()) { string[] langPairs = LangPair.Split(CurrentLangInfo.PairSeparator); new Gator.GatorStarter(this.Word, langPairs[0], langPairs[1], waitingUIObject); // bool f = (new Gator()).ShowArticles(this.Word, langPairs[0], langPairs[1], this); RegisterEvent(); } }
public override string GetUrl(string word, LangPair langPair) { if (langPair.From == "de") { return(base.GetUrl(word, LangPair.Revert(langPair))); } return(base.GetUrl(word, langPair)); }
public virtual string GetUrl(string word, LangPair langPair) { if (string.IsNullOrEmpty(word)) { return(""); } word = PrepareWord(word); return(string.Format(this.URL, word, langPair.From, langPair.To)); }
public override string GetUrl(string word, LangPair langPair) { if (string.IsNullOrEmpty(word)) { return(""); } word = PrepareWord(word); return(base.GetUrl(word, new LangPair(GetLangCode(langPair.From), GetLangCode(langPair.To)))); }
//DelegateSetTipArticle invoker; public Starter(string word, LangPair lp) // , DelegateSetTipArticle invoker) { this.word = word; this.lp = lp; //this.invoker = invoker; // Execute(); TipHelper.Instance.CurrentThread = new Thread(new ThreadStart(Execute)); TipHelper.Instance.CurrentThread.Name = string.Format("{0} - {1}", this.word, lp); TipHelper.Instance.CurrentThread.Start(); }
void UpdateAfterChangeLanguageDirection(string languageDirection) { ClearCash(); LangPair lp = new LangPair(LanguageDirection); this.TwinText.SetUpLangDir = lp; // here called autoUpdate //this.TwinText.textWithTranslate.ForeignText.Text = ""; //this.TwinText.textWithTranslate.Sentence = this.TwinList.ListEn.CurrentSentence; // this.RefreshSelectedSentence(); }
public override string GetPublicUrl(string word, LangPair langPair) { // TODO: разный перевод при наличии переноса строки //Jersey? Do you have any idea what the traffic 's gonna be like ? //Jersey ? Do you have //any idea what the traffic's gonna be like ? // full version string url = @"http://translate.google.com/translate_a/t?client=t&text=%0A{0}&hl={1}&sl=auto&tl={2}&multires=1&prev=btn&ssel=0&tsel=0&uptl={2}&sc=1"; string url = @"http://translate.google.com/#{1}|{2}|{0}%0A"; return(string.Format(url, word, langPair.From, langPair.To)); }
public override string GetUrl(string word, LangPair langPair) { if (string.IsNullOrEmpty(word)) { return(""); } word = PrepareWord(word); string newWord = word.Replace(" ", "-"); newWord = newWord[0] + "/" + newWord; return(string.Format(this.URL, newWord, langPair.From)); }
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(); }
public override string GetUrl(string word, LangPair langPair) { return(word); }
public override string GetUrl(string word, LangPair langPair) { return(string.Format(this.URL, word, langPair.From, langPair.To)); }
public void PopupDictionaryArticle(TipTextBox sender, Point point, int charIndexUnderCursor) { //Console.WriteLine("!"); //word = GetClearWordValue(word); string word = sender.GetStringUnderCursor(charIndexUnderCursor, ref this.currentMaskedWord); if (string.IsNullOrEmpty(word)) { return; } this.currentPoint = point; this.currentSender = sender; if (word.Equals(this.currentWord)) { if ((CurrentThread != null && CurrentThread.IsAlive)) { return; } else // if(!this.toolTip.Active) // is showed { this.TipArticleCallBack = this.TipArticleCallBack; if (debugInfo) { Console.WriteLine("Recall"); } return; } } if (this.TipArticleCallBack != null) { lock (this.TipArticleCallBack) { if (CurrentThread != null && CurrentThread.IsAlive) { if (debugInfo) { Console.WriteLine("Abort " + CurrentThread.Name); } CurrentThread.Abort(); } } } else // be made only once { if (CurrentThread != null && CurrentThread.IsAlive) { if (debugInfo) { Console.WriteLine("First Abort " + CurrentThread.Name); } CurrentThread.Abort(); } } if (debugInfo) { Console.WriteLine("GetInfo for: " + word); } this.currentWord = word; LangPair lp = sender.LangDir; if (lp.From.Equals(lp.To) || sender.IsMonoRegim) { GoogleMonoDictionary monoDict = new GoogleMonoDictionary(); // TODO: здесь приходит HTML возможно надо свое окно а не парсинг //if ( Array.IndexOf(monoDict.Languages, this.LangDir.From) != -1 ) //{ // string article = monoDict.GetContent(word, this.LangDir); // tipArticle = GoogleTipDictionary.GetTipArticle(word, article); //} //else TipHelper.Instance.TipArticleCallBack = new GoogleTipDictionary.TipArticle(string.Format("Mono dictionary for '{0}' is not supported", lp), " "); //tipArticle = new GoogleTipDictionary.TipArticle(string.Format("Change language pair '{0}'", LangDir), " "); } else { new Starter(this.currentWord, lp); //, new DelegateSetTipArticle(SetTipArticle)); } }
public override string GetUrl(string word, LangPair langPair) { string convertedWord = System.Web.HttpUtility.UrlEncode(word, System.Text.Encoding.Default); return(base.GetUrl(convertedWord, langPair)); }
public virtual string GetContent(string word, string codeForm, string codeTo) { m_ExceptionMessage = ""; if (string.IsNullOrEmpty(word)) { return(string.Empty); } this.ResetLastResultFromResponse(); LangPair lp = new LangPair(codeForm, codeTo); // TODO: некрасивый дизайн string _acceptedLanguageCode = GetContainsSourceLanguage(lp.ToString()); if (string.IsNullOrEmpty(_acceptedLanguageCode)) // проверка поддержки языка { return(""); // язык не поддерживается } string url = this.GetUrl(word, lp); //TODO: если пользователь меняет конфигурацию словарей то надо сбросить //TODO: историю для текстов храним?? может по ключу текста определятся)) if (history.ContainsKey(word + _acceptedLanguageCode)) { m_LastResultFromResponse = new ResultFromResponse(url, _acceptedLanguageCode, history[word + _acceptedLanguageCode]); return(history[word + _acceptedLanguageCode]); } string response = ""; if (IsDoFullLoading) { response = DoAddLoading(url); } else { #region Getting response #region request HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Proxy = null; request.UserAgent = "Mozilla/5"; // "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 GTB7.1 ( .NET CLR 3.5.30729; .NET4.0E) GTBA" ///////////////////////////////////////// // headers test for www.euronews.com //request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1920.0 Safari/537.36"; //request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; //request.Headers.Add("Accept-Encoding", "gzip,deflate,sdch"); //request.Headers.Add("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4"); //request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.Default); // "Cache-Control", "max-age=0"; //request.Headers.Add("Cache-Control", "max-age=0"); //request.KeepAlive = true; //request.Connection = "Keep-alive"; ////string raw = "__gads=ID=63ac347ea76af89f:T=1395648872:S=ALNI_MaprzlJGOpP_i-K7nBBgJlgGyBpyg; EN_meteo_fc=C; EN_textSize=1; __atuvc=5%7C13%2C3%7C14"; ////string rawAr = raw.Split('=', ';'); //Uri target = new Uri("http://euronews.com/"); //request.CookieContainer = new CookieContainer(); //request.CookieContainer.Add(new Cookie("__gads", "ID=63ac347ea76af89f:T=1395648872:S=ALNI_MaprzlJGOpP_i-K7nBBgJlgGyBpyg") { Domain = target.Host }); //request.CookieContainer.Add(new Cookie("EN_meteo_fc", "C") { Domain = target.Host }); //request.CookieContainer.Add(new Cookie("EN_textSize", "1") { Domain = target.Host }); //request.CookieContainer.Add(new Cookie("__atuvc", "5%7C13%2C3%7C14") { Domain = target.Host }); //request.Host = "euronews.com"; ///////////////////////////////////////// // request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; // request.Headers.Add("Accept-Language", "en-us,en;q=0.5"); // request.Headers.Add("Accept-Encoding", "gzip,deflate"); // request.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); // request.Headers.Add("Cookie", "PREF=ID=e0d94a24a2fa9cc4:U=1c449fa392bc9632:TB=2:TM=1267174677:LM=1273649640:DV=8atQZBunt08B:GM=1:S=x8X2uigJVBwIPI8s; NID=34=B0FfFFFonIaztkSsAmNGRUc2d_zPSqDjWdTKuaQgtMO4v7jmGspcZB0SyUq8sjyCSzzdPeB8T9YeCoUXAn1gkqNecV5TheVtz7gBdH7QHCAU8r6g6H1xV4sNqo9oe-UT; rememberme=true; SID=DQAAAKUAAADbnRqRs2S1NuzS-DqVUTlfDNQUAGZmdptrFk_TtFGpcndN1-wH_J04MBexODkaLHgoJItKux_SIuL4xdCmYZ4PkG_hMSGA9I1u9aiIDP0BVejn5_rXhP6tLrK20SXoFrs2icfy-M3B-nwmhcQpzrSKAC9joJu3E36zvgbrokwZhHMr2oe7Jb2GzfvRb5dXilY0uw67CVTBS8vQtLw1qLPoKu99bi3lZGuXv7LSbTWn-g; HSID=Ap1PAdWAwDLJcgF58; S=indic-transliteration=eE3u86HcynSHRqj7jy_xdg"); // for multitran //request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"; //request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; //request.Headers.Add("Accept-Language", "en-us,en;q=0.5"); //request.Headers.Add("Accept-Encoding", "gzip,deflate"); //request.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); //request.Headers.Add("Keep-Alive", " 115"); //request.Headers.Add("Cookie", " langs=2 1"); #endregion #region Gets a Stream object to use to write request data if (this.RequestParameters.Length > 0 && !this.URL.Contains("{0}")) // && this.StartTag == string.Empty) { request.Method = "POST"; Stream newStream = request.GetRequestStream(); Encoding encoding = new ASCIIEncoding(); // string encodingName = "koi8-r windows-1251"; // string encodingName = Encoding.UTF8; string encodingName = "ISO-8859-1"; encoding = System.Text.Encoding.GetEncoding(encodingName, new EncoderReplacementFallback("(unknown)"), new DecoderReplacementFallback("(error)")); encoding = Encoding.Default; // Console.WriteLine("Request with EncodingName: " + encoding.EncodingName + " CodePage: " + encoding.CodePage); byte[] byte1; //byte1 = encoding.GetBytes("security_token=" + "AKrFfvIEjIbGcYBjuELVb-iUTz8SO_5xQg:1285153424972"); //newStream.Write(byte1, 0, byte1.Length); //byte1 = encoding.GetBytes("entity=" + "00001otndccsdmo"); //newStream.Write(byte1, 0, byte1.Length); //byte1 = encoding.GetBytes("esm=" + "true"); //newStream.Write(byte1, 0, byte1.Length); //Console.WriteLine("!!!!!!!!"); byte1 = encoding.GetBytes(this.RequestParameters[0] + word); newStream.Write(byte1, 0, byte1.Length); //byte1 = encoding.GetBytes("sl=" + lp.From); //newStream.Write(byte1, 0, byte1.Length); //byte1 = encoding.GetBytes("tl=" + lp.To); //newStream.Write(byte1, 0, byte1.Length); newStream.Close(); } #endregion #region GetResponse WebResponse resp = null; try { resp = request.GetResponse(); //Console.WriteLine("Log: Get response for URL: '{0}'", url); } catch (WebException ex) { // тем самым состояние установим что у нас были проблемы m_ExceptionMessage = ex.Message + Environment.NewLine + request.Address.ToString(); if (this.IsOnGetResponseErrorThrowing) { throw ex; } if (!WWW.IsOnline()) { m_ExceptionMessage = WWW.InternetIsUnavailable; return(WWW.InternetIsUnavailable); } //var statusCode = ((HttpWebResponse)ex.Response).StatusCode; //return "An error occurred, status code: " + statusCode; // if (ex.Message.Contains("(404)")) return(m_ExceptionMessage); // ex.Status == ProtocolError // from System.Net.WebExceptionStatus // if (ex.Status == WebExceptionStatus.NameResolutionFailure) //Console.WriteLine("Errror: {0}, Response: {1}, URL: {2}", ex.Message, ex.Response, url); } #endregion if (resp == null) { if (!WWW.IsOnline()) { return(WWW.InternetIsUnavailable); } return("An error occurred while processing the request."); } response = GetStringFromResponse(resp); #endregion } this.LastRawResponse = response; if (this.StartTags != null && !string.IsNullOrEmpty(this.StartTags[0])) { response = GetContentFromTag(response); } // (c использованием base не получилось) //response = string.Format(@"<base target=""_blank"" /> <base href=""{0}"" /> ", this.CorrectionURL) + response; response = DoCorrectionForUrl(response, "href=\"#", url); // for bookmarks response = DoCorrectionForUrl(response, "href=\"", this.CorrectionURL); // for href=" (c использованием base не получилось) response = DoCorrectionForUrl(response, "src=\"", this.CorrectionURLForImage); response = DoCorrectionForUrl(response, "href=/", this.CorrectionURL); // for href=/ (c использованием base не получилось) response = DoCorrectionForUrl(response, "src=/", this.CorrectionURLForImage); response = DoCorrectionForUrl(response, "src='", this.CorrectionURLForImage); if (this.ClearFromScript) { response = DoCorrectionForScript(response); } if (this.ClearFromIframe) { response = DoCorrectionForIframe(response); } // for preventing opening new window (meat-in urban dictionary; unknownword - in wordReference) //response = response.Replace("<iframe", @"<base target=""_parent"" /> <iframe"); //response = response.Replace("<iframe", @"<iframe target=""_parent"""); lock (history) { if (!history.ContainsKey(word + _acceptedLanguageCode)) // другой поток мог успеть добавить { history.Add(word + _acceptedLanguageCode, response); } } m_LastResultFromResponse = new ResultFromResponse(url, _acceptedLanguageCode, response); if (!String.IsNullOrEmpty(this.Styles)) { string htmlTemplate = @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN""><html><head>{0}</head><body>{1}</body></html>"; response = string.Format(htmlTemplate, this.Styles, response); } return(response); }
public string GetContent(string word, LangPair lp) { word = word.Replace('\n', ' '); return(GetContent(word, lp.From, lp.To)); }
// URL for web page (is not for getting data) public virtual string GetPublicUrl(string word, LangPair langPair) { return(GetUrl(word, langPair)); }
static public LangPair Revert(LangPair lp) { return(new LangPair(lp.To, lp.From)); }
private void btReverse_Click(object sender, EventArgs e) { CurrentLangInfo.LanguageDirection = LangPair.Revert(CurrentLangInfo.LanguageDirection); BackFocusForTyping(); }
// "<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 } } }