public void LinkToWithExistingCondition()
        {
            var owner = new Mock <IOwnScheduleDefinitions>();

            ScheduleElementId id = null;
            var scheduleBuilder  = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(
                    s => s.LinkTo(
                        It.IsAny <IScheduleVertex>(),
                        It.IsAny <IScheduleVertex>(),
                        It.IsAny <ScheduleElementId>()))
                .Callback <IScheduleVertex, IScheduleVertex, ScheduleElementId>(
                    (s, e, c) => id = c);
            }

            var builder = new ScheduleDefinitionBuilder(owner.Object, scheduleBuilder.Object);

            var condition = new ScheduleConditionRegistrationId(typeof(string), 0, "a");

            builder.LinkTo(new MarkHistoryVertex(0), new InsertVertex(1), condition);

            Assert.IsNotNull(id);

            var firstId = id;

            builder.LinkTo(new MarkHistoryVertex(2), new InsertVertex(3), condition);

            Assert.IsNotNull(id);
            Assert.AreSame(firstId, id);
        }
Пример #2
0
        /// <summary>
        /// Links the given start vertex to the end vertex.
        /// </summary>
        /// <param name="start">The start vertex.</param>
        /// <param name="end">The end vertex.</param>
        /// <param name="traverseCondition">
        /// The ID of the condition that determines if it is possible to move from <paramref name="start"/> to <paramref name="end"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="start"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="UnknownScheduleVertexException">
        ///     Thrown if <paramref name="start"/> does not exist in the current schedule.
        /// </exception>
        /// <exception cref="CannotExplicitlyLinkStartVertexException">
        ///     Thrown if <paramref name="start"/> is equal to the start vertex of the schedule.
        /// </exception>
        /// <exception cref="CannotExplicitlyLinkStartVertexException">
        ///     Thrown if <paramref name="start"/> is equal to the end vertex of the schedule.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="end"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="UnknownScheduleVertexException">
        ///     Thrown if <paramref name="end"/> does not exist in the current schedule.
        /// </exception>
        /// <exception cref="CannotExplicitlyLinkStartVertexException">
        ///     Thrown if <paramref name="end"/> is equal to the start vertex of the schedule.
        /// </exception>
        /// <exception cref="CannotExplicitlyLinkStartVertexException">
        ///     Thrown if <paramref name="end"/> is equal to the end vertex of the schedule.
        /// </exception>
        /// <exception cref="CannotLinkAVertexToItselfException">
        ///     Thrown if <paramref name="start"/> and <paramref name="end"/> are the same vertex.
        /// </exception>
        public void LinkTo(IScheduleVertex start, IScheduleVertex end, ScheduleElementId traverseCondition = null)
        {
            {
                Lokad.Enforce.Argument(() => start);
                Lokad.Enforce.With <UnknownScheduleVertexException>(
                    m_Schedule.ContainsVertex(start),
                    Resources.Exceptions_Messages_UnknownScheduleVertex);
                Lokad.Enforce.With <CannotExplicitlyLinkStartVertexException>(
                    !ReferenceEquals(m_Start, start),
                    Resources.Exceptions_Messages_CannotExplicitlyLinkStartVertex);
                Lokad.Enforce.With <CannotExplicitlyLinkEndVertexException>(
                    !ReferenceEquals(m_End, start),
                    Resources.Exceptions_Messages_CannotExplicitlyLinkEndVertex);

                Lokad.Enforce.Argument(() => end);
                Lokad.Enforce.With <UnknownScheduleVertexException>(
                    m_Schedule.ContainsVertex(end),
                    Resources.Exceptions_Messages_UnknownScheduleVertex);
                Lokad.Enforce.With <CannotExplicitlyLinkStartVertexException>(
                    !ReferenceEquals(m_Start, end),
                    Resources.Exceptions_Messages_CannotExplicitlyLinkStartVertex);
                Lokad.Enforce.With <CannotExplicitlyLinkEndVertexException>(
                    !ReferenceEquals(m_End, end),
                    Resources.Exceptions_Messages_CannotExplicitlyLinkEndVertex);

                Lokad.Enforce.With <CannotLinkAVertexToItselfException>(
                    !ReferenceEquals(start, end),
                    Resources.Exceptions_Messages_CannotLinkAVertexToItself);
            }

            m_Schedule.AddEdge(new ScheduleEdge(start, end, traverseCondition));
        }
        public void AddActionWithExistingAction()
        {
            var owner = new Mock <IOwnScheduleDefinitions>();

            ScheduleElementId id = null;
            var scheduleBuilder  = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddExecutingAction(It.IsAny <ScheduleElementId>()))
                .Callback <ScheduleElementId>(s => id = s)
                .Returns <ScheduleElementId>(s => new ExecutingActionVertex(0, s));
            }

            var builder = new ScheduleDefinitionBuilder(owner.Object, scheduleBuilder.Object);

            var firstRegistration  = new ScheduleActionRegistrationId(typeof(string), 0, "a");
            var secondRegistration = new ScheduleActionRegistrationId(typeof(string), 0, "a");
            var firstVertex        = builder.AddExecutingAction(firstRegistration);

            var first = id;

            id = null;
            var secondVertex = builder.AddExecutingAction(secondRegistration);

            Assert.IsNotNull(firstVertex);
            Assert.IsNotNull(secondVertex);
            Assert.AreEqual(first, id);
        }
