예제 #1
0
 public Task <string> ExecuteRequest(Uri url)
 {
     try
     {
         var client = new PatientWebClient {
             Credentials = CredentialCache.DefaultNetworkCredentials
         };
         using (client)
         {
             return(Task.Run(() => client.DownloadString(url)));
         }
     }
     catch (Exception e)
     {
         Dev2Logger.Error(e, "Warewolf Error");
         return(new Task <string>((() => e.Message)));
     }
 }
예제 #2
0
        private static DatasetsResponse DownloadDataset(int page, QuandlDatabase database)
        {
            using (PatientWebClient client = new PatientWebClient())
            {
                try
                {
                    var json = client.DownloadString("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);

                    return(response);
                }
                catch (Exception e)
                {
                    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));
                    return(new DatasetsResponse());
                }
            }
        }
예제 #3
0
        string ExecuteRequest(Uri url)
        {
            Task <string> failRequest;
            var           client = new PatientWebClient {
                Credentials = CredentialCache.DefaultNetworkCredentials
            };

            using (client)
            {
                failRequest = Task.Run(() => client.DownloadString(url));
            }
            string failRequestResult;

            try
            {
                failRequestResult = failRequest.Result;
            }
            catch (AggregateException e)
            {
                return(new StreamReader((e.InnerExceptions[0] as WebException)?.Response?.GetResponseStream())?.ReadToEnd());
            }

            return(failRequestResult);
        }
예제 #4
0
        private static DatatableResponse DownloadDatatable(QuandlDatatable datatable)
        {
            using (PatientWebClient client = new PatientWebClient())
            {
                try
                {
                    var json = client.DownloadString(" https://www.quandl.com/api/v3/datatables/" + datatable.Name + ".json?api_key=" + Utils.Constants.API_KEY);
                    DatatableResponse response =
                        JsonConvert.DeserializeObject <DatatableResponse>(json, new JsonSerializerSettings {
                        ContractResolver = Utils.Converters.MakeUnderscoreContract()
                    });

                    Utils.ConsoleInformer.PrintProgress("1B", "Fetching datatable [" + datatable.Name + "]: ", Utils.Helpers.GetPercent(count, datatables.Count).ToString() + "%");

                    return(response);
                }
                catch (Exception e)
                {
                    // Add error to inform and log later
                    errors.Add(new Tuple <string, string>("Failed to fetch datatable: [" + datatable.Name + "]", "Ex: " + e.Message));
                    return(new DatatableResponse());
                }
            }
        }