Ejemplo n.º 1
0
        public async Task ProcessEvent(IEventData e)
        {
            if (netMon.State == NetworkState.Sync)
            {
                throw new Exception("Engine is syncing");
            }

            var reactions = await GetReactionsFor(e);

            var queue = new Queue <Effect>();

            try {
                foreach (var handler in reactions)
                {
                    var effect = await handler(e);

                    queue.Enqueue(effect);
                }
            }
            catch (Exception exception) {
                throw new Exception("Error playing event", exception);
            }


            try {
                while (queue.Count > 0)
                {
                    var effect = queue.Dequeue();
                    await effect.Execute(storage);
                }
            }
            catch (Exception exception) {
                throw new Exception("Fatal error running effect", exception);
            }

            await storage.AddEvent(e);

            Position++;
        }