Ejemplo n.º 1
0
        public List <Transition> GetActivityDiagram(FlatFlow flatFlow, bool everyEventHasAnIssuer)
        {
            List <Transition>  allTransitions = new List <Transition>();
            CommandDescription initialCommand = new CommandDescription(null, "Start of flow");

            var initialEvent = flatFlow.EventToCommands.First(e => e.Key.FlowEvent == typeof(OnStart)).Key;

            allTransitions.AddRange(GetTransitions(flatFlow, new SourceOfEvent(initialCommand, null), initialEvent));

            var restOfTheEvents = flatFlow.EventToCommands
                                  .Where(eventToCommand => eventToCommand.Key != initialEvent)
                                  .Select(eventToCommand => eventToCommand.Key)
                                  .Distinct();

            foreach (var flowEvent in restOfTheEvents)
            {
                IEnumerable <SourceOfEvent> sourcesOfEvents;

                sourcesOfEvents = GetSourceOfEvents(flatFlow, flowEvent, everyEventHasAnIssuer);

                foreach (var sourceOfEvent in sourcesOfEvents)
                {
                    allTransitions.AddRange(GetTransitions(flatFlow, sourceOfEvent, flowEvent));
                }
            }

            return(allTransitions);
        }
Ejemplo n.º 2
0
        private static List <Transition> GetTransitions(FlatFlow flatFlow, SourceOfEvent sourceCommand, EventDescription flowEvent)
        {
            List <Transition> transitions = new List <Transition>();
            var startEvent = flatFlow.EventToCommands.First(e => e.Key == flowEvent);

            foreach (var transition in startEvent.Value)
            {
                transitions.Add(new Transition(startEvent.Key, sourceCommand.Command, transition, sourceCommand.ConditionOfRaise));
            }

            return(transitions);
        }
Ejemplo n.º 3
0
        private static IEnumerable <SourceOfEvent> GetSourceOfEvents(
            FlatFlow flatFlow,
            EventDescription flowEvent,
            bool everyEventHasAnIssuer)
        {
            IEnumerable <SourceOfEvent> commands = commands = flatFlow.CommandToEvents
                                                              .Where(c => c.Value.Any(mayRaise => mayRaise.EventThatMayBeRaised == flowEvent.FlowEvent))
                                                              .Select(c => new SourceOfEvent(c.Key, c.Value.First(mayRaise => mayRaise.EventThatMayBeRaised == flowEvent.FlowEvent)));

            if (everyEventHasAnIssuer && !commands.Any())
            {
                throw new InvalidProgramException($"There is no command attached to event:{flowEvent}");
            }

            return(commands);
        }
Ejemplo n.º 4
0
        public FlatFlow GetFlatFlow()
        {
            var links = flowClass
                        .GetTypeInfo()
                        .GetCustomAttributes <LinkEventToCommandAttribute>()
                        .ToArray();

            FlatFlow flatFlow = new FlatFlow();


            var commands = links
                           .ToDictionary(link => link, l => new CommandDescription(l.Command, l.CommandName));

            var distinctCommands = commands
                                   .GroupBy(e => new { e.Value.Command, e.Value.CommandName })
                                   .Select(g => g.First().Value);


            var events = links
                         .ToDictionary(link => link, link => new EventDescription(link.FlowEvent, link.SourceEventCommandName));

            var distinctEvents = events
                                 .GroupBy(e => new { e.Value.FlowEvent, e.Value.SourceCommandName })
                                 .Select(g => g.First().Value);


            foreach (var eventFlow in distinctEvents)
            {
                var commandsLinkedToEvent = links
                                            .Where(link => link.FlowEvent == eventFlow.FlowEvent && link.SourceEventCommandName == eventFlow.SourceCommandName)
                                            .Select(link => commands[link])
                                            .ToList();

                flatFlow.EventToCommands.Add(eventFlow, commandsLinkedToEvent);
            }

            foreach (var command in distinctCommands)
            {
                var eventsThatCommandMayRaise = command.Command.GetTypeInfo().GetCustomAttributes <MayRaiseAttribute>().ToList();

                flatFlow.CommandToEvents.Add(command, eventsThatCommandMayRaise);
            }

            return(flatFlow);
        }