private async Task <ResilientHttpClient> GetClientAndLoginAsync(string username, string password, CancellationToken cToken) { var client = new ResilientHttpClient(); client.RetryAfterTimeout = false; client.RetryCount = 0; client.Timeout = TimeSpan.FromSeconds(10); var content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("login_username", username), new KeyValuePair <string, string>("login_password", password), new KeyValuePair <string, string>("submit_form", "1") }); var response = await client.PostAsync("https://7777.bg/login/", content, cToken); var result = await response.Content.ReadAsStringAsync(); var document = this.parser.Parse(result); var title = document.Title; if (title.ToLower().Contains("вход")) { return(null); } return(client); }
public FileChaosController(ResilientHttpClient client, IOptions <MonitoringSettings> monitoringOptions, IOptionsSnapshot <AppChaosSettings> chaosOptionsSnapshot, ILogger <FileChaosController> logger) { this.client = client; monitoringSettings = monitoringOptions.Value; chaosSettings = chaosOptionsSnapshot.Value; _logger = logger; }
public TripController(IUserRepository userRepository, IDriverRepository driverRepository, IMemoryCache cache, ResilientHttpClient httpClient, IOptions <TripApiSettings> tripApiSettings, IHubContext <TripHub> hubContext, IReportingRepository reportingRepository, Lazy <Task <GeneralChaosSetting> > generalChaosSettingFactory) { _userRepository = userRepository; _driverRepository = driverRepository; _cache = cache; _httpClient = httpClient; _tripApiSettings = tripApiSettings; _hubContext = hubContext; _reportingRepository = reportingRepository; _generalChaosSettingFactory = generalChaosSettingFactory; _originsAndDestinations = new Dictionary <SelectListItem, LocationModel> { { new SelectListItem { Text = "Poblado's Park" }, new LocationModel { Latitude = 6.210292869847029, Longitude = -75.57115852832794, Description = "Poblado's Park" } }, { new SelectListItem { Text = "Lleras Park" }, new LocationModel { Latitude = 6.2087793817882515, Longitude = -75.56776275426228, Description = "Lleras Park" } }, { new SelectListItem { Text = "Sabaneta Park" }, new LocationModel { Latitude = 6.151584634798451, Longitude = -75.61546325683594, Description = "Sabaneta Park" } }, { new SelectListItem { Text = "The executive bar" }, new LocationModel { Latitude = 6.252063572976704, Longitude = -75.56599313040351, Description = "The executive bar" } }, }; }
public async Task <bool> LoginAsync(string username, string password, CancellationToken cToken) { this.usernameCache = username; this.passwordCache = password; var newClient = await this.GetClientAndLoginAsync(this.usernameCache, this.passwordCache, cToken); this.client?.Dispose(); this.client = newClient; if (newClient == null) { this.IsLoggedIn = false; return(false); } else { this.IsLoggedIn = true; this.timer.Start(); return(true); } }
public Task Handle(string eventName, dynamic eventData) { var publishedEvent = _IExternalSubscriptionsManager.GetPublishedEvent(eventName); if (publishedEvent.EventThresholdSeconds > 0) { var cachekey = eventName + "_LastHandleTime"; var lastHandleTime = _IDataCacheManager.GetCache <DateTime?>(cachekey); if (lastHandleTime != null && DateTime.Now.Subtract(lastHandleTime.Value).TotalSeconds < publishedEvent.EventThresholdSeconds) { return(Task.FromResult(0)); } _IDataCacheManager.SetCache(cachekey, DateTime.Now); } var subscribers = _IExternalSubscriptionsManager.GetPublicSubscribersByEventName(eventName); var resilientHttpClient = new ResilientHttpClient((c) => CreatePolicies(), _logger); foreach (var subscriber in subscribers) { string strNewAddress = subscriber.Address + (subscriber.Address.IndexOf("?") == -1 ? "?" : "&"); strNewAddress += "eventname=" + eventName; if (String.IsNullOrEmpty(subscriber.PrivateKey)) { resilientHttpClient.PostAsync(strNewAddress, eventData); } else { var message = JsonConvert.SerializeObject(eventData); var encryptMessage = AESCryptor.EncryptStringAES(message, subscriber.PrivateKey); resilientHttpClient.PostAsync(strNewAddress, encryptMessage); } } return(Task.FromResult(1)); }
public PaymentServiceAdapter(ResilientHttpClient httpClient, string paymentServiceBaseUrl) { _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); _paymentServiceBaseUrl = !string.IsNullOrWhiteSpace(paymentServiceBaseUrl) ? paymentServiceBaseUrl : throw new ArgumentNullException(nameof(paymentServiceBaseUrl)); }
public PaymentServiceAdapter(ResilientHttpClient httpClient, string paymentServiceBaseUrl, Lazy <Task <GeneralChaosSetting> > generalChaosSettingFactory) { _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); _generalChaosSettingFactory = generalChaosSettingFactory ?? throw new ArgumentException(nameof(generalChaosSettingFactory)); _paymentServiceBaseUrl = !string.IsNullOrWhiteSpace(paymentServiceBaseUrl) ? paymentServiceBaseUrl : throw new ArgumentNullException(nameof(paymentServiceBaseUrl)); }
public MonitoringController(ResilientHttpClient client, IOptions <MonitoringSettings> monitoringOptions, IOptionsSnapshot <AppChaosSettings> chaosOptionsSnapshot) { this.client = client; monitoringSettings = monitoringOptions.Value; chaosSettings = chaosOptionsSnapshot.Value; }