예제 #1
0
        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();
            }
        }
예제 #2
0
        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);
            }
        }