Ejemplo n.º 1
0
        public void TestHttpClientDefaults()
        {
            var http = HttpClientHelpers.Create();

            Assert.AreEqual(HttpClientHelpers.DefaultTimeout, http.Timeout);
            Assert.AreEqual(HttpClientHelpers.UserAgentString(), String.Join(" ", http.DefaultRequestHeaders.UserAgent.Select(x => x.ToString())));
        }
 internal RandomOrgExternalRandomSource(bool useDiskSourceForUnitTests, Guid apiKey)
     : base(TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero)
 {
     this._UserAgent = HttpClientHelpers.UserAgentString();
     this._UseDiskSourceForUnitTests = useDiskSourceForUnitTests;
     this._ApiKey = apiKey;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a user-agent string to use with HTTP requests.
        /// </summary>
        /// <param name="usageIdentifier">An email address, website, or other identifying mark to include.</param>
        /// <exception cref="System.Exception">May throw if the usageIdentifier has invalid characters.</exception>
        public static string UserAgent(string usageIdentifier)
        {
            var id   = (usageIdentifier ?? "unconfigured").Replace("@", ".AT.");
            var ua   = HttpClientHelpers.UserAgentString(id);
            var http = HttpClientHelpers.Create(userAgent: ua);

            http.Dispose();
            return(ua);
        }
Ejemplo n.º 4
0
        public QrngEthzChExternalRandomSource(string userAgent, int bytesPerRequest, TimeSpan periodNormalPriority, TimeSpan periodHighPriority, TimeSpan periodLowPriority)
            : base(periodNormalPriority, periodHighPriority, periodLowPriority)
        {
            if (bytesPerRequest < 4 || bytesPerRequest > 2048)      // No published maximum, but we'll be nice.
            {
                throw new ArgumentOutOfRangeException(nameof(bytesPerRequest), bytesPerRequest, "Bytes per request must be between 4 and 2048");
            }

            this._UserAgent       = String.IsNullOrWhiteSpace(userAgent) ? HttpClientHelpers.UserAgentString() : userAgent;
            this._BytesPerRequest = bytesPerRequest;
        }
        public RandomNumbersInfoExternalRandomSource(string userAgent, int numberOfNumbers, TimeSpan periodNormalPriority, TimeSpan periodHighPriority, TimeSpan periodLowPriority)
            : base(periodNormalPriority, periodHighPriority, periodLowPriority)
        {
            if (numberOfNumbers < 0 || numberOfNumbers > 1000)
            {
                throw new ArgumentOutOfRangeException(nameof(numberOfNumbers), numberOfNumbers, "Between 1 and 1000 numbers are allowed");
            }

            this._UserAgent       = String.IsNullOrWhiteSpace(userAgent) ? HttpClientHelpers.UserAgentString() : userAgent;
            this._NumberOfNumbers = numberOfNumbers;
        }
        public RandomOrgExternalRandomSource(string userAgent, int bytesPerRequest, Guid apiKey, TimeSpan periodNormalPriority, TimeSpan periodHighPriority, TimeSpan periodLowPriority)
            : base(periodNormalPriority, periodHighPriority, periodLowPriority)
        {
            if (bytesPerRequest < 4 || bytesPerRequest > 4096)
            {
                throw new ArgumentOutOfRangeException(nameof(bytesPerRequest), bytesPerRequest, "Bytes per request must be between 4 and 4096");
            }

            this._UserAgent       = String.IsNullOrWhiteSpace(userAgent) ? HttpClientHelpers.UserAgentString() : userAgent;
            this._BytesPerRequest = bytesPerRequest;
            this._ApiKey          = apiKey;
        }
Ejemplo n.º 7
0
        public HotbitsExternalRandomSource(string userAgent, int bytesPerRequest, string apiKey, TimeSpan periodNormalPriority, TimeSpan periodHighPriority, TimeSpan periodLowPriority)
            : base(periodNormalPriority, periodHighPriority, periodLowPriority)
        {
            if (bytesPerRequest < 4 || bytesPerRequest > 2048)      // Max of 2048 bytes based on Web UI.
            {
                throw new ArgumentOutOfRangeException(nameof(bytesPerRequest), bytesPerRequest, "Bytes per request must be between 4 and 2048");
            }

            this._UserAgent       = String.IsNullOrWhiteSpace(userAgent) ? HttpClientHelpers.UserAgentString() : userAgent;
            this._BytesPerRequest = bytesPerRequest;
            this._ApiKey          = string.IsNullOrWhiteSpace(apiKey) ? null : apiKey;
        }
Ejemplo n.º 8
0
        public ExternalWebContentSource(string userAgent, IEnumerable <Uri> sources, TimeSpan periodNormalPriority, TimeSpan periodHighPriority, TimeSpan periodLowPriority, int serversPerSample, IRandomNumberGenerator rng)
            : base(periodNormalPriority, periodHighPriority, periodLowPriority)
        {
            if (serversPerSample <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(serversPerSample), serversPerSample, "Servers per sample must be at least one.");
            }

            this._UserAgent = String.IsNullOrWhiteSpace(userAgent) ? HttpClientHelpers.UserAgentString() : userAgent;
            this._Sources   = (sources ?? LoadInternalServerList()).ToList();
            if (_Sources.Count <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(sources), sources, "At least one source URL must be provided.");
            }

            this._ServersPerSample = serversPerSample > 0 ? serversPerSample : 4;
            this._ServersPerSample = Math.Min(_ServersPerSample, _Sources.Count);
            this._Rng = rng ?? StandardRandomWrapperGenerator.StockRandom();
            _Sources.ShuffleInPlace(_Rng);
        }
 public RandomNumbersInfoExternalRandomSource() : this(HttpClientHelpers.UserAgentString(), 256, TimeSpan.FromHours(8))
 {
 }
