Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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));
        }