Пример #4
0
 /// <summary>
 /// Removes the action with the specified ID.
 /// </summary>
 /// <param name="id">The ID of the action that should be removed.</param>
 public void Remove(ScheduleElementId id)
 {
     if ((id != null) && m_Actions.ContainsKey(id))
     {
         m_Actions.Remove(id);
     }
 }
        public void ExecuteInProcess()
        {
            var action1 = new ScheduleElementId();
            var action2 = new ScheduleElementId();
            var exitCondition = new ScheduleElementId();
            var passThroughCondition = new ScheduleElementId();
            var subSchedule = new ScheduleId();

            var schedule = BuildSchedule(
                action1,
                action2,
                subSchedule,
                exitCondition,
                passThroughCondition);

            var knownSchedules = ScheduleStorage.CreateInstanceWithoutTimeline();
            var scheduleInfo = knownSchedules.Add(
                schedule,
                "a",
                "b");

            ISchedule storedSchedule = null;
            var executor = new Mock<IExecuteSchedules>();
            Func<ISchedule, ScheduleId, ScheduleExecutionInfo, IExecuteSchedules> builder =
                (s, i, e) =>
                {
                    storedSchedule = s;
                    return executor.Object;
                };

            var distributor = new ScheduleDistributor(knownSchedules, builder);
            var returnedExecutor = distributor.Execute(scheduleInfo.Id);
            Assert.AreSame(executor.Object, returnedExecutor);
            VerifySchedule(schedule, storedSchedule);
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExecutingActionVertex"/> class.
        /// </summary>
        /// <param name="index">The index of the vertex in the graph.</param>
        /// <param name="actionToExecute">The ID of the action that should be executed.</param>
        public ExecutingActionVertex(int index, ScheduleElementId actionToExecute)
        {
            {
                Debug.Assert(actionToExecute != null, "The ID of the action should not be a null reference.");
            }

            Index = index;
            m_Action = actionToExecute;
        }
        /// <summary>
        /// Links the given vertex to the end point of the schedule.
        /// </summary>
        /// <param name="source">The vertex.</param>
        /// <param name="traverseCondition">
        /// The ID of the condition that determines if it is possible to move from <paramref name="source"/> to the end point.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="source"/> is <see langword="null" />.
        /// </exception>
        public void LinkToEnd(IScheduleVertex source, ScheduleConditionRegistrationId traverseCondition = null)
        {
            {
                Lokad.Enforce.Argument(() => source);
            }

            ScheduleElementId condition = ToScheduleCondition(traverseCondition);

            m_Builder.LinkToEnd(source, condition);
        }
        /// <summary>
        /// Links the start point of the schedule to the given vertex.
        /// </summary>
        /// <param name="target">The vertex.</param>
        /// <param name="traverseCondition">
        /// The ID of the condition that determines if it is possible to move from the start point to <paramref name="target"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="target"/> is <see langword="null" />.
        /// </exception>
        public void LinkFromStart(IScheduleVertex target, ScheduleConditionRegistrationId traverseCondition = null)
        {
            {
                Lokad.Enforce.Argument(() => target);
            }

            ScheduleElementId condition = ToScheduleCondition(traverseCondition);

            m_Builder.LinkFromStart(target, condition);
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScheduleEdge"/> class.
        /// </summary>
        /// <param name="source">The start vertex for the edge.</param>
        /// <param name="target">The end vertex for the edge.</param>
        /// <param name="traversingCondition">The ID of the condition that determines if this edge can be traversed.</param>
        public ScheduleEdge(IScheduleVertex source, IScheduleVertex target, ScheduleElementId traversingCondition = null)
            : base(source, target)
        {
            {
                Debug.Assert(source != null, "The source vertex cannot be a null reference.");
                Debug.Assert(target != null, "The target vertex cannot be a null reference.");
            }

            m_TraversingCondition = traversingCondition;
        }
Пример #10
0
        /// <summary>
        /// Returns the action information for the action that is mapped to the given ID.
        /// </summary>
        /// <param name="id">The ID for the action.</param>
        /// <returns>The action information.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="id"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="UnknownScheduleActionException">
        ///     Thrown if <paramref name="id"/> is not linked to a known action.
        /// </exception>
        public ScheduleActionInformation Information(ScheduleElementId id)
        {
            {
                Lokad.Enforce.Argument(() => id);
                Lokad.Enforce.With <UnknownScheduleActionException>(
                    m_Actions.ContainsKey(id),
                    Resources.Exceptions_Messages_UnknownScheduleAction);
            }

            return(m_Actions[id].Information);
        }
Пример #11
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);
        }