Ejemplo n.º 10
0
 public BeaconNistExternalRandomSource(string userAgent, TimeSpan periodNormalPriority, TimeSpan periodHighPriority, TimeSpan periodLowPriority)
     : base(periodNormalPriority, periodHighPriority, periodLowPriority)
 {
     this._UserAgent = String.IsNullOrWhiteSpace(userAgent) ? HttpClientHelpers.UserAgentString() : userAgent;
 }
Ejemplo n.º 11
0
 public BeaconNistExternalRandomSource() : this(HttpClientHelpers.UserAgentString(), TimeSpan.FromHours(4))
 {
 }
Ejemplo n.º 12
0
 internal ExternalWebContentSource(bool useDiskSourceForUnitTests)
     : this(HttpClientHelpers.UserAgentString(), null, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero, 5, null)
 {
     this._UseRandomSourceForUnitTest = useDiskSourceForUnitTests;
 }
Ejemplo n.º 13
0
 public ExternalWebContentSource() : this(HttpClientHelpers.UserAgentString(), null, TimeSpan.FromMinutes(15.0), 5)
 {
 }
 public RandomOrgExternalRandomSource() : this(HttpClientHelpers.UserAgentString(), 128, TimeSpan.FromHours(8))
 {
 }
Ejemplo n.º 15
0
 private string UnitTestUserAgent() => HttpClientHelpers.UserAgentString("TerningerUnitTests.AT.ligos.net")
 ;
Ejemplo n.º 16
0
 public QrngEthzChExternalRandomSource() : this(HttpClientHelpers.UserAgentString(), 256, TimeSpan.FromHours(8))
 {
 }
 internal RandomNumbersInfoExternalRandomSource(bool useDiskSourceForUnitTests)
     : base(TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero)
 {
     this._UserAgent = HttpClientHelpers.UserAgentString();
     this._UseDiskSourceForUnitTests = useDiskSourceForUnitTests;
 }
Ejemplo n.º 18
0
 public AnuExternalRandomSource() : this(HttpClientHelpers.UserAgentString(), TimeSpan.FromHours(12))
 {
 }