示例#1
0
 public void RestoreFromMemento(IMemento m)
 {
     if (!m.GetType().Equals(typeof(NullMemento)))
     {
         InternalState = m.GetState();
     }
 }
示例#2
0
 public void Restore(IMemento memento)
 {
     if (memento is not BalanceMemento)
     {
         throw new UnknownMementoClassException(memento.ToString());
     }
     Balance = memento.GetState();
 }
示例#3
0
        public void Restore(IMemento memento)
        {
            if (!(memento is ConcreteMemento))
            {
                throw new Exception("Unknown memento class");
            }

            this._cities = memento.GetState();
        }
示例#4
0
        public void Restore(IMemento memento)
        {
            if (!(memento is ConcreteMemento))
            {
                throw new ArgumentException("Unknown memento class: " + memento.GetType().Name);
            }

            _state = memento.GetState();
        }
示例#5
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();
        }
        /// <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();
        }
示例#7
0
        public bool Restore(IMemento memento)
        {
            if (!(memento is OriginatorMemento))
            {
                return(false);
            }

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

            this._state = memento.GetState();
            Console.WriteLine($"Текущее состояние: {_state}");
        }
示例#9
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}");
        }
示例#10
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}");
        }
示例#11
0
        // Восстанавливает состояние Создателя из объекта снимка.
        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}");
        }
示例#12
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);
            }

            _state = memento.GetState().ToString();
            _outputHelper.WriteLine($"Originator: My state has changed to: {_state}");
        }
示例#13
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}");
        }
        public void Restore(IMemento memento)
        {
            if (!(memento is ConcreteMemento))
            {
                throw new InvalidMementoException();
            }

            this.IsRestored           = true;
            this.CurrentEditorContent = memento.GetState();
        }
示例#15
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}");
        }
示例#16
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}");
        }
示例#17
0
        public void SetMemento(IMemento memento)
        {
            this.State      = memento.GetState();
            this.TypeOfPlay = (TypeOfPlay)State.TypeOfPlay;

            this.CreatePlaylist(this.TypeOfPlay);

            if (string.IsNullOrEmpty(State.SongFilePath) == false)
            {
                this.CurrentSong = Songs.FirstOrDefault(item => item.FilePath == State.SongFilePath);

                mediaPlayer.Open(new Uri(this.CurrentSong.FilePath));
                AddSongToHistory(CurrentSong);
                mediaPlayer.MediaOpened += MediaPlayer_MediaOpened;
            }
        }
示例#18
0
        private void Read()
        {
            FileInfo fileInfo = new FileInfo("data.xml");

            if (!fileInfo.Exists)
            {
                return;
            }

            FileStream fileStream = null;

            IMemento memento = null;

            try
            {
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                fileStream = new FileStream("data.xml", FileMode.OpenOrCreate);
                memento    = (MementoOfState)binaryFormatter.Deserialize(fileStream);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }

            if (memento != null)
            {
                this.folerPath = memento.GetState().FolderPath;

                if (string.IsNullOrEmpty(this.folerPath))
                {
                    return;
                }

                try
                {
                    List <string> files = Directory.GetFiles(this.folerPath, "*.mp3").ToList();
                    Player.Instance.LoadSongs(files, this.folerPath);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                RaisePropertyChanged(nameof(this.IsFilesLoaded));

                Player.Instance.SetMemento(memento);

                switch (Player.Instance.TypeOfPlay)
                {
                case TypeOfPlay.Normal:
                    this._playNormal   = true;
                    this._playRandom   = false;
                    this._playReversed = false;
                    break;

                case TypeOfPlay.Random:
                    this._playNormal   = false;
                    this._playRandom   = true;
                    this._playReversed = false;
                    break;

                case TypeOfPlay.Reversed:
                    this._playNormal   = false;
                    this._playRandom   = false;
                    this._playReversed = true;
                    break;

                default:
                    break;
                }

                RaisePropertyChanged(nameof(this.PlayNormal));
                RaisePropertyChanged(nameof(this.PlayRandom));
                RaisePropertyChanged(nameof(this.PlayReversed));
            }
        }
示例#19
0
 public void Restore(IMemento memento)
 {
     _map = memento.GetState();
 }
示例#20
0
 public void Restore(IMemento memento)
 {
     _state = memento.GetState().ToList();
 }
示例#21
0
 public void Restore(IMemento memento)
 {
     expression = memento.GetState();
 }
示例#22
0
 public void Restore(IMemento memento)
 {
     _state = memento.GetState();
     PrintStateChange(nameof(Restore), null);
 }
示例#23
0
 public void Restore(IMemento memento)
 {
     this.state = memento.GetState();
 }