/// <summary> /// Clears all snapshot records. /// </summary> public static void ClearSnapshots() { lock (SnapshotManager.AccessLock) { SnapshotManager.Snapshots.Clear(); SnapshotManager.DeletedSnapshots.Clear(); SnapshotManager.NotifyObservers(); // There can be multiple GB of deleted snapshots, so run the garbage collector ASAP for a performance boost. Task.Run(() => GC.Collect()); } }
/// <summary> /// Reverses an undo action. /// </summary> public static void RedoSnapshot() { lock (SnapshotManager.AccessLock) { if (SnapshotManager.DeletedSnapshots.Count == 0) { return; } SnapshotManager.Snapshots.Push(SnapshotManager.DeletedSnapshots.Pop()); SnapshotManager.NotifyObservers(); } }
/// <summary> /// Saves a new snapshot, which will become the current active snapshot. /// </summary> /// <param name="snapshot">The snapshot to save.</param> public static void SaveSnapshot(Snapshot snapshot) { lock (SnapshotManager.AccessLock) { // Remove null snapshot if exists if (SnapshotManager.Snapshots.Count != 0 && SnapshotManager.Snapshots.Peek() == null) { SnapshotManager.Snapshots.Pop(); } // Do not keep large snapshots in the undo history if (SnapshotManager.Snapshots.Count != 0 && SnapshotManager.Snapshots.Peek() != null && SnapshotManager.Snapshots.Peek().ByteCount > SnapshotManager.SizeLimit) { SnapshotManager.Snapshots.Pop(); } SnapshotManager.Snapshots.Push(snapshot); SnapshotManager.DeletedSnapshots.Clear(); SnapshotManager.NotifyObservers(); } }