Я создаю приложение, в котором есть несколько турниров, и в каждом турнире есть несколько коллекций.
IsolatedStorage работает правильно, только если я пишу название турнира, если я пытаюсь добавить что-либо в его коллекции, он вылетает.
Мой турнирный класс
public class TournamentMain
{
public int ID = 0;
public string name { get; set; }
public double buy_in { get; set; }
public double re_buy { get; set; }
public double add_on { get; set; }
public int blindindex = 1;
public int placeindex = 1;
public int playerindex = 1;
public ObservableCollection<Blind> blinds { get; set; }
public ObservableCollection<Player> players { get; set; }
public ObservableCollection<Place> places { get; set; }
public ObservableCollection<Paidplace> paidplaces {get; set;}
public TournamentMain() {
players = new ObservableCollection<Player>();
places = new ObservableCollection<Place>();
blinds = new ObservableCollection<Blind>();
paidplaces = new ObservableCollection<Paidplace>();
} }
Мой класс хранения
public class StorageSaveing
{
static XmlSerializer serializer;
public static void saveIT()
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = new IsolatedStorageFileStream("data.txt",
FileMode.Create,
FileAccess.Write,
store))
{
serializer = new XmlSerializer(typeof(ObservableCollection<TournamentMain>));
serializer.Serialize(stream, App.tournaments);
}
}
public static ObservableCollection<TournamentMain> loadIT()
{
using( var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = new IsolatedStorageFileStream("data.txt",
FileMode.OpenOrCreate,
FileAccess.Read,
store))
using( var reader = new StreamReader(stream))
{
serializer = new XmlSerializer(typeof(ObservableCollection<TournamentMain>));
return reader.EndOfStream
? new ObservableCollection<TournamentMain>()
: (ObservableCollection<TournamentMain>)serializer.Deserialize(reader);
}
}
}
Вызывается, когда приложение закрывается и открывается
Любая помощь очень ценится !!:)
Вот класс TournamentMain
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Collections.Generic;
namespace PokerAssistant
{
public class TournamentMain
{
public int ID = 0;
public string name { get; set; }
public double buy_in { get; set; }
public double re_buy { get; set; }
public double add_on { get; set; }
public int blindindex = 1;
public int placeindex = 1;
public int playerindex = 1;
private ObservableCollection<Blind> _blinds;
public ObservableCollection<Blind> blinds { get{
return _blinds;
}
set {
_blinds = value;
}
}
public ObservableCollection<Player> players { get; set; }
public ObservableCollection<Place> places { get; set; }
public ObservableCollection<Paidplace> paidplaces {get; set;}
public TournamentMain() {
players = new ObservableCollection<Player>();
places = new ObservableCollection<Place>();
_blinds = new ObservableCollection<Blind>();
paidplaces = new ObservableCollection<Paidplace>();
}
public double calculatePot() {
double totalsum = 0;
foreach (Player player in players)
{
totalsum += player.cash;
}
foreach (Blind blind in blinds)
{
totalsum += blind.Ante * players.Count;
}
return totalsum;
}
public void setPlacesList() {
int i=1;
foreach(Double place in calculatePlaces()){
Paidplace p = new Paidplace();
p.name = i + ". " + place + "$";
paidplaces.Add(p);
i++;
}
}
public List<double> calculatePlaces() {
List<double> paidplaces = new List<double>();
double total = 0;
foreach (Place place in places)
{
paidplaces.Add(calculatePot() * (place.place_pr/100));
total += calculatePot() * (place.place_pr / 100);
}
total = calculatePot()-total;
paidplaces.Add(total);
return paidplaces;
}
public int playersCount() {
return players.Count;
}
}
}