Esempio n. 1
0
        private void open_Click(object sender, RoutedEventArgs e)
        {
            var fileContent = string.Empty;
            var filePath    = string.Empty;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = "D:\\";
                openFileDialog.Filter           = "(*.xml)|*.xml";
                openFileDialog.FilterIndex      = 2;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //Get the path of specified file
                    filePath = openFileDialog.FileName;

                    //Read the contents of the file into a stream
                    var fileStream = openFileDialog.OpenFile();

                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        fileContent = reader.ReadToEnd();
                    }
                    if (filePath.Length > 0)
                    {
                        OldGame oldGame = new OldGame();
                        oldGame = SerializeAndDeserialize.DeserializeObjectToXML <OldGame>(filePath);
                        var temp = new BoardVM(oldGame);

                        DataContext = temp;
                    }
                }
            }
        }
Esempio n. 2
0
        private void save_Click(object sender, RoutedEventArgs e)
        {
            Stream         myStream;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter           = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            saveFileDialog1.FilterIndex      = 2;
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    myStream.Close();

                    OldGame oldGame = new OldGame();
                    oldGame.Pieces           = (DataContext as BoardVM).Pieces;
                    oldGame.Player1Serialize = BoardVM.Player1;
                    oldGame.Player2Serialize = BoardVM.Player2;

                    SerializeAndDeserialize.SerializeObjectToXML <OldGame>(oldGame, saveFileDialog1.FileName);
                }
            }
        }
Esempio n. 3
0
 public void Initialize()
 {
     instance          = this;
     premio_por_enviar = PlayerPrefs.GetString("url_pendiente");
 }