public async Task <int> Start() { _log.Information("Starting backup session"); var request = _restClient.PostRequest("start", _config.GetClientInfo()); SessionStartDto response; try { response = await request.ExecuteAsync <SessionStartDto>(); } catch (Exception e) { _log.Fatal(e, "Session start error: "); return(-1); } _config.SetSession(response); _config.ForgeToken = response.AccessToken; _timer.Elapsed += async(sender, args) => { try { var tokenRequest = _restClient.GetRequest($"token/{_config.ClientId}"); var tokenResponse = await tokenRequest.ExecuteAsync <TokenDto>(); _config.ForgeToken = tokenResponse.AccessToken; _log.Information("Token refresh ok"); } catch (Exception e) { _log.Error(e, "Token refresh error: "); } }; _timer.Start(); _tasks.Add(Task.Run(async() => await PullData()) .ContinueWith(x => _log.Information("Puller exit"))); _tasks.Add(Task.Run(async() => await PushData()) .ContinueWith(x => _log.Information("Pusher exit"))); _tasks.AddRange(Enumerable.Range(0, _config.Concurrency) .Select(i => ProcessData(i + 1) .ContinueWith(x => _log.Information($"Worker {i + 1} exit")))); _log.Information("Session started, workers: " + _config.Concurrency); Task.WaitAll(_tasks.ToArray()); _log.Information("BimZip BimZipClient shutdown"); return(0); }
private void DoGetRequest(String RouterPath = null) { Task.Run(action: async() => { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; client = new TinyRestClient(new HttpClient(), ApiUrl); client.Settings.DefaultHeaders.Add("Accept", "application/json"); client.Settings.DefaultHeaders.Add("User-Agent", "Admin Client 1.0"); client.Settings.DefaultHeaders.AddBearer("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMiJ9.PbGhl-f91Mc537CmVSrCHnah0qB-ze7c3orXaKwshZk"); // client.Settings.Formatters.OfType<JsonFormatter>().First().UseKebabCase(); try { // String response = await client.GetRequest(RouterPath).ExecuteAsStringAsync(); // JObject json = JObject.Parse(response); JObject output = await client.GetRequest(RouterPath).ExecuteAsync <JObject>(); WriteToFile(output.ToString()); } catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { WriteToFile($"{ex.Message} {ex.ReasonPhrase}"); } catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.InternalServerError) { WriteToFile($"{ex.Message} {ex.ReasonPhrase}"); } catch (Exception ex) { WriteToFile($"{ex.Message}"); } }); }
public async Task <IEnumerable <Cotizacion> > Get(string idCiudad, string fechaHoraRetiro, string fechaHoraDevolucion) { try { _logger.LogInformation("Inicio"); var client = new TinyRestClient(new HttpClient(), _config["url_api_proveedor"]); List <Cotizacion> arregloVacio = new List <Cotizacion>(); var cotizaciones = await client. GetRequest("Vehiculos/cotizar"). AddQueryParameter("idCiudad", idCiudad). AddQueryParameter("fechaHoraRetiro", fechaHoraRetiro). AddQueryParameter("fechaHoraDevolucion", fechaHoraDevolucion). WithOAuthBearer(await AuthorizationHelper.ObtenerAccessToken()). ExecuteAsync <List <Cotizacion> >(); Console.WriteLine("string cotizaciones:", cotizaciones); if (cotizaciones == null) { return(arregloVacio); } else { return(cotizaciones); } } catch (Exception ex) { _logger.LogError("Error: " + ex.Message); return(null); } }
/// <inheritdoc/> public async Task <IList <Launchpad> > GetList(string keyword, int?pageNumber, int?itemsPerPage, string sortBy, bool?sortAscending) { var launchPads = await _client.GetRequest("launchpads") .AddQueryParameter("offset", pageNumber) .AddQueryParameter("limit", itemsPerPage) .ExecuteAsync <IList <Launchpad> >(); if (!string.IsNullOrEmpty(keyword)) { launchPads = launchPads.Where(l => l.FullName.ToLower().Contains(keyword.ToLower())).ToList(); } launchPads = Sort(launchPads, sortBy, sortAscending ?? false); return(launchPads); }
public async Task <IEnumerable <Ciudad> > Get() { try { _logger.LogInformation("Inicio"); // Consumir API Proveedor // Creamos una instancia de Client TinyRestClient, // indicando la url base de la API que queremos consumir var client = new TinyRestClient(new HttpClient(), _config["url_api_proveedor"]); // El metodo GetRequest prepara el request HTTP a // la API en cuestion, en este caso /ciudades var ciudades = await client. // El metodo GetRequest prepara el request HTTP a la API en cuestion, en este caso /ciudades GetRequest("Ciudades"). //Para agregar parametros en el request AddQueryParameter("name", "valor"). //Agregamos el Token OAuth 2.0 WithOAuthBearer(await AuthorizationHelper.ObtenerAccessToken()). // El metodo ExecuteAsync ejecuta la peticio HTTP y con la // respuesta construye una lista de Ciudades (List<Ciudad>) ExecuteAsync <List <Ciudad> >(); return(ciudades); } catch (Exception ex) { _logger.LogError("Error: " + ex.Message); return(null); } }
public async Task <IEnumerable <ReservasData> > Get() { try { _logger.LogInformation("Inicio"); var client = new TinyRestClient(new HttpClient(), _config["url_api_proveedor"]); var reservas = await client. GetRequest("Reservas"). WithOAuthBearer(await AuthorizationHelper.ObtenerAccessToken()). ExecuteAsync <List <Reserva> >(); List <ScanCondition> condiciones = new List <ScanCondition>(); List <ReservasData> reservas_cliente = await _context.ScanAsync <ReservasData>(condiciones).GetRemainingAsync(); return(reservas_cliente); } catch (Exception ex) { _logger.LogError("Error: " + ex.Message); return(null); } }
bool isVPN(string ip, Entity player) { ignoredPlayers = System.IO.File.ReadAllLines(ignoredPlayersTxt); foreach (string ignoredPlayer in ignoredPlayers) { if (player.Name == ignoredPlayer) { WriteLog.Info($"{player.Name} has a VPN but they have been ignored."); return(false); } } var client = new TinyRestClient(new HttpClient(), "http://v2.api.iphub.info"); var response = client.GetRequest($"ip/{ip}") .AddHeader("X-Key", API_KEY) .ExecuteAsStringAsync(); Dictionary <string, object> result = JsonConvert.DeserializeObject <Dictionary <string, object> >(response.Result); if (result["block"].ToString() == "1") { return(true); } else { addToPlayersInGame(player); return(false); } }
public void Update() { var m_currencyPairList = dbContext.CurrencyPair.AsNoTracking() .Where(cp => cp.isDeleted.Equals(false)) .ToList(); var m_currentCourseDictionary = restClient. GetRequest("convert"). AddQueryParameter("q", convertCurryncyPairToQueryParams(m_currencyPairList)). AddQueryParameter(COMPACT_PARAM_NAME, COMPACT_PARAM_VALUE). AddQueryParameter(API_KEY_NAME, serverAPIkey). ExecuteAsync <Dictionary <string, double> >(). Result; writeRateHistory(m_currentCourseDictionary, m_currencyPairList); }
private static async Task <int> DownloadListToFile(Options opts) { using (var httpClientHandler = new HttpClientHandler()) { httpClientHandler.ServerCertificateCustomValidationCallback = CertValidation.IsExpectedCert; using (var httpClient = new HttpClient(httpClientHandler)) { var client = new TinyRestClient(httpClient, ccUrl); client.Settings.DefaultHeaders.AddBasicAuthentication(opts.User, opts.Password); var list = await client.GetRequest().ExecuteAsStringAsync(); File.WriteAllText(opts.Output, list); } } return(ExitSuccess); }
public async Task <IEnumerable <Ciudad> > Get() { try { _logger.LogInformation("Inicio"); var client = new TinyRestClient(new HttpClient(), _config["url_api_proveedor"]); var ciudades = await client. GetRequest("Ciudades"). WithOAuthBearer(await AuthorizationHelper.ObtenerAccessToken()). ExecuteAsync <List <Ciudad> >(); return(ciudades); } catch (Exception ex) { _logger.LogError("Error: " + ex.Message); return(null); } }
private async Task <List <long> > BestStoriesListAsync() => await _client.GetRequest("beststories.json").ExecuteAsync <List <long> >();
public async Task <PostmanCollectionList> BuscarCollections() => await Client.GetRequest("collections").ExecuteAsync <PostmanCollectionList>();