/// <summary> /// Add a single event to the specified collection. /// </summary> /// <param name="collection">Collection name</param> /// <param name="eventInfo">The event to add.</param> /// <param name="addOns">Optional collection of Data Enhancement Add-ons</param> public async Task AddEventAsync(string collection, object eventInfo, IEnumerable <AddOn> addOns = null) { // Preconditions KeenUtil.ValidateEventCollectionName(collection); if (null == eventInfo) { throw new KeenException("Event data is required."); } if (string.IsNullOrWhiteSpace(_prjSettings.WriteKey)) { throw new KeenException("Write API key is required for AddEvent"); } var jEvent = PrepareUserObject(eventInfo, addOns); // If an event cache has been provided, cache this event insead of sending it. if (null != EventCache) { await EventCache.Add(new CachedEvent(collection, jEvent)) .ConfigureAwait(false); } else { await EventCollection.AddEvent(collection, jEvent) .ConfigureAwait(false); } }
public void Raise(IDomainEvent domainEvent) { WriteLog($"Raising Event {domainEvent.GetType()}"); // Cache event if (FiTechCoreExtensions.StdoutEventHubLogs) { domainEvent.d_RaiseOrigin = Environment.StackTrace; } domainEvent.EventsHub = this; lock (EventCache) { if (EventCache.Any(x => x.RID == domainEvent.RID)) { return; } EventCache.RemoveAll(e => (DateTime.UtcNow - e.TimeStamp) > EventCacheDuration); } // Raise event on all listeners. List <IDomainEventListener> listeners; lock (Listeners) { Listeners.RemoveAll(l => l == null); listeners = Listeners.ToList(); } foreach (var listener in listeners) { MainQueuer.Enqueue(async() => { await listener.OnEventTriggered(domainEvent).ConfigureAwait(false); if (domainEvent.AllowPropagation) { parentHub?.Raise(domainEvent); } }, async x => { try { await listener.OnEventHandlingError(domainEvent, x).ConfigureAwait(false); } catch (Exception y) { Fi.Tech.Throw(x); } }, (b) => { return(Fi.Result()); }); } if (EnableEventCache) { lock (EventCache) { domainEvent.TimeStamp = DateTime.UtcNow; EventCache.Add(domainEvent); } LastEventDateTime = Fi.Tech.GetUtcTime(); CancelationTokenSource.Cancel(); CancelationTokenSource = new CancellationTokenSource(); } }
/// <summary> /// Tracks an event from an interaction. Adds it to the cache if set, and fires event /// </summary> /// <param name="view"></param> /// <param name="gesture"></param> private void TrackEvent(View view, GestureType gesture) { var uiEvent = new UIEvent { Gesture = gesture, Id = Guid.NewGuid(), EventTime = DateTime.UtcNow, ViewObject = view }; if (IsUsingCache) { EventCache.Add(uiEvent); } OnInteractionDetected?.Invoke(this, new InteractionEventArgs(uiEvent)); }