Exemple #1
0
 public EnvironmentSetting(SdkEnvironment environment, string mqHost, string apiHost, bool onlySsl, List <SdkEnvironment> environmentRetryList = null)
 {
     Environment          = environment;
     MqHost               = mqHost;
     ApiHost              = apiHost;
     OnlySsl              = onlySsl;
     EnvironmentRetryList = environmentRetryList ?? new List <SdkEnvironment>();
 }
        /// <summary>
        /// Gets the API host for specified <see cref="SdkEnvironment"/>
        /// </summary>
        /// <param name="environment">The environment</param>
        /// <returns>The API host for specified <see cref="SdkEnvironment"/></returns>
        public static string GetApiHost(SdkEnvironment environment)
        {
            var setting = EnvironmentSettings.Find(f => f.Environment.Equals(environment));

            if (setting != null)
            {
                return(setting.ApiHost);
            }

            return(string.Empty);
        }
Exemple #3
0
        /// <summary>
        /// Loads the whoami endpoint data
        /// </summary>
        /// <param name="hostName">The host name</param>
        /// <param name="useSsl">Value indicating whether a secure connection should be attempted</param>
        /// <param name="rethrow">Value indicating whether caught exceptions should be rethrown</param>
        /// <param name="environment">Get data for selected environment</param>
        /// <returns>True if data was successfully retrieved. False otherwise. May throw <see cref="CommunicationException"/></returns>
        private bool LoadWhoamiData(string hostName, bool useSsl, bool rethrow, SdkEnvironment environment)
        {
            Guard.Argument(hostName, nameof(hostName)).NotNull().NotEmpty();

            var hostUrl = useSsl
                              ? "https://" + hostName
                              : "http://" + hostName;

            try
            {
                ExecutionLog.LogInformation($"Attempting to retrieve whoami data. Host URL={hostUrl}, Environment={Enum.GetName(typeof(SdkEnvironment), environment)}");
                var bookmakerDetailsDTO = _bookmakerDetailsProvider.GetData(hostUrl);
                ExecutionLog.LogInformation($"Whoami data successfully retrieved. Host URL={hostUrl}, Environment={Enum.GetName(typeof(SdkEnvironment), environment)}");
                _bookmakerDetails = new BookmakerDetails(bookmakerDetailsDTO);
                ApiHost           = hostName;

                if (_bookmakerDetails.ServerTimeDifference > TimeSpan.FromSeconds(5))
                {
                    ExecutionLog.LogError($"Machine time is out of sync for {_bookmakerDetails.ServerTimeDifference.TotalSeconds} sec. It may produce unwanted results with time sensitive operations within sdk.");
                }
                else if (_bookmakerDetails.ServerTimeDifference > TimeSpan.FromSeconds(2))
                {
                    ExecutionLog.LogWarning($"Machine time is out of sync for {_bookmakerDetails.ServerTimeDifference.TotalSeconds} sec. It may produce unwanted results with time sensitive operations within sdk.");
                }

                return(true);
            }
            catch (Exception ex)
            {
                ExecutionLog.LogInformation($"Failed to retrieve whoami data. Host URL={hostUrl}, Environment={Enum.GetName(typeof(SdkEnvironment), environment)}", ex);
                if (rethrow)
                {
                    throw;
                }
                return(false);
            }
        }
        public OddsFeedConfiguration(
            string accessToken,
            SdkEnvironment environment,
            CultureInfo defaultCulture,
            List <CultureInfo> wantedCultures,
            string host,
            string virtualHost,
            int port,
            string username,
            string password,
            string apiHost,
            bool useSsl,
            bool useApiSsl,
            int inactivitySeconds,
            int maxRecoveryExecutionInSeconds,
            int minIntervalBetweenRecoveryRequests,
            int nodeId,
            List <int> disabledProducers,
            ExceptionHandlingStrategy exceptionHandlingStrategy,
            bool adjustAfterAge,
            int httpClientTimeout,
            int recoveryHttpClientTimeout,
            IOddsFeedConfigurationSection section)
        {
            Guard.Argument(accessToken, nameof(accessToken)).NotNull().NotEmpty();
            Guard.Argument(defaultCulture, nameof(defaultCulture)).NotNull();
            Guard.Argument(inactivitySeconds, nameof(inactivitySeconds)).InRange(SdkInfo.MinInactivitySeconds, SdkInfo.MaxInactivitySeconds);
            Guard.Argument(maxRecoveryExecutionInSeconds, nameof(maxRecoveryExecutionInSeconds)).Min(SdkInfo.MinRecoveryExecutionInSeconds);
            Guard.Argument(minIntervalBetweenRecoveryRequests, nameof(minIntervalBetweenRecoveryRequests)).InRange(SdkInfo.MinIntervalBetweenRecoveryRequests, SdkInfo.MaxIntervalBetweenRecoveryRequests);
            Guard.Argument(httpClientTimeout, nameof(httpClientTimeout)).InRange(SdkInfo.MinHttpClientTimeout, SdkInfo.MaxHttpClientTimeout);
            Guard.Argument(recoveryHttpClientTimeout, nameof(recoveryHttpClientTimeout)).InRange(SdkInfo.MinHttpClientTimeout, SdkInfo.MaxHttpClientTimeout);

            AccessToken   = accessToken;
            Environment   = environment;
            DefaultLocale = defaultCulture;
            var locales = new List <CultureInfo>();

            if (wantedCultures != null && wantedCultures.Any())
            {
                locales.AddRange(wantedCultures);
            }
            if (locales.Contains(defaultCulture))
            {
                locales.Remove(defaultCulture);
            }
            locales.Insert(0, defaultCulture);
            Locales           = new List <CultureInfo>(locales.Distinct());
            Host              = host;
            VirtualHost       = virtualHost;
            Port              = port;
            Username          = string.IsNullOrEmpty(username) ? accessToken : username;
            Password          = password;
            UseSsl            = useSsl;
            ApiHost           = apiHost;
            UseApiSsl         = useApiSsl;
            InactivitySeconds = inactivitySeconds;
            MaxRecoveryTime   = maxRecoveryExecutionInSeconds;
            MinIntervalBetweenRecoveryRequests = minIntervalBetweenRecoveryRequests;
            NodeId = nodeId;
            if (nodeId < 0)
            {
                _executionLog.Warn($"Setting nodeId to {nodeId}. Use only positive numbers; negative are reserved for internal use.");
            }
            DisabledProducers = disabledProducers != null && disabledProducers.Any()
                ? new List <int>(disabledProducers)
                : null;
            ExceptionHandlingStrategy = exceptionHandlingStrategy;
            AdjustAfterAge            = adjustAfterAge;
            HttpClientTimeout         = httpClientTimeout;
            RecoveryHttpClientTimeout = recoveryHttpClientTimeout;
            Section = section;
        }
