예제 #1
0
        private void SendTravellerBackToOwner(TimelineTraveller traveller)
        {
            {
                Debug.Assert(traveller != null, "The traveller should not be a null reference.");
            }

            var id = traveller.Owner;

            if (m_ObjectTimelines.ContainsKey(id))
            {
                var owner = m_ObjectTimelines[id] as IReceiveMessagesFromTheFuture;
                if (owner != null)
                {
                    owner.ReceiveTraveller(traveller);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Rolls the state forward to the named point in time an provides the <see cref="TimelineTraveller"/>
        /// to the history objects that want it.
        /// </summary>
        /// <param name="mark">The named point in time to roll-forward to.</param>
        /// <param name="traveller">The object that stores state that needs to survive the roll-forward.</param>
        public void RollForwardTo(string mark, TimelineTraveller traveller = null)
        {
            {
                Lokad.Enforce.Argument(() => mark);
                Lokad.Enforce.Argument(() => mark, Lokad.Rules.StringIs.NotEmpty);
            }

            if (!m_NameToTimeMap.ContainsKey(mark))
            {
                throw new UnknownTimeMarkerException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              Resources.Exceptions_Messages_UnknownTimeMarker_WithName,
                              mark));
            }

            var marker = m_NameToTimeMap[mark];

            RollForwardTo(marker, traveller);
        }
예제 #3
0
        /// <summary>
        /// Rolls the state back to the given point in time and provides the <see cref="TimelineTraveller"/>
        /// to the history objects that want it.
        /// </summary>
        /// <param name="mark">The point in time to roll-back to.</param>
        /// <param name="traveller">The object that stores state that needs to survive the roll-back.</param>
        public void RollBackTo(TimeMarker mark, TimelineTraveller traveller = null)
        {
            {
                Lokad.Enforce.Argument(() => mark);
                Lokad.Enforce.With <InvalidTimeMarkerException>(
                    mark >= TimeMarker.TheBeginOfTime,
                    Resources.Exceptions_Messages_CannotMovePastBeginningOfTime);
                Lokad.Enforce.With <InvalidTimeMarkerException>(
                    mark <= m_Current,
                    Resources.Exceptions_Messages_CannotRollBackToAPointInTheFuture);
            }

            // Check that we are able to perform the roll-back
            VerifyThatPastDependenciesAllowRollBack(mark);

            RaiseOnRollingBack();

            RollBackMarkers(mark);
            RollBackDependencies(mark);
            RollBackCreatedObjects(mark);

            // Roll back all the changes
            foreach (var pair in m_ObjectTimelines)
            {
                pair.Value.RollBackTo(mark);
            }

            // Clear all the objects that were created but weren't marked
            m_NonMarkedObjectTimelines.Clear();

            // Make the state consistent before sending the traveller back
            m_Current = mark;

            // Send the traveller back to the owner
            if (traveller != null)
            {
                SendTravellerBackToOwner(traveller);
            }

            RaiseOnRolledBack();
        }
예제 #4
0
        /// <summary>
        /// Rolls the state forward to the given point in time an provides the <see cref="TimelineTraveller"/>
        /// to the history objects that want it.
        /// </summary>
        /// <param name="mark">The point in time to roll-forward to.</param>
        /// <param name="traveller">The object that stores state that needs to survive the roll-forward.</param>
        public void RollForwardTo(TimeMarker mark, TimelineTraveller traveller = null)
        {
            {
                Lokad.Enforce.Argument(() => mark);
                Lokad.Enforce.With <InvalidTimeMarkerException>(
                    mark >= m_Current,
                    Resources.Exceptions_Messages_CannotRollForwardToAPointInThePast);
            }

            VerifyThatFutureDependenciesAllowRollForward(mark);

            RaiseOnRollingForward();

            RollForwardMarkers(mark);
            RollFowardDependencies(mark);
            RollForwardCreatedObjects(mark);

            // Roll the changes forward
            foreach (var pair in m_ObjectTimelines)
            {
                pair.Value.RollForwardTo(mark);
            }

            // Clear all the objects that were created but weren't marked
            m_NonMarkedObjectTimelines.Clear();

            // Make the state consistent before sending the traveller back
            m_Current = mark;

            // Send the traveller back to the owner
            if (traveller != null)
            {
                SendTravellerBackToOwner(traveller);
            }

            RaiseOnRolledForward();
        }