public virtual bool Track(string key, string trafficType, string eventType, double?value = null, Dictionary <string, object> properties = null) { if (_statusManager.IsDestroyed()) { return(false); } using (var clock = new Util.SplitStopwatch()) { clock.Start(); var keyResult = _keyValidator.IsValid(new Key(key, null), nameof(Track)); var eventTypeResult = _eventTypeValidator.IsValid(eventType, nameof(eventType)); var eventPropertiesResult = _eventPropertiesValidator.IsValid(properties); var trafficTypeResult = _blockUntilReadyService.IsSdkReady() ? _trafficTypeValidator.IsValid(trafficType, nameof(trafficType)) : new ValidatorResult { Success = true, Value = trafficType }; if (!keyResult || !trafficTypeResult.Success || !eventTypeResult || !eventPropertiesResult.Success) { return(false); } try { var eventToLog = new Event { key = key, trafficTypeName = trafficTypeResult.Value, eventTypeId = eventType, value = value, timestamp = CurrentTimeHelper.CurrentTimeMillis(), properties = (Dictionary <string, object>)eventPropertiesResult.Value }; _tasksManager.Start(() => { _eventsLog.Log(new WrappedEvent { Event = eventToLog, Size = eventPropertiesResult.EventSize }); }, new CancellationTokenSource(), "Track"); RecordLatency(nameof(Track), clock.ElapsedMilliseconds); return(true); } catch (Exception e) { _log.Error("Exception caught trying to track an event", e); RecordException(nameof(Track)); return(false); } } }
public virtual bool Track(string key, string trafficType, string eventType, double?value = null, Dictionary <string, object> properties = null) { if (Destroyed) { return(false); } var keyResult = _keyValidator.IsValid(new Key(key, null), nameof(Track)); var eventTypeResult = _eventTypeValidator.IsValid(eventType, nameof(eventType)); var eventPropertiesResult = _eventPropertiesValidator.IsValid(properties); var trafficTypeResult = _blockUntilReadyService.IsSdkReady() ? _trafficTypeValidator.IsValid(trafficType, nameof(trafficType)) : new ValidatorResult { Success = true, Value = trafficType }; if (!keyResult || !trafficTypeResult.Success || !eventTypeResult || !eventPropertiesResult.Success) { return(false); } try { var eventToLog = new Event { key = key, trafficTypeName = trafficTypeResult.Value, eventTypeId = eventType, value = value, timestamp = CurrentTimeHelper.CurrentTimeMillis(), properties = (Dictionary <string, object>)eventPropertiesResult.Value }; Task.Factory.StartNew(() => { _eventsLog.Log(new WrappedEvent { Event = eventToLog, Size = eventPropertiesResult.EventSize }); }); return(true); } catch (Exception e) { _log.Error("Exception caught trying to track an event", e); return(false); } }