bool TryRouteEvent() { var hasRoute = _routesByEvent.TryGetValue(_event, out var route); if (!_givensByEvent.TryGetValue(_event, out var given)) { given = new FlowMethodSet <FlowGiven>(); } FlowObservation observation; if (!_flow.IsTopic) { observation = new FlowObservation(_flow, _event, route, given); } else { if (!_whensByEvent.TryGetValue(_event, out var when)) { when = new FlowMethodSet <TopicWhen>(); } observation = new TopicObservation(_flow, _event, route, given, when); } _flow.Observations.Declare(observation); _event.Observations.Write.Add(observation); return(hasRoute); }
void DeclareMethods <T>(Dictionary <EventType, FlowMethodSet <T> > methodsByEvent, T method, bool scheduled) where T : FlowMethod { if (!methodsByEvent.TryGetValue(_event, out var methods)) { methods = new FlowMethodSet <T>(); methodsByEvent.Add(_event, methods); } methods.GetMethods(scheduled).Write.Add(method); }
private void RegisterEvents() { var unroutedEvents = new List <EventType>(); foreach (var e in _events) { FlowMethodSet <FlowGiven> given; FlowMethodSet <FlowWhen> when; FlowRoute route; if (!_givenLookup.TryGetValue(e, out given)) { given = new FlowMethodSet <FlowGiven>(); } if (!_whenLookup.TryGetValue(e, out when)) { when = new FlowMethodSet <FlowWhen>(); } if (!_routesByEvent.TryGetValue(e, out route)) { unroutedEvents.Add(e); } _flow.Events.Register(new FlowEvent(_flow, e, given, when, route)); } if (unroutedEvents.Count > 0 && unroutedEvents.Count < _events.Count) { throw new Exception($"Flow {_flow} specifies routes but is missing some: {unroutedEvents.ToTextSeparatedBy(", ")}"); } if (_flow.IsRequest) { _flow.SetRouted(); } else if (_events.Count > 0 && unroutedEvents.Count == 0) { if (!_flow.Events.Any(e => e.Route.IsFirst)) { throw new Exception($"Flow {_flow} specifies routes but no RouteFirst methods"); } _flow.SetRouted(); } else { _flow.SetSingleInstance(); } }
private static void RegisterMethod <T>(EventType e, MethodLookup <T> lookup, T method, bool scheduled) where T : FlowMethod { FlowMethodSet <T> methods; if (!lookup.TryGetValue(e, out methods)) { methods = new FlowMethodSet <T>(); lookup.Add(e, methods); } if (scheduled) { methods.ScheduledMethods.Write.Add(method); } else { methods.Methods.Write.Add(method); } }