private async void RelhaxWindow_Loaded(object sender, RoutedEventArgs e) { //write that we're currently loading string loadingString = Translations.GetTranslatedString("loading"); DatabaseUpdateText.Text = ApplicationUpdateText.Text = loadingString; ViewNewsOnGoogleTranslate.TheHyperlink.Click += TheHyperlink_Click; //get the strings using (PatientWebClient client = new PatientWebClient()) { try { DatabaseUpdateText.Text = await client.DownloadStringTaskAsync(ApplicationConstants.DatabaseNotesUrl); ApplicationUpdateText.Text = await client.DownloadStringTaskAsync(ApplicationConstants.ApplicationNotesBetaUrl); } catch (Exception ex) { Logging.Error("Failed to get news information"); Logging.Exception(ex.ToString()); if (DatabaseUpdateText.Text.Equals(loadingString)) { DatabaseUpdateText.Text = Translations.GetTranslatedString("failedToGetNews"); } ApplicationUpdateText.Text = Translations.GetTranslatedString("failedToGetNews"); } } }
private async void RelhaxWindow_Loaded(object sender, RoutedEventArgs e) { //write that we're currently loading DatabaseUpdateText.Text = ApplicationUpdateText.Text = Translations.GetTranslatedString("loading"); ViewNewsOnGoogleTranslate.TheHyperlink.Click += TheHyperlink_Click; //get the strings using (PatientWebClient client = new PatientWebClient()) { DatabaseUpdateText.Text = await client.DownloadStringTaskAsync(Settings.DatabaseNotesUrl); ApplicationUpdateText.Text = await client.DownloadStringTaskAsync(Settings.ApplicationNotesBetaUrl); } }
public static async Task <bool> TriggerMirrorSyncAsync() { using (PatientWebClient client = new PatientWebClient() { Credentials = PrivateStuff.BigmodsNetworkCredentialScripts, Timeout = 100000 }) { try { string result = await client.DownloadStringTaskAsync(PrivateStuff.BigmodsTriggerManualMirrorSyncPHP); Logging.Info(result.Replace("<br />", "\n")); if (result.ToLower().Contains("trigger=1")) { return(true); } } catch (WebException wex) { Logging.Error("Failed to run trigger manual sync script"); Logging.Exception(wex.ToString()); return(false); } } return(false); }
private static async Task DownloadDatasetsAsync(int page, QuandlDatabase database) { using (PatientWebClient client = new PatientWebClient()) { try { string json = await client.DownloadStringTaskAsync(new Uri("https://www.quandl.com/api/v3/datasets.json?database_code=" + database.DatabaseCode + "&sort_by=id&page=" + page + "&api_key=" + Utils.Constants.API_KEY)); DatasetsResponse response = JsonConvert.DeserializeObject <DatasetsResponse>(json, new JsonSerializerSettings { ContractResolver = Utils.Converters.MakeUnderscoreContract() }); pagesSum++; Utils.ConsoleInformer.PrintProgress("1B", "Fetching datasets [" + database.DatabaseCode + "]: ", Utils.Helpers.GetPercent(pagesSum, response.Meta.TotalPages).ToString() + "%"); // Add it to its own group //datasetsGroups.Find(d => d.DatabaseCode == database.DatabaseCode).Datasets.AddRange(response.Datasets); // Insert datasets page directly QuandlDatasetGroup datasetGroup = new QuandlDatasetGroup() { DatabaseCode = database.DatabaseCode, Datasets = response.Datasets }; PostgresHelpers.QuandlDatasetActions.InsertQuandlDatasetGroup(datasetGroup); } catch (Exception e) { // Blocked? if (e.Message.Contains("(429)") && !blocked) { Utils.ConsoleInformer.Inform("Looks like quandl just blocked you"); blocked = true; } // Log Utils.Helpers.Log("Failed to fetch page: " + page + " from Database: [" + database.DatabaseCode + "]", "Ex: " + e.Message); // Add error to inform and log later errors.Add(new Tuple <string, string>("Failed to fetch page: " + page + " from Database: [" + database.DatabaseCode + "]", "Ex: " + e.Message)); } } }
private static async Task DownloadDatasetDataAsync(QuandlDataset dataset, int to) { using (PatientWebClient client = new PatientWebClient()) { try { string data = await client.DownloadStringTaskAsync(new Uri("https://www.quandl.com/api/v3/datasets/" + dataset.DatabaseCode + "/" + dataset.DatasetCode + "/data.json?api_key=" + Utils.Constants.API_KEY + "&start_date=" + dataset.LastFetch.GetValueOrDefault(DateTime.MinValue).AddDays(1).ToString("yyyy-MM-dd"))); // Add one day because I dont want to include the current newest in the json DataResponse response = JsonConvert.DeserializeObject <DataResponse>(data, new JsonSerializerSettings { ContractResolver = Utils.Converters.MakeUnderscoreContract() }); QuandlDatasetData datasetData = response.DatasetData; datasetData.SetBaseDataset(dataset); datasetsFetched++; Utils.ConsoleInformer.PrintProgress("1C", "Fetching dataset [" + dataset.DatasetCode + "]: ", Utils.Helpers.GetPercent(datasetsFetched, to).ToString() + "%"); // Replace old uncomplete dataset with new one //ReplaceCompleteDataset(datasetData); //AddCompleteDataset(datasetData); // Insert QuandlDatasetDataGroup datasetGroup = new QuandlDatasetDataGroup() { DatabaseCode = datasetData.DatabaseCode, Datasets = new List <QuandlDatasetData>() }; datasetGroup.Datasets.Add(datasetData); PostgresHelpers.QuandlDatasetActions.InsertQuandlDatasetsDataGroup(datasetGroup); } catch (Exception e) { // Add to fetch later (Create datasetgroup if doesnt exists in failed list) if (!failedToFetch.Exists(d => d.DatabaseCode == dataset.DatabaseCode)) { failedToFetch.Add(new QuandlDatasetGroup() { DatabaseCode = dataset.DatabaseCode, Datasets = new List <QuandlDataset>() }); } failedToFetch.Find(d => d.DatabaseCode == dataset.DatabaseCode).Datasets.Add(dataset); if (e.Message.Contains("(429)")) { // Print only once if (!blocked) { Utils.ConsoleInformer.Inform("Looks like quandl just blocked you"); } blocked = true; } // Log Utils.Helpers.Log("Failed to fetch data: from dataset: [" + dataset.DatabaseCode + "/" + dataset.DatasetCode + "] Will try to recover", "Ex: " + e.Message); //errors.Add(new Tuple<string, string>("Failed to fetch data: from dataset: [" + dataset.DatabaseCode + "/" + dataset.DatasetCode + "]", "Ex: " + e.Message)); } } }