/// <summary>
        /// Initializes a new instance of the <see cref="SdkConfiguration"/> class
        /// </summary>
        public SdkConfigurationInternal(ISdkConfiguration config, IDataFetcher dataFetcher)
            : base(config.Username, config.Password, config.Host, config.VirtualHost, config.UseSsl, config.SslServerName, config.NodeId, config.BookmakerId, config.LimitId, config.Currency, config.Channel, config.AccessToken, config.UfEnvironment, config.ProvideAdditionalMarketSpecifiers, config.Port, config.ExclusiveConsumer)
        {
            Guard.Argument(config, nameof(config)).NotNull();
            ApiHost = null;

            switch (config.UfEnvironment)
            {
            case Entities.Enums.UfEnvironment.Integration:
                ApiHost = SdkInfo.ApiHostIntegration;
                return;

            case Entities.Enums.UfEnvironment.Production:
                ApiHost = SdkInfo.ApiHostProduction;
                return;
            }

            if (dataFetcher == null)
            {
                ApiHost = SdkInfo.ApiHostIntegration;
            }
            else
            {
                try
                {
                    var result = dataFetcher.GetDataAsync(new Uri($"{SdkInfo.ApiHostProduction}/v1/users/whoami.xml")).Result;
                    ApiHost = SdkInfo.ApiHostProduction;
                    result.Close();
                }
                catch (Exception)
                {
                    ApiHost = SdkInfo.ApiHostIntegration;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Fetches and deserializes the data from the provided <see cref="Uri"/>
        /// </summary>
        /// <param name="uri">A <see cref="Uri"/> specifying the data location</param>
        /// <returns>A <see cref="Task{T}"/> representing the ongoing operation</returns>
        protected async Task <T> GetDataAsyncInternal(Uri uri)
        {
            Guard.Argument(uri, nameof(uri)).NotNull();

            var stream = await _fetcher.GetDataAsync(uri).ConfigureAwait(false);

            return(_deserializer.Deserialize(stream));
        }
        /// <summary>
        ///     Fetches and deserializes the data from the provided <see cref="Uri" />
        /// </summary>
        /// <param name="uri">A <see cref="Uri" /> specifying the data location</param>
        /// <returns>A <see cref="Task{T}" /> representing the ongoing operation</returns>
        protected async Task <T> GetDataAsyncInternal(Uri uri)
        {
            Contract.Requires(uri != null);

            var stream = await _fetcher.GetDataAsync(uri).ConfigureAwait(false);

            return(_deserializer.Deserialize(stream));
        }
示例#4
0
        /// <summary>
        /// Fetches and deserializes the data from the provided <see cref="Uri"/>.
        /// </summary>
        /// <param name="authorization">The value of authorization header</param>
        /// <param name="uri">A <see cref="Uri"/> specifying the data location</param>
        /// <returns>A <see cref="Task{T}"/> representing the ongoing operation</returns>
        protected async Task <TOut> GetDataAsyncInternal(string authorization, Uri uri)
        {
            Guard.Argument(uri, nameof(uri)).NotNull();

            var stream = await _fetcher.GetDataAsync(authorization, uri).ConfigureAwait(false);

            var deserializedObject = _deserializer.Deserialize(stream);

            return(_mapperFactory.CreateMapper(deserializedObject).Map());
        }
示例#5
0
        /// <summary>
        /// Fetches and deserializes the data from the provided <see cref="Uri"/>.
        /// </summary>
        /// <param name="uri">A <see cref="Uri"/> specifying the data location</param>
        /// <returns>A <see cref="Task{T}"/> representing the ongoing operation</returns>
        protected async Task <TOut> GetDataAsyncInternal(Uri uri)
        {
            Guard.Argument(uri, nameof(uri)).NotNull();

            var stream = await _fetcher.GetDataAsync(uri).ConfigureAwait(false);

            var item = _deserializer.Deserialize(stream);

            DispatchReceivedRawApiData(uri, item);
            return(_mapperFactory.CreateMapper(item).Map());
        }
示例#6
0
        /// <summary>
        ///     Fetches and deserializes the data from the provided <see cref="Uri" />.
        /// </summary>
        /// <param name="uri">A <see cref="Uri" /> specifying the data location</param>
        /// <returns>A <see cref="Task{T}" /> representing the ongoing operation</returns>
        protected async Task <TOut> GetDataAsyncInternal(Uri uri)
        {
            Contract.Requires(uri != null);

            var stream = await _fetcher.GetDataAsync(uri).ConfigureAwait(false);

            var item = _deserializer.Deserialize(stream);

            DispatchReceivedRawApiData(uri, item);
            return(_mapperFactory.CreateMapper(item).Map());
        }
示例#7
0
        private async void StartDispatching()
        {
            var files = Directory.GetFiles(_dirPath);

            foreach (var file in files)
            {
                var stream = await _dataFetcher.GetDataAsync(new Uri(file, UriKind.Absolute));

                var unused = _deserializer.Deserialize(stream);
            }
        }
        /// <summary>
        /// Fetches and deserializes the data from the provided <see cref="Uri"/>.
        /// </summary>
        /// <param name="uri">A <see cref="Uri"/> specifying the data location</param>
        /// <param name="requestParams">The parameters associated with the request (if present)</param>
        /// <param name="culture">The language associated with the request</param>
        /// <returns>A <see cref="Task{T}"/> representing the ongoing operation</returns>
        protected async Task <TOut> GetDataAsyncInternal(Uri uri, string requestParams, string culture)
        {
            Guard.Argument(uri, nameof(uri)).NotNull();

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            var stream = await _fetcher.GetDataAsync(uri).ConfigureAwait(false);

            var item = _deserializer.Deserialize(stream);

            stopWatch.Stop();
            DispatchReceivedRawApiData(uri, item, requestParams, TimeSpan.FromMilliseconds(stopWatch.ElapsedMilliseconds), culture);
            return(_mapperFactory.CreateMapper(item).Map());
        }
示例#9
0
        public IPAddress GetPublicIp()
        {
            string data;

            try
            {
                var stream = _dataFetcher.GetDataAsync(new Uri("http://ipecho.net/plain")).Result;
                using var reader = new StreamReader(stream, Encoding.UTF8);
                data             = reader.ReadToEnd();
            }
            catch (AggregateException)
            {
                return(null);
            }

            return(IPAddress.TryParse(data, out var address)
                       ? address
                       : null);
        }
        private async Task <EntityList <NamedValueDTO> > GetDescriptionsInternalAsync(Uri uri)
        {
            var stream = await _fetcher.GetDataAsync(uri).ConfigureAwait(false);

            return(GetDescriptions(stream, uri));
        }