Пример #12
0
        public void Create()
        {
            IScheduleVertex source = new StartVertex(10);
            IScheduleVertex target = new EndVertex(11);

            var condition = new ScheduleElementId();
            var edge      = new ScheduleEdge(source, target, condition);

            Assert.AreSame(source, edge.Source);
            Assert.AreSame(target, edge.Target);
            Assert.AreSame(condition, edge.TraversingCondition);
        }
Пример #13
0
        public void Create()
        {
            IScheduleVertex source = new StartVertex(10);
            IScheduleVertex target = new EndVertex(11);

            var condition = new ScheduleElementId();
            var edge = new ScheduleEdge(source, target, condition);

            Assert.AreSame(source, edge.Source);
            Assert.AreSame(target, edge.Target);
            Assert.AreSame(condition, edge.TraversingCondition);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ScheduleConditionInformation"/> class.
        /// </summary>
        /// <param name="id">The ID of the condition that is being described by this information object.</param>
        /// <param name="name">The name of the condition that is being described by this information object.</param>
        /// <param name="description">The description of the condition that is being described by this information object.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="id"/> is <see langword="null" />.
        /// </exception>
        public ScheduleConditionInformation(
            ScheduleElementId id,
            string name,
            string description)
        {
            {
                Lokad.Enforce.Argument(() => id);
            }

            m_Id = id;
            m_Name = name;
            m_Description = description;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ScheduleActionInformation"/> class.
        /// </summary>
        /// <param name="id">The ID of the action that is being described by this information object.</param>
        /// <param name="name">The name of the action that is being described by this information object.</param>
        /// <param name="description">The description of the action that is being described by this information object.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="id"/> is <see langword="null" />.
        /// </exception>
        public ScheduleActionInformation(
            ScheduleElementId id,
            string name,
            string description)
        {
            {
                Lokad.Enforce.Argument(() => id);
            }

            m_Id          = id;
            m_Name        = name;
            m_Description = description;
        }
Пример #16
0
        public void InsertInWithSubSchedule()
        {
            var conditionId1 = new ScheduleElementId();
            var conditionId2 = new ScheduleElementId();

            var builder      = new FixedScheduleBuilder();
            var insertVertex = builder.AddInsertPoint();

            builder.LinkFromStart(insertVertex, conditionId1);
            builder.LinkToEnd(insertVertex, conditionId2);

            var scheduleId = new ScheduleId();

            builder.InsertIn(insertVertex, scheduleId);
            var schedule = builder.Build();

            int index       = 0;
            var vertexTypes = new List <Type>
            {
                typeof(StartVertex),
                typeof(InsertVertex),
                typeof(SubScheduleVertex),
                typeof(InsertVertex),
                typeof(EndVertex)
            };
            var conditions = new List <ScheduleElementId>
            {
                conditionId1,
                null,
                null,
                conditionId2
            };

            schedule.TraverseAllScheduleVertices(
                schedule.Start,
                (vertex, edges) =>
            {
                Assert.AreEqual(vertexTypes[index], vertex.GetType());
                if (index < conditions.Count)
                {
                    Assert.AreEqual(1, edges.Count());
                    Assert.AreEqual(conditions[index], edges.First().Item1);
                }

                index++;
                return(true);
            });
        }
        private ScheduleElementId ToScheduleCondition(ScheduleConditionRegistrationId traverseCondition = null)
        {
            ScheduleElementId condition = null;

            if (traverseCondition != null)
            {
                if (!m_Conditions.ContainsKey(traverseCondition))
                {
                    m_Conditions.Add(traverseCondition, new ScheduleElementId());
                }

                condition = m_Conditions[traverseCondition];
            }

            return(condition);
        }
Пример #18
0
        /// <summary>
        /// Adds the <see cref="IScheduleAction"/> object with the variables it affects and the dependencies for that action.
        /// </summary>
        /// <param name="action">The action that should be stored.</param>
        /// <param name="name">The name of the action that is being described by this information object.</param>
        /// <param name="description">The description of the action that is being described by this information object.</param>
        /// <returns>An object identifying and describing the action.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="action"/> is <see langword="null" />.
        /// </exception>
        public ScheduleActionInformation Add(
            IScheduleAction action,
            string name,
            string description)
        {
            {
                Lokad.Enforce.Argument(() => action);
            }

            var id   = new ScheduleElementId();
            var info = new ScheduleActionInformation(id, name, description);

            m_Actions.Add(id, new ActionMap(info, action));

            return(info);
        }
        public void AddExecutingAction()
        {
            var actionId = new ScheduleElementId();

            var builder = new FixedScheduleBuilder();
            var actionVertex = builder.AddExecutingAction(actionId);
            builder.LinkFromStart(actionVertex);
            builder.LinkToEnd(actionVertex);
            Assert.AreEqual(actionId, actionVertex.ActionToExecute);
            Assert.AreEqual(2, actionVertex.Index);

            var schedule = builder.Build();
            Assert.AreEqual(3, schedule.Vertices.Count());
            Assert.IsTrue(AreVerticesEqual(schedule.Start, schedule.Vertices.ElementAt(0)));
            Assert.IsTrue(AreVerticesEqual(actionVertex, schedule.Vertices.ElementAt(1)));
            Assert.IsTrue(AreVerticesEqual(schedule.End, schedule.Vertices.ElementAt(2)));
        }
Пример #20
0
        /// <summary>
        /// Links the start point of the schedule to the given vertex.
        /// </summary>
        /// <param name="vertex">The vertex.</param>
        /// <param name="traverseCondition">
        /// The ID of the condition that determines if it is possible to move from the start point to <paramref name="vertex"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="vertex"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="UnknownScheduleVertexException">
        ///     Thrown if <paramref name="vertex"/> does not exist in the current schedule.
        /// </exception>
        /// <exception cref="CannotExplicitlyLinkStartVertexException">
        ///     Thrown if <paramref name="vertex"/> is equal to the end vertex of the schedule.
        /// </exception>
        /// <exception cref="CannotLinkAVertexToItselfException">
        ///     Thrown if the start vertex of the schedule and <paramref name="vertex"/> are the same vertex.
        /// </exception>
        public void LinkFromStart(IScheduleVertex vertex, ScheduleElementId traverseCondition = null)
        {
            {
                Lokad.Enforce.Argument(() => vertex);
                Lokad.Enforce.With <UnknownScheduleVertexException>(
                    m_Schedule.ContainsVertex(vertex),
                    Resources.Exceptions_Messages_UnknownScheduleVertex);

                Lokad.Enforce.With <CannotExplicitlyLinkEndVertexException>(
                    !ReferenceEquals(m_End, vertex),
                    Resources.Exceptions_Messages_CannotExplicitlyLinkEndVertex);
                Lokad.Enforce.With <CannotLinkAVertexToItselfException>(
                    !ReferenceEquals(m_Start, vertex),
                    Resources.Exceptions_Messages_CannotLinkAVertexToItself);
            }

            m_Schedule.AddEdge(new ScheduleEdge(m_Start, vertex, traverseCondition));
        }
Пример #21
0
        public void AddExecutingAction()
        {
            var actionId = new ScheduleElementId();

            var builder      = new FixedScheduleBuilder();
            var actionVertex = builder.AddExecutingAction(actionId);

            builder.LinkFromStart(actionVertex);
            builder.LinkToEnd(actionVertex);
            Assert.AreEqual(actionId, actionVertex.ActionToExecute);
            Assert.AreEqual(2, actionVertex.Index);

            var schedule = builder.Build();

            Assert.AreEqual(3, schedule.Vertices.Count());
            Assert.IsTrue(AreVerticesEqual(schedule.Start, schedule.Vertices.ElementAt(0)));
            Assert.IsTrue(AreVerticesEqual(actionVertex, schedule.Vertices.ElementAt(1)));
            Assert.IsTrue(AreVerticesEqual(schedule.End, schedule.Vertices.ElementAt(2)));
        }
Пример #22
0
        public void ExecuteWithAlreadyRunningSchedule()
        {
            var action1              = new ScheduleElementId();
            var action2              = new ScheduleElementId();
            var exitCondition        = new ScheduleElementId();
            var passThroughCondition = new ScheduleElementId();
            var subSchedule          = new ScheduleId();

            var schedule = BuildSchedule(
                action1,
                action2,
                subSchedule,
                exitCondition,
                passThroughCondition);

            var knownSchedules = ScheduleStorage.CreateInstanceWithoutTimeline();
            var scheduleInfo   = knownSchedules.Add(
                schedule,
                "a",
                "b");

            var executor = new Mock <IExecuteSchedules>();

            int index = 0;
            Func <ISchedule, ScheduleId, ScheduleExecutionInfo, IExecuteSchedules> builder =
                (s, id, e) =>
            {
                index++;
                return(executor.Object);
            };

            var distributor      = new ScheduleDistributor(knownSchedules, builder);
            var returnedExecutor = distributor.Execute(scheduleInfo.Id);

            Assert.AreSame(executor.Object, returnedExecutor);
            Assert.AreEqual(1, index);

            var otherReturnedExecutor = distributor.Execute(scheduleInfo.Id);

            Assert.AreSame(executor.Object, otherReturnedExecutor);
            Assert.AreEqual(1, index);
        }
        public void AddAction()
        {
            var owner = new Mock <IOwnScheduleDefinitions>();

            ScheduleElementId id = null;
            var scheduleBuilder  = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(s => s.AddExecutingAction(It.IsAny <ScheduleElementId>()))
                .Callback <ScheduleElementId>(s => id = s)
                .Returns <ScheduleElementId>(s => new ExecutingActionVertex(0, s));
            }

            var builder = new ScheduleDefinitionBuilder(owner.Object, scheduleBuilder.Object);

            var registrationId = new ScheduleActionRegistrationId(typeof(string), 0, "a");
            var vertex         = builder.AddExecutingAction(registrationId);

            Assert.IsNotNull(vertex);
            Assert.IsNotNull(id);
        }
Пример #24
0
        /// <summary>
        /// Replaces the action current stored against the given ID with a new one.
        /// </summary>
        /// <param name="actionToReplace">The ID of the action that should be replaced.</param>
        /// <param name="newAction">The new action.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="actionToReplace"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="newAction"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="UnknownScheduleActionException">
        ///     Thrown if <paramref name="actionToReplace"/> is not linked to a known action.
        /// </exception>
        public void Update(
            ScheduleElementId actionToReplace,
            IScheduleAction newAction)
        {
            {
                Lokad.Enforce.Argument(() => actionToReplace);
                Lokad.Enforce.Argument(() => newAction);
                Lokad.Enforce.With <UnknownScheduleActionException>(
                    m_Actions.ContainsKey(actionToReplace),
                    Resources.Exceptions_Messages_UnknownScheduleAction);
            }

            var oldInfo = m_Actions[actionToReplace].Information;
            var info    = new ScheduleActionInformation(
                actionToReplace,
                oldInfo.Name,
                oldInfo.Description);

            m_Actions[actionToReplace] = new ActionMap(info, newAction);
        }
Пример #25
0
        public void ExecuteWithAlreadyRunningSchedule()
        {
            var action1 = new ScheduleElementId();
            var action2 = new ScheduleElementId();
            var exitCondition = new ScheduleElementId();
            var passThroughCondition = new ScheduleElementId();
            var subSchedule = new ScheduleId();

            var schedule = BuildSchedule(
                action1,
                action2,
                subSchedule,
                exitCondition,
                passThroughCondition);

            var knownSchedules = ScheduleStorage.CreateInstanceWithoutTimeline();
            var scheduleInfo = knownSchedules.Add(
                schedule,
                "a",
                "b");

            var executor = new Mock<IExecuteSchedules>();

            int index = 0;
            Func<ISchedule, ScheduleId, ScheduleExecutionInfo, IExecuteSchedules> builder =
                (s, id, e) =>
                {
                    index++;
                    return executor.Object;
                };

            var distributor = new ScheduleDistributor(knownSchedules, builder);
            var returnedExecutor = distributor.Execute(scheduleInfo.Id);
            Assert.AreSame(executor.Object, returnedExecutor);
            Assert.AreEqual(1, index);

            var otherReturnedExecutor = distributor.Execute(scheduleInfo.Id);
            Assert.AreSame(executor.Object, otherReturnedExecutor);
            Assert.AreEqual(1, index);
        }
        public void LinkToEndWithCondition()
        {
            var owner = new Mock <IOwnScheduleDefinitions>();

            ScheduleElementId id = null;
            var scheduleBuilder  = new Mock <IBuildFixedSchedules>();
            {
                scheduleBuilder.Setup(
                    s => s.LinkToEnd(
                        It.IsAny <IScheduleVertex>(),
                        It.IsAny <ScheduleElementId>()))
                .Callback <IScheduleVertex, ScheduleElementId>(
                    (s, c) => id = c);
            }

            var builder = new ScheduleDefinitionBuilder(owner.Object, scheduleBuilder.Object);

            var condition = new ScheduleConditionRegistrationId(typeof(string), 0, "a");

            builder.LinkToEnd(new InsertVertex(1), condition);

            Assert.IsNotNull(id);
        }
Пример #27
0
        public void ExecuteInProcess()
        {
            var action1              = new ScheduleElementId();
            var action2              = new ScheduleElementId();
            var exitCondition        = new ScheduleElementId();
            var passThroughCondition = new ScheduleElementId();
            var subSchedule          = new ScheduleId();

            var schedule = BuildSchedule(
                action1,
                action2,
                subSchedule,
                exitCondition,
                passThroughCondition);

            var knownSchedules = ScheduleStorage.CreateInstanceWithoutTimeline();
            var scheduleInfo   = knownSchedules.Add(
                schedule,
                "a",
                "b");

            ISchedule storedSchedule = null;
            var       executor       = new Mock <IExecuteSchedules>();
            Func <ISchedule, ScheduleId, ScheduleExecutionInfo, IExecuteSchedules> builder =
                (s, i, e) =>
            {
                storedSchedule = s;
                return(executor.Object);
            };

            var distributor      = new ScheduleDistributor(knownSchedules, builder);
            var returnedExecutor = distributor.Execute(scheduleInfo.Id);

            Assert.AreSame(executor.Object, returnedExecutor);
            VerifySchedule(schedule, storedSchedule);
        }
Пример #28
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);
        }
