Ejemplo n.º 1
0
        /// <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());
            }
        }
Ejemplo n.º 2
0
        /// <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();
            }
        }
Ejemplo n.º 3
0
        /// <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();
            }
        }