public DateTime Snapshot() { DateTime rollbackTime = DateTime.Now; CharacterMemento memento = _character.Export(); _snapshots.Insert(0, rollbackTime, memento); return(rollbackTime); }
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); } }