/// <summary> /// Registers an external event. /// </summary> /// <param name="ExternalEvent">External event.</param> public void Register(IExternalEvent ExternalEvent) { if (this.externalEvents is null) { this.externalEvents = new LinkedList <IExternalEvent>(); } this.externalEvents.AddLast(ExternalEvent); }
/// <summary> /// Tries to get an external event, given its name. /// </summary> /// <param name="Name">Name of external event.</param> /// <param name="ExternalEvent">External event object.</param> /// <returns>If an external event with the corresponding name was found.</returns> public bool TryGetExternalEvent(string Name, out IExternalEvent ExternalEvent) { if (this.externalEvents is null) { ExternalEvent = null; return(false); } else { return(this.externalEvents.TryGetValue(Name, out ExternalEvent)); } }
public async Task Publish(IExternalEvent @event) { using (var p = new ProducerBuilder <string, string>(config.ProducerConfig).Build()) { // publish event to kafka topic taken from config await p.ProduceAsync(config.Topic, new Message <string, string> { // store event type name in message Key Key = @event.GetType().Name, // serialize event to message Value Value = JsonConvert.SerializeObject(@event) }); } }
/// <summary> /// Registers an external event on the actor. /// </summary> /// <param name="ExternalEvent">External event</param> public void Register(IExternalEvent ExternalEvent) { string Name = ExternalEvent.Name; if (this.externalEvents is null) { this.externalEvents = new Dictionary <string, IExternalEvent>(); } if (this.externalEvents.ContainsKey(Name)) { throw new Exception("External event named " + Name + " already registered on actor " + this.id); } else { this.externalEvents[Name] = ExternalEvent; } }
public Task Publish(IExternalEvent @event) { return(Task.CompletedTask); }
public Task Publish(IExternalEvent @event, CancellationToken cancellationToken = default) { return(Task.CompletedTask); }
public Task Publish(IExternalEvent @event) { PublishedEvents.Add(@event); return(Task.CompletedTask); }
public void ReactOnEvent(IExternalEvent externalEvent) { ITamagotchiState tamagotchiState; _externalEventReaction.React(externalEvent, State, out tamagotchiState); State = tamagotchiState; }