Пример #29
0
        /// <summary>
        /// Links the given vertex to the end point of the schedule.
        /// </summary>
        /// <param name="vertex">The vertex.</param>
        /// <param name="traverseCondition">
        /// The ID of the condition that determines if it is possible to move from <paramref name="vertex"/> to the end point.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="vertex"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="UnknownScheduleVertexException">
        ///     Thrown if <paramref name="vertex"/> does not exist in the current schedule.
        /// </exception>
        /// <exception cref="CannotExplicitlyLinkStartVertexException">
        ///     Thrown if <paramref name="vertex"/> is equal to the start vertex of the schedule.
        /// </exception>
        /// <exception cref="CannotLinkAVertexToItselfException">
        ///     Thrown if the end vertex of the schedule and <paramref name="vertex"/> are the same vertex.
        /// </exception>
        public void LinkToEnd(IScheduleVertex vertex, ScheduleElementId traverseCondition = null)
        {
            {
                Lokad.Enforce.Argument(() => vertex);
                Lokad.Enforce.With<UnknownScheduleVertexException>(
                    m_Schedule.ContainsVertex(vertex),
                    Resources.Exceptions_Messages_UnknownScheduleVertex);
                Lokad.Enforce.With<CannotExplicitlyLinkStartVertexException>(
                    !ReferenceEquals(m_Start, vertex),
                    Resources.Exceptions_Messages_CannotExplicitlyLinkStartVertex);
                Lokad.Enforce.With<CannotLinkAVertexToItselfException>(
                    !ReferenceEquals(m_End, vertex),
                    Resources.Exceptions_Messages_CannotLinkAVertexToItself);
            }

            m_Schedule.AddEdge(new ScheduleEdge(vertex, m_End, traverseCondition));
        }
        public void InsertInWithSubSchedule()
        {
            var conditionId1 = new ScheduleElementId();
            var conditionId2 = new ScheduleElementId();

            var builder = new FixedScheduleBuilder();
            var insertVertex = builder.AddInsertPoint();
            builder.LinkFromStart(insertVertex, conditionId1);
            builder.LinkToEnd(insertVertex, conditionId2);

            var scheduleId = new ScheduleId();
            builder.InsertIn(insertVertex, scheduleId);
            var schedule = builder.Build();

            int index = 0;
            var vertexTypes = new List<Type>
                {
                    typeof(StartVertex),
                    typeof(InsertVertex),
                    typeof(SubScheduleVertex),
                    typeof(InsertVertex),
                    typeof(EndVertex)
                };
            var conditions = new List<ScheduleElementId>
                {
                    conditionId1,
                    null,
                    null,
                    conditionId2
                };

            schedule.TraverseAllScheduleVertices(
                schedule.Start,
                (vertex, edges) =>
                {
                    Assert.AreEqual(vertexTypes[index], vertex.GetType());
                    if (index < conditions.Count)
                    {
                        Assert.AreEqual(1, edges.Count());
                        Assert.AreEqual(conditions[index], edges.First().Item1);
                    }

                    index++;
                    return true;
                });
        }
