Esempio n. 1
0
        public void React(RFEvent e, IRFProcessingContext processingContext)
        {
            var allInstructions = new BlockingCollection <RFInstruction>();

            if (e is RFIntervalEvent ie) // silently store intervals in database?
            {
                processingContext.SaveEntry(new RFDocument
                {
                    Content = ie.Interval,
                    Key     = _config.IntervalDocumentKey(),
                    Type    = typeof(RFInterval).FullName
                }, false, true);
            }
            Parallel.ForEach(_reactors, reactor =>
            {
                try
                {
                    var instructions = reactor.React(e);
                    if (instructions != null)
                    {
                        foreach (var instruction in instructions)
                        {
                            allInstructions.Add(instruction);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception(this, ex, "Reactor {0} threw an exception processing event {1}", reactor, e);
                }
            });

            foreach (var instruction in allInstructions)
            {
                processingContext.QueueInstruction(this, instruction);
            }
        }