private static string GenerateRTFHash(bool is_note_format, string text_for_cluster)
 {
     if (!String.IsNullOrEmpty(text_for_cluster))
     {
         return
             (""
              + (is_note_format ? "0" : "1")
              + StreamFingerprint.FromText(text_for_cluster).Substring(0, 8)
             );
     }
     else
     {
         return(null);
     }
 }
        private static string DoSearch(string title)
        {
            try
            {
                string title_encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(title));

                string auth = title;
                if (0 < auth.Length)
                {
                    // construct key for bibtexsearch.com authentication hash:
                    auth = auth[0] + auth + auth[0];
                }
                auth = StreamFingerprint.FromText(auth);

                string url_server = bibtex_search_server_manager.GetServerUrl();
                string url        = String.Format("{0}/search?auth={1}&qe={2}", url_server, auth, WebUtility.HtmlEncode(title_encoded));
                try
                {
                    WebHeaderCollection header_collection;
                    Stopwatch           clk = Stopwatch.StartNew();

                    using (MemoryStream ms = UrlDownloader.DownloadWithBlocking(url, out header_collection))
                    {
                        bibtex_search_server_manager.ReportLatency(url_server, clk.ElapsedMilliseconds);
                        Logging.Debug特("bibtex_search_server_manager: Download {0} took {1} ms", url, clk.ElapsedMilliseconds);

                        string json = Encoding.UTF8.GetString(ms.ToArray());
                        return(json);
                    }
                }
                catch (Exception ex)
                {
                    bibtex_search_server_manager.ReportError(url_server);
                    Logging.Warn(ex, "There was a problem searching for BibTeX for title '{0}' at server '{1}'.", title, url_server);
                }
            }

            catch (Exception ex)
            {
                Logging.Warn(ex, "There was a problem searching for BibTeX for title '{0}'.", title);
            }

            return(null);
        }
        private static string DoSearch(string title)
        {
            try
            {
                string title_encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(title));

                string auth = title;
                if (0 < auth.Length)
                {
                    auth = auth[0] + auth + auth[0];
                }
                auth = StreamFingerprint.FromText(auth);

                string url_server = bibtex_search_server_manager.GetServerUrl();
                string url        = String.Format("{0}/search?auth={1}&qe={2}", url_server, auth, WebUtility.HtmlEncode(title_encoded));
                try
                {
                    MemoryStream        ms;
                    WebHeaderCollection header_collection;
                    DateTime            START = DateTime.UtcNow;
                    UrlDownloader.DownloadWithBlocking(ConfigurationManager.Instance.Proxy, url, out ms, out header_collection);
                    DateTime STOP = DateTime.UtcNow;
                    bibtex_search_server_manager.ReportLatency(url_server, (STOP - START).TotalMilliseconds);

                    string json = Encoding.UTF8.GetString(ms.ToArray());
                    return(json);
                }

                catch (Exception ex)
                {
                    bibtex_search_server_manager.ReportError(url_server);
                    Logging.Warn(ex, "There was a problem searching for BibTeX for title '{0}' at server '{1}'.", title, url_server);
                }
            }

            catch (Exception ex)
            {
                Logging.Warn(ex, "There was a problem searching for BibTeX for title '{0}'.", title);
            }

            return(null);
        }