Exemplo n.º 1
0
        // *** constructor ***

        /// <summary>
        /// Creates a new instance of type Beacon
        /// </summary>
        /// <param name="logger">Logger for logging messages</param>
        /// <param name="cache">Cache storing beacon related data</param>
        /// <param name="configuration">OpenKit related configuration</param>
        /// <param name="clientIPAddress">The client's IP address</param>
        /// <param name="threadIdProvider">Provider for retrieving thread id</param>
        /// <param name="timingProvider">Provider for time related methods</param>
        public Beacon(ILogger logger, BeaconCache beaconCache, OpenKitConfiguration configuration, string clientIPAddress,
                      IThreadIDProvider threadIDProvider, ITimingProvider timingProvider)
        {
            this.logger         = logger;
            this.beaconCache    = beaconCache;
            this.sessionNumber  = configuration.NextSessionNumber;
            this.timingProvider = timingProvider;

            this.configuration    = configuration;
            this.threadIDProvider = threadIDProvider;
            this.sessionStartTime = timingProvider.ProvideTimestampInMilliseconds();

            if (InetAddressValidator.IsValidIP(clientIPAddress))
            {
                this.clientIPAddress = clientIPAddress;
            }
            else
            {
                this.clientIPAddress = string.Empty;
            }

            // store the current http configuration
            this.httpConfiguration = configuration.HTTPClientConfig;

            basicBeaconData = CreateBasicBeaconData();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of type Beacon
        /// </summary>
        /// <param name="initializer">provider of relevant parameters to initialize / create the beacon</param>
        /// <param name="configuration">OpenKit related configuration</param>
        internal Beacon(IBeaconInitializer initializer, IBeaconConfiguration configuration)
        {
            beaconCache = initializer.BeaconCache;

            var beaconId = initializer.SessionIdProvider.GetNextSessionId();

            SessionSequenceNumber = initializer.SessionSequenceNumber;
            beaconKey             = new BeaconKey(beaconId, SessionSequenceNumber);
            SessionNumber         = DetermineSessionNumber(configuration, beaconId);

            this.configuration = configuration;
            threadIdProvider   = initializer.ThreadIdProvider;
            timingProvider     = initializer.TimingProvider;
            SessionStartTime   = timingProvider.ProvideTimestampInMilliseconds();

            DeviceId = CreateDeviceId(configuration, initializer.RandomNumberGenerator);

            TrafficControlValue = initializer.RandomNumberGenerator.NextPercentageValue();

            logger = initializer.Logger;
            var ipAddress = initializer.ClientIpAddress;

            if (ipAddress == null)
            {
                // A client IP address, which is a null, is valid.
                // The real IP address is determined on the server side.
                clientIpAddress = null;
            }
            else if (InetAddressValidator.IsValidIP(ipAddress))
            {
                clientIpAddress = ipAddress;
            }
            else
            {
                if (logger.IsWarnEnabled)
                {
                    logger.Warn($"Beacon: Client IP address validation failed: {ipAddress}");
                }
                clientIpAddress = null; // determined on server side, based on remote IP address
            }

            basicBeaconData = CreateBasicBeaconData();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new instance of type Beacon
        /// </summary>
        /// <param name="logger">Logger for logging messages</param>
        /// <param name="cache">Cache storing beacon related data</param>
        /// <param name="configuration">OpenKit related configuration</param>
        /// <param name="clientIPAddress">The client's IP address</param>
        /// <param name="threadIdProvider">Provider for retrieving thread id</param>
        /// <param name="timingProvider">Provider for time related methods</param>
        /// <param name="randomNumberGenerator">Random number generator</param>
        internal Beacon(ILogger logger, BeaconCache beaconCache, OpenKitConfiguration configuration, string clientIPAddress,
                        IThreadIDProvider threadIDProvider, ITimingProvider timingProvider, IPRNGenerator randomNumberGenerator)
        {
            this.logger         = logger;
            this.beaconCache    = beaconCache;
            BeaconConfiguration = configuration.BeaconConfig;

            if (beaconConfiguration.DataCollectionLevel == DataCollectionLevel.USER_BEHAVIOR)
            {
                SessionNumber = configuration.NextSessionNumber;
                DeviceID      = Truncate(configuration.DeviceID);
            }
            else
            {
                SessionNumber = 1;
                DeviceID      = randomNumberGenerator.NextLong(long.MaxValue)
                                .ToString(CultureInfo.InvariantCulture);
            }

            this.timingProvider = timingProvider;

            this.configuration         = configuration;
            this.threadIDProvider      = threadIDProvider;
            this.randomNumberGenerator = randomNumberGenerator;
            sessionStartTime           = timingProvider.ProvideTimestampInMilliseconds();

            if (InetAddressValidator.IsValidIP(clientIPAddress))
            {
                this.clientIPAddress = clientIPAddress;
            }
            else
            {
                this.clientIPAddress = string.Empty;
            }
            // store the current http configuration
            httpConfiguration = configuration.HTTPClientConfig;
            basicBeaconData   = CreateBasicBeaconData();
        }