/// <summary>
        /// The post async.
        /// </summary>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task <BrokerEnrichmentMessage> PostAsync(BrokerEnrichmentMessage message)
        {
            this.logger.LogInformation($"get called with broker enrichment message for {Route}");
            var response = await this.PostAsync(message, Route);

            this.logger.LogInformation($"get completed with broker enrichment message for {Route}");

            return(response);
        }
Beispiel #2
0
        public async Task Get()
        {
            var repo = new BrokerApi(this.configuration, this.httpClientFactory, this.policyFactory, this.logger);

            var message = new BrokerEnrichmentMessage
            {
                Brokers = new[] { new BrokerEnrichmentDto {
                                      Name = "1010data Financial"
                                  } }
            };

            var messageResult = await repo.PostAsync(message);

            Assert.IsTrue(true);
        }
        public async Task <bool> Scan()
        {
            await _semaphoreSlimScanLock.WaitAsync();

            {
                try
                {
                    var securities = await this._marketRepository.GetUnEnrichedSecurities();

                    var brokers = await this._orderBrokerRepository.GetUnEnrichedBrokers();

                    var scanTokenSource = new CancellationTokenSource(10000);
                    var apiCheck        = await this._api.HeartBeatingAsync(scanTokenSource.Token);

                    if (!apiCheck)
                    {
                        this._logger.LogError(
                            "Enrichment Service was about to enrich a scan but found the enrichment api to be unresponsive.");
                        return(false);
                    }

                    var response = false;

                    if (securities != null && securities.Any())
                    {
                        var enrichmentResponse = await Enrich(securities);

                        await this._marketRepository.UpdateUnEnrichedSecurities(enrichmentResponse?.Securities);

                        response = enrichmentResponse?.Securities?.Any() ?? false;
                    }

                    if (brokers != null && brokers.Any())
                    {
                        var message = new BrokerEnrichmentMessage
                        {
                            Brokers = brokers?.Select(
                                _ => new BrokerEnrichmentDto
                            {
                                CreatedOn  = _.CreatedOn,
                                ExternalId = _.ReddeerId,
                                Id         = _.Id,
                                Live       = _.Live,
                                Name       = _.Name
                            }).ToArray()
                        };

                        this._logger.LogInformation("We need to add enrichment for brokers");

                        var enrichmentResponse = await this._brokerApi.PostAsync(message);

                        await this._orderBrokerRepository.UpdateEnrichedBroker(enrichmentResponse.Brokers);

                        response = true;
                    }

                    return(response);
                }
                catch (Exception ex)
                {
                    this._logger.LogError(ex, $"Error while Scan {nameof(Scan)} ");
                    return(false);
                }
                finally
                {
                    _semaphoreSlimScanLock.Release();
                }
            }
        }