public void SetUp()
 {
     _apiConnectionSettings = new ApiConnectionSettings
     {
         MainServer = new ApiConnectionServer
         {
             Host = "main_server"
         },
         CacheServers = new[]
         {
             new ApiConnectionServer
             {
                 Host = "cache_server_1"
             },
             new ApiConnectionServer
             {
                 Host = "cache_server_2"
             }
         }
     };
 }
        public void Execute(CancellationToken cancellationToken)
        {
            DebugLogger.Log("Trying to geolocate current host...");

            try
            {
                string responseString = null;
                JToken jToken         = null;

#if UNITY_STANDALONE
                var eventWaitHandle = UnityDispatcher.Invoke(() =>
                {
                    var www       = new WWW("https://ip2loc.patchkit.net/v1/country");
                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    while (!www.isDone)
                    {
                        if (stopwatch.ElapsedMilliseconds >= Timeout)
                        {
                            break;
                        }
                    }

                    if (!www.isDone)
                    {
                        DebugLogger.LogError("Timeout while getting country code");
                        return;
                    }

                    responseString = www.text;
                    jToken         = JToken.Parse(www.text);
                });
                eventWaitHandle.WaitOne();
#else
                ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;

                var apiConnectionSettings = new ApiConnectionSettings
                {
                    CacheServers = new string[0],
                    MainServer   = "ip2loc.patchkit.net",
                    Timeout      = Timeout,
                    UseHttps     = true,
                    Port         = 443
                };

                var apiConnection = new ApiConnection(apiConnectionSettings);
                DebugLogger.Log("aaa");
                ServicePointManager.ServerCertificateValidationCallback += CertificateValidationCallBack;
                var countryResponse = apiConnection.GetResponse("/v1/country", null);

                responseString = countryResponse.Body;
                jToken         = countryResponse.GetJson();
#endif

                if (jToken.Value <string>("country") != null)
                {
                    CountryCode    = jToken.Value <string>("country");
                    HasCountryCode = !string.IsNullOrEmpty(CountryCode);

                    if (HasCountryCode)
                    {
                        DebugLogger.LogFormat("Geolocation succeeded! Country code: '{0}'", CountryCode);
                    }
                    else
                    {
                        DebugLogger.LogWarning("Geolocation succeeded, but empty country code received.");
                    }
                }
                else
                {
                    DebugLogger.LogErrorFormat("Cannot find 'country' key in response json: {0}", responseString);
                }
            }
            catch (Exception ex)
            {
                DebugLogger.LogErrorFormat("Error while trying to geolocate: " + ex.Message);
                DebugLogger.LogException(ex);
            }
        }
Beispiel #3
0
 public SiteService(IOptions <ApiConnectionSettings> connectionSettings, ISiteRepository repository, IMapper mapper)
 {
     _connectionSettings = connectionSettings.Value;
     _repository         = repository;
     _mapper             = mapper;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="KeysApiConnection"/> class.
 /// </summary>
 /// <param name="connectionSettings">The connection settings.</param>
 public KeysApiConnection(ApiConnectionSettings connectionSettings) : base(connectionSettings)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MainApiConnection"/> class.
 /// </summary>
 /// <param name="connectionSettings">The connection settings.</param>
 public MainApiConnection(ApiConnectionSettings connectionSettings) : base(connectionSettings)
 {
 }
Beispiel #6
0
 public ConfigurationController(ILogger <ConfigurationController> logger, IOptions <RemoteConfig> remoteConfig, IOptions <ApiConnectionSettings> apiConnection)
 {
     _logger                = logger;
     _remoteConfig          = remoteConfig.Value;
     _apiConnectionSettings = apiConnection.Value;
 }