Esempio n. 1
0
        public UTSession
        (
            IUTSessionConfig config,
            IUTInteraction defaultInteraction,
            string deviceIdentifier,
            string uTTokenValue,
            IUTGrammar grammar = null
        )
        {
            if (null == config)
            {
                throw new ArgumentNullException(nameof(UTSession), " config can not be null");
            }

            if (grammar == null)
            {
                grammar = UTGrammar.UTV1Grammar();
            }

            this.utGrammar = grammar;

            this.defaultInteraction      = defaultInteraction;
            this.defaultDeviceIdentifier = deviceIdentifier;

            this.sessionConfig = config.SessionConfigShallowCopy();
            this.requestMerger = new UserRequestMerger(this.sessionConfig, this.defaultDeviceIdentifier);

            this.uTTokenValue = uTTokenValue;

            this.cookies = new CookieContainer();
            this.handler = new HttpClientHandler();
            this.handler.CookieContainer = cookies;
            this.httpClient = new HttpClient(this.handler);
        }
        private IUTEvent ApplyDeviceIdentifier(IUTEvent utEvent)
        {
            string deviceInfoKey   = UTGrammar.UTV1Grammar().DeviceIdentifierKeyValue;
            string deviceInfoValue = null;

            Dictionary <string, string> mergedCustomValues = utEvent.CustomValues;

            if (mergedCustomValues == null)
            {
                mergedCustomValues = new Dictionary <string, string>();
            }

            if (mergedCustomValues.ContainsKey(deviceInfoKey))
            {
                deviceInfoValue = mergedCustomValues[deviceInfoKey];
            }

            if (this.defaultDeviceIdentifier == null || deviceInfoValue != null)
            {
                return(utEvent);
            }

            mergedCustomValues.Add(deviceInfoKey, this.defaultDeviceIdentifier);

            IUTEvent mergedEvent = new UTEvent(
                utEvent.Timestamp,
                mergedCustomValues,
                utEvent.DefinitionId,
                utEvent.ItemId,
                utEvent.EngagementValue,
                utEvent.ParentEventId,
                utEvent.Text,
                utEvent.Duration,
                utEvent.TrackingInteractionId,
                utEvent.type
                );

            return(mergedEvent);
        }