/// <summary> /// Retrieves a list of all the game data history stored in local storage. /// </summary> /// <returns></returns> public async Task <GameDataList> RetrieveGameData() { var data = new GameDataList(); var dataFile = await ApplicationData.Current.LocalFolder.CreateFileAsync( BaseFileName, CreationCollisionOption.OpenIfExists); if (dataFile == null) { return(data); } using (var dataInputStream = await dataFile.OpenStreamForReadAsync()) { try { var binaryReader = new BinaryReader(dataInputStream); data.Read(binaryReader); } catch (EndOfStreamException) { // Swallow this exception which is thrown when you try to deserialize an empty obj. } } return(data); }
/// <summary> /// Adds the pending game data to local storage. /// </summary> /// <returns></returns> public async Task StoreGameData(GameData dataToSave) { if (dataToSave.GameDuration <= 0 || dataToSave.GameHost == null || dataToSave.GameMoves == null || dataToSave.PlayerDictionary == null || dataToSave.Winner == null) { #if DEBUG throw new ArgumentException("Invalid game data."); #else return; #endif } // // Retrieve existing data in storage so that it isn't overwritten. // _gameDataList._GameData.Clear(); _gameDataList = await RetrieveGameData(); _gameDataList._GameData.Add(dataToSave); // // Now write the data to the file. // var localFolder = ApplicationData.Current.LocalFolder; var file = await localFolder.CreateFileAsync( BaseFileName, CreationCollisionOption.OpenIfExists); using (var streamFile = await file.OpenStreamForWriteAsync()) { var binaryWriter = new BinaryWriter(streamFile); _gameDataList.Write(binaryWriter); } }
/// <summary> /// Adds the pending game data to local storage. /// </summary> /// <returns></returns> public async Task StoreGameData(GameData dataToSave) { if (dataToSave.GameDuration <= 0 || dataToSave.GameHost == null || dataToSave.GameMoves == null || dataToSave.PlayerDictionary == null || dataToSave.Winner == null) { #if DEBUG throw new ArgumentException("Invalid game data."); #else return; #endif } // // Retrieve existing data in storage so that it isn't overwritten. // _gameDataList._GameData.Clear(); _gameDataList = await RetrieveGameData(); _gameDataList._GameData.Add(dataToSave); // // Now write the data to the file. // var localFolder = ApplicationData.Current.LocalFolder; var file = await localFolder.CreateFileAsync( BaseFileName, CreationCollisionOption.OpenIfExists); using (var streamFile = await file.OpenStreamForWriteAsync()) { var binaryWriter = new BinaryWriter(streamFile); _gameDataList.Write(binaryWriter); } }
private GameDataHistory() { _gameDataList = new GameDataList(); }
public void Initialize() { _testGameMoveDataPoint = new GameMoveDataPoint { MoveType = MoveType.Dump, Player = "NewPlayer", TimeOfMove = 5 }; _playerGameStats = new PlayerGameStats { AvgTimeBetweenDumps = 10, AvgTimeBetweenPeels = 5, IsWinner = true, NumberOfDumps = 3, NumberOfPeels = 0, PerformedFirstPeel = false, RawGameData = new List<GameMoveDataPoint>() {_testGameMoveDataPoint, _testGameMoveDataPoint, _testGameMoveDataPoint} }; _gameData = new GameData {GameDuration = 10, GameHost = "GameHost", GameStartTime = DateTime.Now, Winner = "NewPlayer"}; _gameData.GameMoves.Add(_testGameMoveDataPoint); _gameData.GameMoves.Add(_testGameMoveDataPoint); _gameData.PlayerDictionary.Add("NewPlayer", _playerGameStats); _gameData.PlayerDictionary.Add("NewPlayer2", _playerGameStats); _gameDataList = new GameDataList(); _gameDataList._GameData.Add(_gameData); _gameDataList._GameData.Add(_gameData); _stringPacketV1 = new PacketV1 { PacketType = PacketType.c_QueryIfAliasAvailable, Data = "Mobius", Recipients = null, Sender = "*****@*****.**" }; _IBinarySerializablePacketV1 = new PacketV1 { PacketType = PacketType.c_UploadGameData, Data = _gameData, Recipients = null, Sender = "*****@*****.**" }; _packetBase = new PacketBase { PacketVersion = PacketVersion.Version1, Data = _stringPacketV1 }; }
private GameDataHistory() { _gameDataList = new GameDataList(); }
/// <summary> /// Retrieves a list of all the game data history stored in local storage. /// </summary> /// <returns></returns> public async Task<GameDataList> RetrieveGameData() { var data = new GameDataList(); var dataFile = await ApplicationData.Current.LocalFolder.CreateFileAsync( BaseFileName, CreationCollisionOption.OpenIfExists); if (dataFile == null) { return data; } using (var dataInputStream = await dataFile.OpenStreamForReadAsync()) { try { var binaryReader = new BinaryReader(dataInputStream); data.Read(binaryReader); } catch (EndOfStreamException) { // Swallow this exception which is thrown when you try to deserialize an empty obj. } } return data; }