예제 #1
0
        public DateTime Snapshot()
        {
            DateTime         rollbackTime = DateTime.Now;
            CharacterMemento memento      = _character.Export();

            _snapshots.Insert(0, rollbackTime, memento);
            return(rollbackTime);
        }
예제 #2
0
        public void Rollback(DateTime snapshotTime)
        {
            CharacterMemento targetMemento = null;

            foreach (DictionaryEntry snapshot in _snapshots)
            {
                DateTime         time    = (DateTime)snapshot.Key;
                CharacterMemento memento = (CharacterMemento)snapshot.Value;

                if (time <= snapshotTime)
                {
                    targetMemento = memento;
                }
            }

            if (targetMemento != null)
            {
                _character.Import(targetMemento);
            }
        }