Exemple #5
0
        public OddsFeedConfiguration(
            string accessToken,
            SdkEnvironment environment,
            CultureInfo defaultCulture,
            List <CultureInfo> wantedCultures,
            string host,
            string virtualHost,
            int port,
            string username,
            string password,
            string apiHost,
            bool useSsl,
            bool useApiSsl,
            int inactivitySeconds,
            int maxRecoveryExecutionInSeconds,
            int nodeId,
            List <int> disabledProducers,
            ExceptionHandlingStrategy exceptionHandlingStrategy,
            bool adjustAfterAge,
            IOddsFeedConfigurationSection section)
        {
            Contract.Requires(!string.IsNullOrEmpty(accessToken));
            Contract.Requires(defaultCulture != null);
            Contract.Requires(inactivitySeconds >= SdkInfo.MinInactivitySeconds && inactivitySeconds <= SdkInfo.MaxInactivitySeconds);

            AccessToken   = accessToken;
            Environment   = environment;
            DefaultLocale = defaultCulture;
            var locales = new List <CultureInfo>();

            if (wantedCultures != null && wantedCultures.Any())
            {
                locales.AddRange(wantedCultures);
            }
            if (locales.Contains(defaultCulture))
            {
                locales.Remove(defaultCulture);
            }
            locales.Insert(0, defaultCulture);
            Locales           = new List <CultureInfo>(locales.Distinct());
            Host              = host;
            VirtualHost       = virtualHost;
            Port              = port;
            Username          = string.IsNullOrEmpty(username) ? accessToken : username;
            Password          = password;
            UseSsl            = useSsl;
            ApiHost           = apiHost;
            UseApiSsl         = useApiSsl;
            InactivitySeconds = inactivitySeconds;
            MaxRecoveryTime   = maxRecoveryExecutionInSeconds;
            NodeId            = nodeId;
            if (nodeId < 0)
            {
                _executionLog.Warn($"Setting nodeId to {nodeId}. Use only positive numbers; negative are reserved for internal use.");
            }
            DisabledProducers = disabledProducers != null && disabledProducers.Any()
                ? new List <int>(disabledProducers)
                : null;
            ExceptionHandlingStrategy = exceptionHandlingStrategy;
            AdjustAfterAge            = adjustAfterAge;
            Section = section;
        }
 /// <inheritdoc />
 public IConfigurationBuilder SelectEnvironment(SdkEnvironment ufEnvironment)
 {
     return(new ConfigurationBuilder(_accessToken, _sectionProvider, ufEnvironment));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationBuilder"/> class
 /// </summary>
 /// <param name="accessToken">An access token used to authenticate with the feed</param>
 /// <param name="sectionProvider">A <see cref="IConfigurationSectionProvider"/> used to access <see cref="IOddsFeedConfigurationSection"/></param>
 /// <param name="environment">An <see cref="SdkEnvironment"/> specifying the selected environment</param>
 public ConfigurationBuilder(string accessToken, IConfigurationSectionProvider sectionProvider, SdkEnvironment environment)
     : base(accessToken, sectionProvider)
 {
     _environment = environment;
 }
        /// <summary>
        /// Gets the MQ and API settings for specified <see cref="SdkEnvironment"/>
        /// </summary>
        /// <param name="environment">The environment</param>
        /// <returns>The MQ and API settings for specified <see cref="SdkEnvironment"/></returns>
        public static EnvironmentSetting GetSetting(SdkEnvironment environment)
        {
            var setting = EnvironmentSettings.Find(f => f.Environment.Equals(environment));

            return(setting);
        }