Ejemplo n.º 1
0
        public async Task <ClientDto> Handle(GetClientQuery request, CancellationToken cancellationToken)
        {
            Client client = await _provider.GetClient(request);

            return(new ClientDto {
                id = client.id, age = client.age, name = client.name
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Runs the transmitter process
        /// </summary>
        public void Run()
        {
            IClientProvider provider = Activator.CreateInstance <T>();
            var             client   = provider.GetClient();

            _beforeRun();
            _run(client);
            _afterRun();
        }
Ejemplo n.º 3
0
        public ElasticSearcher(IClientProvider clientProvider, IElasticConnectionSettings elasticConnectionSettings)
        {
            if (clientProvider == null) throw new ArgumentNullException("clientProvider");
            if (elasticConnectionSettings == null) throw new ArgumentNullException("elasticConnectionSettings");

            _clientProvider = clientProvider;
            _elasticConnectionSettings = elasticConnectionSettings;
            _client = _clientProvider.GetClient(_elasticConnectionSettings);
        }
        public async Task <ClientCategoryDto> Handle(GetClientCategoryQuery request, CancellationToken cancellationToken)
        {
            Client client = await _provider.GetClient(request);

            if (client.age >= 18)
            {
                return(new ClientCategoryDto {
                    category = "Adult", canDrink = true
                });
            }
            else
            {
                return(new ClientCategoryDto {
                    category = "Child", canDrink = false
                });
            }
        }
Ejemplo n.º 5
0
        public async Task <LogoutUserHandlerResponseDto> RunAsync(Guid clientGuid)
        {
            var client = _clientProvider.GetClient(clientGuid);

            // FYI: This would be the preferred way of fetching the logout link, if AngleSharp was able to run the JS on the page...
            //      var logoutLink = _client.Context.Active.QuerySelector<IHtmlAnchorElement>("a[id=nav-item-signout]");
            var logoutLink = client.Context.Active.QuerySelector <IHtmlAnchorElement>(AmazonConstants.LogoutHrefSelector);

            if (logoutLink == null)
            {
                return(new LogoutUserHandlerResponseDto(new ErrorDto("Failed to locate the logout link.", client.Context.Active.Source.Text)));
            }

            await logoutLink.NavigateAsync();

            return(client.Context.Active.Title == AmazonConstants.LoginPageTitle
                       ? new LogoutUserHandlerResponseDto()
                       : new LogoutUserHandlerResponseDto(new ErrorDto("Logout failed.", client.Context.Active.Source.Text)));
        }
        public async Task <LoginUserHandlerResponseDto> RunAsync(Guid clientGuid, string username, string password)
        {
            var client = _clientProvider.GetClient(clientGuid);
            await client.Context.OpenAsync(new Url(AmazonConstants.LoginPageUrl));

            var loginForm = client.Context.Active.QuerySelector <IHtmlFormElement>(AmazonConstants.LoginFormSelector);

            if (loginForm == null)
            {
                return(new LoginUserHandlerResponseDto(new ErrorDto("Failed to locate the login form.", client.Context.Active.Source.Text)));
            }

            var postData = new Dictionary <string, string>
            {
                { "email", username },
                { "password", password }
            };
            await loginForm.SubmitAsync(postData);

            return(client.Context.Active.Title == AmazonConstants.HomePageTitle
                       ? new LoginUserHandlerResponseDto()
                       : new LoginUserHandlerResponseDto(new ErrorDto("Login failed.", client.Context.Active.Source.Text)));
        }
Ejemplo n.º 7
0
        public async Task <OrderDetailsHandlerResponseDto> RunAsync(Guid clientGuid, string orderNumber)
        {
            var client = _clientProvider.GetClient(clientGuid);

            // TODO - hier "orderId" statt "orderID" schreiben, um eine Amazon-Seite durch den Anonymizer zu jagen....
            var uri = new UriBuilder(AmazonConstants.OrderDetailsPageUrl)
            {
                Query = $"orderID={orderNumber}"
            };
            await client.Context.OpenAsync(new Url(uri.ToString()));

            if (client.Context.Active.Title != AmazonConstants.OrderDetailsPageTitle)
            {
                return(new OrderDetailsHandlerResponseDto(new ErrorDto("Failed to open the order details page.", client.Context.Active.Source.Text)));
            }

            var orderItems = new List <ItemDto>();

            // The order details page has infos about each ordered item.
            foreach (var orderItemElement in client.Context.Active.QuerySelectorAll <IHtmlDivElement>("div[class='a-fixed-left-grid-col a-col-right']")
                     )
            {
                // Each ordered item must have 6 property elements.
                var propertyElements = orderItemElement.QuerySelectorAll <IHtmlDivElement>("div[class=a-row]").ToArray();
                if (propertyElements.Length != 6)
                {
                    return(new OrderDetailsHandlerResponseDto(new ErrorDto("Failed to parse the order details page.", client.Context.Active.Source.Text)));
                }

                var itemDescription = propertyElements[0].Text().Trim();
                var itemPrice       = propertyElements[3].Text().Trim();
                orderItems.Add(new ItemDto(itemDescription, itemPrice));
            }

            return(new OrderDetailsHandlerResponseDto(orderItems));
        }
 public CrdRegistrar(ILogger <CrdRegistrar> logger, IClientProvider clientProvider, IContentTypeProvider contentTypeProvider)
 {
     Logger = logger;
     Client = clientProvider.GetClient();
     ContentTypeProvider = contentTypeProvider;
 }
 public DocumentDeleter(IClientProvider clientProvider)
 {
     Client = clientProvider.GetClient();
 }
 public DocumentCreator(ILogger <DocumentCreator> logger, IClientProvider clientProvider)
 {
     Logger = logger;
     Client = clientProvider.GetClient();
 }
Ejemplo n.º 11
0
        public object CreateClient(string configurationName)
        {
            var client = _provider.GetClient(configurationName);

            return(client);
        }