private void PerformRequest(string url) { bool is_chat_available = false; try { using (MemoryStream ms = UrlDownloader.DownloadWithBlocking(url)) { ProcessDisplayResponse(ms); } is_chat_available = true; } catch (Exception ex) { Logging.Warn(ex, "There was a problem communicating with chat. URL: {0}", url); next_autopoll_datetime = DateTime.UtcNow.AddMinutes(1); is_chat_available = false; } // make sure we're not in the process of shutting down Qiqqa for then the next code chunk will cause a CRASH: if (null != Application.Current && !Utilities.Shutdownable.ShutdownableManager.Instance.IsShuttingDown) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { IsEnabled = is_chat_available; TxtChatUnavailable.Visibility = is_chat_available ? Visibility.Collapsed : Visibility.Visible; })); } else { Logging.Warn("Chat: detected Qiqqa shutting down."); } }
private void PerformRequest(string url) { bool is_chat_available = false; try { MemoryStream ms; UrlDownloader.DownloadWithBlocking(ConfigurationManager.Instance.Proxy, url, out ms); ProcessDisplayResponse(ms); is_chat_available = true; } catch (Exception ex) { Logging.Warn(ex, "There was a problem communicating with chat."); next_autopoll_datetime = DateTime.UtcNow.AddMinutes(1); is_chat_available = false; } Application.Current.Dispatcher.BeginInvoke(new Action(() => { this.IsEnabled = is_chat_available; TxtChatUnavailable.Visibility = is_chat_available ? Visibility.Collapsed : Visibility.Visible; })); }
public static List <GoogleScholarScrapePaper> ScrapeUrl(IWebProxy proxy, string url) { List <GoogleScholarScrapePaper> gssps = new List <GoogleScholarScrapePaper>(); MemoryStream ms = new MemoryStream(); try { WebHeaderCollection header_collection = new WebHeaderCollection(); UrlDownloader.DownloadWithBlocking(proxy, url, out ms, out header_collection); HtmlDocument doc = new HtmlDocument(); doc.Load(ms); ScrapeDoc(doc, url, gssps); } catch (Exception ex) { Logging.Error(ex, "There was a problem parsing the GoogleScholar url"); } finally { if (ms != null) { ms.Dispose(); } } return(gssps); }
internal static void Check(WebLibraryDetail web_library_detail) { WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread(); // We can operate only on bundle libs if (!web_library_detail.IsBundleLibrary) { return; } // Only check every hour if (DateTime.UtcNow.Subtract(web_library_detail.LastBundleManifestDownloadTimestampUTC ?? DateTime.MinValue).TotalMinutes < 60) { return; } // Flag that we are running this update check now web_library_detail.LastBundleManifestDownloadTimestampUTC = DateTime.UtcNow; WebLibraryManager.Instance.NotifyOfChangeToWebLibraryDetail(); // Download the new manifest BundleLibraryManifest manifest_existing = BundleLibraryManifest.FromJSON(web_library_detail.BundleManifestJSON); string manifest_latest_url = manifest_existing.BaseUrl + @"/" + manifest_existing.Id + Common.EXT_BUNDLE_MANIFEST; using (MemoryStream ms = UrlDownloader.DownloadWithBlocking(manifest_latest_url)) { string manifest_latest_json = Encoding.UTF8.GetString(ms.ToArray()); BundleLibraryManifest manifest_latest = BundleLibraryManifest.FromJSON(manifest_latest_json); // It is an old version or we have this version if (0 <= String.Compare(manifest_existing.Version, manifest_latest.Version)) { return; } // It is a version the user has chosen to ignore if (web_library_detail.LastBundleManifestIgnoreVersion == manifest_latest.Version) { return; } BundleLibraryUpdateNotification blun = new BundleLibraryUpdateNotification(web_library_detail, manifest_latest); NotificationManager.Instance.AddPendingNotification( new NotificationManager.Notification( String.Format("An update is available for your Bundle Library '{0}', from version {1} to {2}.", manifest_latest.Title, manifest_existing.Version, manifest_latest.Version), "Bundle Library update available!", NotificationManager.NotificationType.Info, Icons.LibraryTypeBundle, "Download!", blun.Download, "No thanks!", blun.NoThanks ) ); } }
internal static string GetRootStyleFilename(string style_xml_filename) { string parent_filename; string parent_url; if (IsDependentStyle(style_xml_filename, out parent_filename, out parent_url)) { // Check that we have the dependent style - if we don't prompt to download it string full_parent_filename = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(style_xml_filename), parent_filename)); if (!File.Exists(full_parent_filename)) { string message = String.Format( "Can't find parent style for this dependent style" + "\n\n" + "Your style depends on a parent style named {0}, which needs to be saved in the same directory.\n\n" + "It appears to be available from {1}.\n" + "Shall we try to download it automatically? If you choose NO, Qiqqa will open the website for you so you can download it manually.", parent_filename, parent_url ); if (MessageBoxes.AskQuestion(message)) { try { using (MemoryStream ms = UrlDownloader.DownloadWithBlocking(parent_url)) { File.WriteAllBytes(full_parent_filename, ms.ToArray()); } } catch (UnauthorizedAccessException ex) { Logging.Error(ex, "You don't seem to have permission to write the new style to the directory '{0}'.\nPlease copy the original style file '{1}' to a folder where you can write (perhaps alongside your Word document), and try again.", full_parent_filename, style_xml_filename); MessageBoxes.Warn("You don't seem to have permission to write the new style to the directory '{0}'.\nPlease copy the original style file '{1}' to a folder where you can write (perhaps alongside your Word document), and try again.", full_parent_filename, style_xml_filename); } } else { MainWindowServiceDispatcher.Instance.OpenUrlInBrowser(parent_url, true); } } // Check again if the parent file exists, and if it does, recurse the dependency check if (File.Exists(full_parent_filename)) { return(GetRootStyleFilename(full_parent_filename)); } else { // We need the parent style, but haven't managed to download it, so return nothing... return(null); } } else // Not a dependent style, so use this filename { return(style_xml_filename); } }
internal static void Check(Library library) { // We can operate only on bundle libs if (!library.WebLibraryDetail.IsBundleLibrary) { return; } // Only check every hour if (DateTime.UtcNow.Subtract(library.WebLibraryDetail.LastBundleManifestDownloadTimestampUTC ?? DateTime.MinValue).TotalMinutes < 60) { return; } // Flag that we are running this update check now library.WebLibraryDetail.LastBundleManifestDownloadTimestampUTC = DateTime.UtcNow; WebLibraryManager.Instance.NotifyOfChangeToWebLibraryDetail(); // Download the new manifest BundleLibraryManifest manifest_existing = BundleLibraryManifest.FromJSON(library.WebLibraryDetail.BundleManifestJSON); string manifest_latest_url = manifest_existing.BaseUrl + "/" + manifest_existing.Id + ".qiqqa_bundle_manifest"; MemoryStream ms; UrlDownloader.DownloadWithBlocking(ConfigurationManager.Instance.Proxy, manifest_latest_url, out ms); string manifest_latest_json = Encoding.UTF8.GetString(ms.ToArray()); BundleLibraryManifest manifest_latest = BundleLibraryManifest.FromJSON(manifest_latest_json); // It is an old version or we have this version if (0 <= String.Compare(manifest_existing.Version, manifest_latest.Version)) { return; } // It is a version the user has chosen to ignore if (library.WebLibraryDetail.LastBundleManifestIgnoreVersion == manifest_latest.Version) { return; } { BundleLibraryUpdateNotification blun = new BundleLibraryUpdateNotification(library, manifest_latest); NotificationManager.Instance.AddPendingNotification( new NotificationManager.Notification( String.Format("An update is available for your Bundle Library '{0}', from version {1} to {2}.", manifest_latest.Title, manifest_existing.Version, manifest_latest.Version), "Bundle Library update available!", NotificationManager.NotificationType.Info, Icons.LibraryTypeBundle, "Download!", blun.Download, "No thanks!", blun.NoThanks ) ); } }
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); }
public static List <GoogleScholarScrapePaper> ScrapeUrl(string url) { List <GoogleScholarScrapePaper> gssps = new List <GoogleScholarScrapePaper>(); try { WebHeaderCollection header_collection = new WebHeaderCollection(); using (MemoryStream ms = UrlDownloader.DownloadWithBlocking(url, out header_collection)) { HtmlDocument doc = new HtmlDocument(); doc.Load(ms, System.Text.Encoding.UTF8, detectEncodingFromByteOrderMarks: false); ScrapeDoc(doc, url, gssps); } } catch (Exception ex) { Logging.Error(ex, "There was a problem parsing the GoogleScholar url {0}", url); } return(gssps); }