Exemple #1
0
        /// <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);
        }
Exemple #2
0
 /// <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));
     }
 }
Exemple #3
0
 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)
         });
     }
 }
Exemple #4
0
        /// <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;
            }
        }
Exemple #5
0
 public Task Publish(IExternalEvent @event)
 {
     return(Task.CompletedTask);
 }
Exemple #6
0
 public Task Publish(IExternalEvent @event, CancellationToken cancellationToken = default)
 {
     return(Task.CompletedTask);
 }
        public Task Publish(IExternalEvent @event)
        {
            PublishedEvents.Add(@event);

            return(Task.CompletedTask);
        }
Exemple #8
0
 public void ReactOnEvent(IExternalEvent externalEvent)
 {
     ITamagotchiState tamagotchiState;
     _externalEventReaction.React(externalEvent, State, out tamagotchiState);
     State = tamagotchiState;
 }