Beispiel #1
0
 private void ViewModel_LoadTriggered(object sender, SaveEventArgs e)
 {
     try
     {
         OpenFileDialog dialog = new OpenFileDialog();
         dialog.DefaultExt = ".json";
         dialog.Filter     = "JSON File|*.json";
         var result = dialog.ShowDialog();
         if (result.HasValue && result.Value && File.Exists(dialog.FileName))
         {
             e.SaveData = JsonConvert.DeserializeObject <IEnumerable <Combatant> >(File.ReadAllText(dialog.FileName));
         }
     }
     catch (Exception ex)
     {
     }
 }
Beispiel #2
0
 private void ViewModel_SaveTriggered(object sender, SaveEventArgs e)
 {
     try
     {
         string         serializedSaveData = JsonConvert.SerializeObject(e.SaveData);
         SaveFileDialog dialog             = new SaveFileDialog();
         dialog.DefaultExt = ".json";
         dialog.Filter     = "JSON File|*.json";
         var result = dialog.ShowDialog();
         if (result.HasValue && result.Value)
         {
             File.WriteAllText(dialog.FileName, serializedSaveData);
         }
     }
     catch (Exception ex)
     {
     }
 }