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 DoFormPostRequest(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"); try { Dictionary <String, String> FormData = new Dictionary <String, String>() { { "username", "davchezt" }, { "password", "4Bahagia4" }, { "login", "true" } }; JObject output = await client.PostRequest(RouterPath) .AddFormParameters(FormData) .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}"); } }); }
private static async Task SendRequestAsync() { await Console.Out.WriteLineAsync("Sending request..."); var client = new TinyRestClient(Client, "http://paycortaxcredintfnquarterly.trafficmanager.net/api"); client.Settings.DefaultHeaders.AddBearer(BearerToken.Value); var response = await client.PostRequest("v1/manualrequest") .AddContent( new ManualRequest { Id = Guid.NewGuid(), EventType = "Payroll.Payrun.Distributed", ClientId = 207002, PlannerUid = 15184521809082 }) .AllowAnyHttpStatusCode() .ExecuteAsync <HttpResponseMessage>(); if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { BearerToken = new Lazy <string>(() => GetBearerTokenAsync().Result); } else { Debug.Assert(response.IsSuccessStatusCode); } }
public async Task <IActionResult> Post([FromBody] ReservasResponse reservasResponse) { try { ReservasData reservasData = new ReservasData() { CodigoReserva = "123132", idCotizacion = "12331312", FechaHoraReserva = "2020-09-12T00:00:00", UsuarioReserva = "12223", TotalReserva = "8787" }; await _context.SaveAsync <ReservasData>(reservasData); _logger.LogInformation("Post Reserva"); Pasajero pasajero1 = new Pasajero() { Nombre = "Juan", Apellido = "Perez", Dni = "12312312", Telefono = "351222522", Email = "*****@*****.**" }; ReservasResponse reserva1 = new ReservasResponse() { idCotizacion = "b7538f04-aace-4d6d-a108-7e31bb165c57", pasajero = pasajero1 }; var client = new TinyRestClient(new HttpClient(), _config["url_api_proveedor"]); _logger.LogInformation("Empieza acá... RESERVA1:", reserva1); Console.WriteLine("RESERFVA:", reserva1); var data = new { IdCotizacion = reserva1.idCotizacion, Pasajero = reserva1.pasajero }; var response = await client. PostRequest("Reservas", data). WithOAuthBearer(await AuthorizationHelper.ObtenerAccessToken()). ExecuteAsync <IActionResult>(); return(response); } catch (Exception ex) { _logger.LogError("Error: " + ex.Message); return(null); } }
public async static Task <string> ObtenerAccessToken() { if (accessToken == null) { var clientOAuth = new TinyRestClient(new HttpClient(), _config["OAuth0::UrlAuth0"]); var request = new OAuthRequest() { audience = _config["OAuth0::Audience"], client_id = _config["OAuth0::ClientId"], client_secret = _config["OAuth0::ClientSecret"], grant_type = "client_credentials" }; accessToken = await clientOAuth.PostRequest("token", request). ExecuteAsync <OAuthAccessToken>(); } return(accessToken.access_token); }
public async static Task <string> ObtenerAccessToken() { if (accessToken == null) { var clientOAuth = new TinyRestClient(new HttpClient(), "https://dev-utn-frc-iaew.auth0.com/oauth"); var request = new OAuthRequest() { audience = "https://www.example.com/reservas", client_id = "Gd23b2IQ7awzx1PueJw2XhZSL9HAD6wT", client_secret = "gao2QIPgFpmFRKRjRn6tfHwFTLQLmqin77wwC-XOM5Vi6P57KHV14nQIYITZaZr_", grant_type = "client_credentials" }; accessToken = await clientOAuth.PostRequest("token", request). ExecuteAsync <OAuthAccessToken>(); } return(accessToken.access_token); }