Example #1
0
        /// <summary>
        /// Adds the executing action with the specified ID to the schedule.
        /// </summary>
        /// <param name="action">The ID of the action that should be added.</param>
        /// <returns>The vertex that contains the information about the given action.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="action"/> is <see langword="null" />.
        /// </exception>
        public ExecutingActionVertex AddExecutingAction(ScheduleElementId action)
        {
            {
                Lokad.Enforce.Argument(() => action);
            }

            var result = new ExecutingActionVertex(m_Schedule.VertexCount, action);

            m_Schedule.AddVertex(result);

            return(result);
        }
        private static Schedule CreateScheduleGraphWithOuterAndInnerLoop(
            ScheduleConditionInformation outerLoopConditionInfo,
            ScheduleConditionInformation innerLoopConditionInfo,
            ScheduleActionInformation outerLoopInfo,
            ScheduleActionInformation innerLoopInfo)
        {
            var graph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>();
            var start = new StartVertex(1);

            graph.AddVertex(start);

            var end = new EndVertex(2);

            graph.AddVertex(end);

            var vertex1 = new InsertVertex(3);

            graph.AddVertex(vertex1);

            var vertex2 = new InsertVertex(4);

            graph.AddVertex(vertex2);

            var vertex3 = new ExecutingActionVertex(5, outerLoopInfo.Id);

            graph.AddVertex(vertex3);

            var vertex4 = new InsertVertex(6);

            graph.AddVertex(vertex4);

            var vertex5 = new ExecutingActionVertex(7, innerLoopInfo.Id);

            graph.AddVertex(vertex5);

            graph.AddEdge(new ScheduleEdge(start, vertex1));
            graph.AddEdge(new ScheduleEdge(vertex1, vertex2));

            graph.AddEdge(new ScheduleEdge(vertex2, end, outerLoopConditionInfo.Id));
            graph.AddEdge(new ScheduleEdge(vertex2, vertex3));

            graph.AddEdge(new ScheduleEdge(vertex3, vertex1, innerLoopConditionInfo.Id));
            graph.AddEdge(new ScheduleEdge(vertex3, vertex4));

            graph.AddEdge(new ScheduleEdge(vertex4, vertex5));
            graph.AddEdge(new ScheduleEdge(vertex5, vertex3));

            return(new Schedule(graph, start, end));
        }
        public void RunWithLoop()
        {
            bool passThrough = false;
            var  condition   = new Mock <IScheduleCondition>();
            {
                condition.Setup(c => c.CanTraverse(It.IsAny <CancellationToken>()))
                .Returns(() => passThrough);
            }

            var conditionStorage = ScheduleConditionStorage.CreateInstanceWithoutTimeline();
            var conditionInfo    = conditionStorage.Add(condition.Object, "a", "b");

            var action = new Mock <IScheduleAction>();
            {
                action.Setup(a => a.Execute(It.IsAny <CancellationToken>()))
                .Callback(() => passThrough = true);
            }

            var collection = ScheduleActionStorage.CreateInstanceWithoutTimeline();
            var info       = collection.Add(
                action.Object,
                "a",
                "b");

            // Making a schedule that looks like:
            // start -> node1 --> node2 -> end
            //            ^           |
            //            |-- node3 <-|
            Schedule schedule;

            {
                var graph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>();
                var start = new StartVertex(1);
                graph.AddVertex(start);

                var end = new EndVertex(2);
                graph.AddVertex(end);

                var vertex1 = new InsertVertex(3);
                graph.AddVertex(vertex1);

                var vertex2 = new InsertVertex(4);
                graph.AddVertex(vertex2);

                var vertex3 = new ExecutingActionVertex(5, info.Id);
                graph.AddVertex(vertex3);

                graph.AddEdge(new ScheduleEdge(start, vertex1));
                graph.AddEdge(new ScheduleEdge(vertex1, vertex2));

                graph.AddEdge(new ScheduleEdge(vertex2, end, conditionInfo.Id));
                graph.AddEdge(new ScheduleEdge(vertex2, vertex3));

                graph.AddEdge(new ScheduleEdge(vertex3, vertex1));

                schedule = new Schedule(graph, start, end);
            }

            using (var executionInfo = new ScheduleExecutionInfo(new CurrentThreadTaskScheduler()))
            {
                using (var executor = new ScheduleExecutor(
                           new List <IProcesExecutableScheduleVertices>
                {
                    new StartVertexProcessor(),
                    new EndVertexProcessor(),
                    new InsertVertexProcessor(),
                    new ActionVertexProcessor(collection),
                },
                           conditionStorage,
                           schedule,
                           new ScheduleId(),
                           executionInfo))
                {
                    var executionOrder = new List <int>();
                    executor.OnVertexProcess += (s, e) => executionOrder.Add(e.Vertex);

                    executor.Start();
                    Assert.That(executionOrder, Is.EquivalentTo(new[] { 1, 3, 4, 5, 3, 4, 2 }));
                }
            }
        }
Example #4
0
        private static Schedule BuildSchedule(
            ScheduleElementId action1,
            ScheduleElementId action2,
            ScheduleId scheduleId,
            ScheduleElementId exitCondition,
            ScheduleElementId passThroughCondition)
        {
            var variable = new Mock <IScheduleVariable>();

            // Making a schedule that looks like:
            // start --> node1 -----------------------> node2 -> end
            //            ^                              |
            //            |-- node5 <-- node4 <-- node3<-|
            //                           ^  |
            //                    node7--|  |->  node6
            //                      ^              |
            //                      |--------------|
            Schedule schedule = null;

            {
                var graph = new BidirectionalGraph <IScheduleVertex, ScheduleEdge>();

                var start = new StartVertex(1);
                graph.AddVertex(start);

                var end = new EndVertex(2);
                graph.AddVertex(end);

                var vertex1 = new ExecutingActionVertex(3, action1);
                graph.AddVertex(vertex1);

                var vertex2 = new ExecutingActionVertex(4, action2);
                graph.AddVertex(vertex2);

                var vertex3 = new SynchronizationStartVertex(5, new IScheduleVariable[] { variable.Object });
                graph.AddVertex(vertex3);

                var vertex4 = new ExecutingActionVertex(6, action2);
                graph.AddVertex(vertex4);

                var vertex5 = new SynchronizationEndVertex(7);
                graph.AddVertex(vertex5);

                var vertex6 = new SubScheduleVertex(8, scheduleId);
                graph.AddVertex(vertex6);

                var vertex7 = new InsertVertex(9);
                graph.AddVertex(vertex7);

                graph.AddEdge(new ScheduleEdge(start, vertex1));
                graph.AddEdge(new ScheduleEdge(vertex1, vertex2));

                graph.AddEdge(new ScheduleEdge(vertex2, end, exitCondition));
                graph.AddEdge(new ScheduleEdge(vertex2, vertex3));

                graph.AddEdge(new ScheduleEdge(vertex3, vertex4));

                graph.AddEdge(new ScheduleEdge(vertex4, vertex5, passThroughCondition));
                graph.AddEdge(new ScheduleEdge(vertex4, vertex6));

                graph.AddEdge(new ScheduleEdge(vertex5, vertex1));
                graph.AddEdge(new ScheduleEdge(vertex6, vertex7));
                graph.AddEdge(new ScheduleEdge(vertex7, vertex4));

                schedule = new Schedule(graph, start, end);
            }

            return(schedule);
        }