Exemple #1
0
 public void Restore(IMemento memento)
 {
     if (memento is not BalanceMemento)
     {
         throw new UnknownMementoClassException(memento.ToString());
     }
     Balance = memento.GetState();
 }
Exemple #2
0
        // Restores the Originator's state from a memento object.
        public void Restore(IMemento memento)
        {
            if (!(memento is ConcreteMemento))
            {
                throw new Exception("Unknown memento class " + memento.ToString());
            }

            this.state = memento.GetState();
        }
        // Восстанавливает состояние Создателя из объекта снимка.
        public void Restore(IMemento memento)
        {
            if (!(memento is ConcreteMemento))
            {
                throw new Exception("Unknown memento class " + memento.ToString());
            }

            this._state = memento.GetState();
            Console.Write($"Originator: My state has changed to: {_state}");
        }
Exemple #4
0
        public void Restore(IMemento memento)
        {
            if (!(memento is ConcreteGameLevel))
            {
                throw new Exception("Unknown memento class " + memento.ToString());
            }

            this._gameState = memento.GetState();
            Console.Write($"Notification: Time of the game has changed to: {_gameState}");
        }
Exemple #5
0
        // Restaura el estado del Originator a partir de un objeto memento.
        public void Restore(IMemento memento)
        {
            if (!(memento is ConcreteMemento))
            {
                throw new Exception("Clase memento desconocida " + memento.ToString());
            }

            _state = memento.GetState();
            Console.WriteLine($"Originator: Mi estado ha cambiado a: {_state}");
        }
        /// <summary>
        /// Restores the Originator's state from a memento object
        /// </summary>
        /// <param name="memento">Memento hold the state which is need to be restored</param>
        public void Restore(IMemento memento)
        {
            // Throw exception if memento is not the current memento's type
            if (!(memento is ConcreteMementoA))
            {
                throw new Exception($"Unknown memento class { memento.ToString() }");
            }

            _currentState = memento.GetState();
        }
Exemple #7
0
        // Восстанавливает состояние Создателя из объекта снимка.
        public void Restore(IMemento memento)
        {
            if (!(memento is ConcreteMemento))
            {
                throw new Exception("Неизвестный снимок " + memento.ToString());
            }

            this._state = memento.GetState();
            Console.WriteLine($"Текущее состояние: {_state}");
        }
Exemple #8
0
        // Restaura o estado do Originador a partir de um objeto memento.
        public void Restore(IMemento memento)
        {
            if (!(memento is ConcreteMemento))
            {
                throw new Exception("Classe de memento desconhecida " + memento.ToString());
            }

            this._state = memento.GetState();
            Console.Write($"Originador: Meu estado mudou para {_state}");
        }
Exemple #9
0
        //Restores the Originator's stanje from a memento object.
        public void Restore(IMemento memento)
        {
            if (!(memento is ConcreteMemento))
            {
                throw new Exception("Unknown memento class " + memento.ToString());
            }

            this._stanje = memento.GetState();
            SingletonTvKuca.Instanca.SetRasporedPrograma(this._stanje);
            Console.Write($"Originator: My stanje has changed to: {_stanje}");
        }
Exemple #10
0
        // Restores the Originator's state from a memento object.
        public void Restore(IMemento memento)
        {
            if (!(memento is ConcreteMemento))
            {
                throw new Exception("Unknown memento class " + memento.ToString());
            }
            double prevBalance = _state.money;

            _state = memento.GetState();
            Console.WriteLine($"Bank account balance was {prevBalance}. It has changed to: {_state.money}");
        }
Exemple #11
0
        /// <summary>
        /// Pushes an memento into the undo stack, any time the state of <see cref="subject"/> changes.
        /// </summary>
        /// <param name="m"></param>
        /// <remarks>
        /// This method MUST be properly involked by programmers right before (preferably) or right after
        /// the state of <see cref="subject"/> is changed.
        /// Whenever <see cref="Do(IMemento&lt;T&gt;)"/> is called, the status of <see cref="InUndoRedo"/>
        /// should aways be checked first. See details at <see cref="InUndoRedo"/>.
        /// This method causes redo stack to be cleared.
        /// </remarks>
        /// <seealso cref="InUndoRedo"/>
        /// <seealso cref="Undo()"/>
        /// <seealso cref="Redo()"/>
        public void Do(IMemento <T> m)
        {
            Debug.WriteLine(string.Format("UndoRedo.Do {0}", m.ToString()));
            if (inUndoRedo)
            {
                throw new InvalidOperationException("Involking do within an undo/redo action.");
            }

            if (tempMemento == null)
            {
                _Do(m);
            }
            else
            {
                tempMemento.Add(m);
            }
        }