Beispiel #1
0
        /// <summary>
        /// Adds the standard NV Pairs to the payload and stitches any available
        /// contexts to the final payload.
        /// </summary>
        /// <param name="payload">The basee event payload</param>
        /// <param name="contexts">The contexts array</param>
        /// <param name="eventId">The event ID</param>
        private void CompleteAndTrackPayload(Payload payload, List <IContext> contexts, string eventId)
        {
            payload.AddDict(_standardNvPairs);

            // Add the subject data if available
            if (_subject != null)
            {
                payload.AddDict(_subject._payload.Payload);
            }

            // Add the session context if available
            if (_clientSession != null)
            {
                contexts.Add(_clientSession.GetSessionContext(eventId));
            }

            // Add the desktop context if available
            if (_desktopContextDelegate != null)
            {
                DesktopContext desktopContext = _desktopContextDelegate.Invoke();
                if (desktopContext != null)
                {
                    contexts.Add(desktopContext);
                }
            }

            // Add the mobile context if available
            if (_mobileContextDelegate != null)
            {
                MobileContext mobileContext = _mobileContextDelegate.Invoke();
                if (mobileContext != null)
                {
                    contexts.Add(mobileContext);
                }
            }

            // Add the geo-location context if available
            if (_geoLocationDelegate != null)
            {
                GeoLocationContext geoLocationContext = _geoLocationDelegate.Invoke();
                if (geoLocationContext != null)
                {
                    contexts.Add(geoLocationContext);
                }
            }

            // Build the final context and it to the payload
            if (contexts != null && contexts.Any())
            {
                var contextArray = new List <Dictionary <string, object> >();
                foreach (IContext context in contexts)
                {
                    contextArray.Add(context.GetJson().Payload);
                }
                var contextEnvelope = new SelfDescribingJson(Constants.SCHEMA_CONTEXTS, contextArray);
                payload.AddJson(contextEnvelope.Payload, _encodeBase64, Constants.CONTEXT_ENCODED, Constants.CONTEXT);
            }

            // Send the payload to the emitter
            if (_synchronous)
            {
                _emitter.Input(payload);
            }
            else
            {
                Task.Factory.StartNew(() => _emitter.Input(payload));
            }
        }