Exemple #1
0
        /// <summary>
        /// Start a tracker with a custom emitter
        /// </summary>
        /// <param name="emitter">The emitter to send events to</param>
        /// <param name="subject">Information on the user</param>
        /// <param name="clientSession">Client sessionization object</param>
        /// <param name="trackerNamespace">Namespace of tracker</param>
        /// <param name="appId">Application ID of tracker</param>
        /// <param name="encodeBase64">Base64 encode collector parameters</param>
        /// <param name="synchronous">Whether to do I/O synchronously</param>
        /// <param name="desktopContextDelegate">Delegate for fetching the desktop context</param>
        /// <param name="mobileContextDelegate">Delegate for fetching the mobile context</param>
        /// <param name="geoLocationContextDelegate">Delegate for fetching the geo-location context</param>
        /// <param name="l">A logger to emit an activity stream to</param>
        public void Start(IEmitter emitter, Subject subject = null, ClientSession clientSession = null, string trackerNamespace = null, string appId = null,
                          bool encodeBase64 = true, bool synchronous = true, DesktopContextDelegate desktopContextDelegate      = null, MobileContextDelegate mobileContextDelegate = null,
                          GeoLocationContextDelegate geoLocationContextDelegate = null, ILogger l = null)
        {
            lock (_lock)
            {
                if (_running)
                {
                    throw new InvalidOperationException("Cannot start - already started");
                }

                _emitter = emitter;
                _emitter.Start();

                if (clientSession != null)
                {
                    _clientSession = clientSession;
                    _clientSession.StartChecker();
                }

                _subject      = subject ?? new Subject();
                _encodeBase64 = encodeBase64;
                _logger       = l ?? new NoLogging();

                _standardNvPairs = new Dictionary <string, string>
                {
                    { Constants.TRACKER_VERSION, Version.VERSION },
                    { Constants.NAMESPACE, trackerNamespace },
                    { Constants.APP_ID, appId }
                };

                _synchronous            = synchronous;
                _desktopContextDelegate = desktopContextDelegate;
                _mobileContextDelegate  = mobileContextDelegate;
                _geoLocationDelegate    = geoLocationContextDelegate;
                _running = true;
                _logger.Info("Tracker started");
            }
        }
Exemple #2
0
        /// <summary>
        /// Start a tracker with a default emitter
        /// </summary>
        /// <param name="endpoint">Hostname of your collector</param>
        /// <param name="dbPath">A filename/path to store queued events in</param>
        /// <param name="method">The method used to send events to a collector. GET or POST</param>
        /// <param name="subject">Information on the user</param>
        /// <param name="clientSession"></param>
        /// <param name="trackerNamespace">Namespace of tracker</param>
        /// <param name="appId">Application ID of tracker</param>
        /// <param name="encodeBase64">Base64 encode collector parameters</param>
        /// <param name="synchronous">Whether to do I/O synchronously</param>
        /// <param name="desktopContextDelegate">Delegate for fetching the desktop context</param>
        /// <param name="mobileContextDelegate">Delegate for fetching the mobile context</param>
        /// <param name="geoLocationContextDelegate">Delegate for fetching the geo-location context</param>
        /// <param name="l">A logger to emit an activity stream to</param>
        public void Start(string endpoint, string dbPath, HttpMethod method = HttpMethod.POST, Subject subject = null, ClientSession clientSession = null,
                          string trackerNamespace = null, string appId = null, bool encodeBase64 = true, bool synchronous = true, DesktopContextDelegate desktopContextDelegate = null,
                          MobileContextDelegate mobileContextDelegate = null, GeoLocationContextDelegate geoLocationContextDelegate = null, ILogger l = null)
        {
            AsyncEmitter emitter;

            lock (_lock)
            {
                var dest    = new SnowplowHttpCollectorEndpoint(endpoint, method: method, l: l);
                var storage = new LiteDBStorage(dbPath);
                _storage = storage;
                var queue = new PersistentBlockingQueue(storage, new PayloadToJsonString());
                emitter = new AsyncEmitter(dest, queue, l: l);
            }
            Start(emitter, subject, clientSession, trackerNamespace, appId, synchronous, encodeBase64, desktopContextDelegate, mobileContextDelegate, geoLocationContextDelegate, l);
        }