Пример #31
0
 public bool Contains(ScheduleElementId id)
 {
     return((id != null) && m_Actions.ContainsKey(id));
 }
        /// <summary>
        /// Replaces the condition current stored against the given ID with a new one.
        /// </summary>
        /// <param name="conditionToReplace">The ID of the condition that should be replaced.</param>
        /// <param name="newCondition">The new condition.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="conditionToReplace"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="newCondition"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="UnknownScheduleConditionException">
        ///     Thrown if <paramref name="conditionToReplace"/> is not linked to a known condition.
        /// </exception>
        public void Update(
            ScheduleElementId conditionToReplace,
            IScheduleCondition newCondition)
        {
            {
                Lokad.Enforce.Argument(() => conditionToReplace);
                Lokad.Enforce.Argument(() => newCondition);
                Lokad.Enforce.With<UnknownScheduleConditionException>(
                    m_Conditions.ContainsKey(conditionToReplace),
                    Resources.Exceptions_Messages_UnknownScheduleCondition);
            }

            var oldInfo = m_Conditions[conditionToReplace].Information;
            var info = new ScheduleConditionInformation(
                conditionToReplace,
                oldInfo.Name,
                oldInfo.Description);
            m_Conditions[conditionToReplace] = new ConditionMap(info, newCondition);
        }
 /// <summary>
 /// Removes the condition with the specified ID.
 /// </summary>
 /// <param name="id">The ID of the condition that should be removed.</param>
 public void Remove(ScheduleElementId id)
 {
     if ((id != null) && m_Conditions.ContainsKey(id))
     {
         m_Conditions.Remove(id);
     }
 }
        /// <summary>
        /// Returns the condition information for the condition that is mapped to the given ID.
        /// </summary>
        /// <param name="id">The ID for the condition.</param>
        /// <returns>The condition information.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="id"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="UnknownScheduleConditionException">
        ///     Thrown if <paramref name="id"/> is not linked to a known condition.
        /// </exception>
        public ScheduleConditionInformation Information(ScheduleElementId id)
        {
            {
                Lokad.Enforce.Argument(() => id);
                Lokad.Enforce.With<UnknownScheduleConditionException>(
                    m_Conditions.ContainsKey(id),
                    Resources.Exceptions_Messages_UnknownScheduleCondition);
            }

            return m_Conditions[id].Information;
        }
 public bool Contains(ScheduleElementId id)
 {
     return (id != null) && m_Conditions.ContainsKey(id);
 }
        /// <summary>
        /// Adds the <see cref="IScheduleCondition"/> object with the dependencies for that condition.
        /// </summary>
        /// <param name="condition">The condition that should be stored.</param>
        /// <param name="name">The name of the condition that is being described by this information object.</param>
        /// <param name="description">The description of the condition that is being described by this information object.</param>
        /// <returns>An object identifying and describing the condition.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="condition"/> is <see langword="null" />.
        /// </exception>
        public ScheduleConditionInformation Add(
            IScheduleCondition condition,
            string name,
            string description)
        {
            {
                Lokad.Enforce.Argument(() => condition);
            }

            var id = new ScheduleElementId();
            var info = new ScheduleConditionInformation(id, name, description);
            m_Conditions.Add(id, new ConditionMap(info, condition));

            return info;
        }
Пример #37
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;
        }
Пример #38
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;
        }