public async Task Handle(ClientRegisteredEvent evt, ICommandSender commandSender)
        {
            try
            {
                string countryCode = null;

                if (!string.IsNullOrEmpty(evt.CountryFromPOA))
                {
                    _log.Info(nameof(ClientRegisteredEvent), $"Getting country '{evt.CountryFromPOA}' from the message", evt.ClientId);
                    countryCode = evt.CountryFromPOA;
                }
                else if (!string.IsNullOrEmpty(evt.Ip))
                {
                    _log.Info(nameof(ClientRegisteredEvent), $"Try to get country by IP address '{evt.Ip}'", evt.ClientId);
                    IIpGeolocationData data = await _geoLocationClient.GetAsync(evt.Ip);

                    countryCode = data?.CountryCode;

                    if (string.IsNullOrEmpty(countryCode))
                    {
                        _log.Warning(nameof(ClientRegisteredEvent), $"Can not find country by IP address '{evt.Ip}'.", context: evt.ClientId);
                    }
                    else
                    {
                        _log.Info(nameof(ClientRegisteredEvent), $"Country '{data.CountryCode}'.", evt.ClientId);
                    }
                }

                if (!string.IsNullOrEmpty(countryCode))
                {
                    await _clientRegulationService.SetDefaultAsync(evt.ClientId, countryCode);
                }
            }
            catch (ServiceException exception)
            {
                _log.Error(nameof(ClientRegisteredEvent), exception, context: evt.ClientId);
            }
        }
Example #2
0
 protected void Apply(ClientRegisteredEvent @event)
 {
     Id = @event.AggregateId;
     _isActive = true;
     _notificationChannel = @event.NotificationChannel;
 }