Exemplo n.º 1
0
        public IMemento CreateMemento()
        {
            this.State.TypeOfPlay = (int)this.TypeOfPlay;

            if (this.CurrentSong != null)
            {
                this.State.SongFilePath = this.CurrentSong?.FilePath;
                this.State.Time         = this.CurrentSongPosition.ToString();
            }

            MementoOfState memento = new MementoOfState();

            memento.SetState(this.State);
            return(memento);
        }
Exemplo n.º 2
0
        private void Save()
        {
            MementoOfState memento = (MementoOfState)Player.Instance.CreateMemento();

            FileStream fileStream = null;

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