private async Task SaveMatchState() { var localSettings = ApplicationData.Current.LocalSettings; vmMatchState _State = new vmMatchState(); await TennisMatch.Save("tennis_pebble.xml"); _State.Fill(TennisMatch); await Tennis_Statistics.Helpers.LocalStorage.Save(_State.Serialize(), "tennismatchstate.json", false); localSettings.Values[Constants.TennisState] = "1"; await SendPebbleTennisScore(_State, TennisMatch); }
/// <summary> /// Tennis handler /// </summary> private async Task TennisHandler() { if (!PebbleConnector.IsBackgroundTaskRunningStatusSet(PebbleConnector.Initiator.Tennis)) { return; } //initialise settings var localSettings = ApplicationData.Current.LocalSettings; var roamingSettings = ApplicationData.Current.RoamingSettings; if (localSettings.Values.Keys.Contains(Constants.BackgroundTennis) && (bool)localSettings.Values[Constants.BackgroundTennis]) { //Initiate tennis match if (TennisMatch == null) { TennisMatch = new vmMatch(); await TennisMatch.Load("tennis_pebble.xml"); if (TennisMatch.Match == null) { System.Diagnostics.Debug.WriteLine("Initialize Tennis Match in background."); vmNewMatch _vmNewMatch = await vmNewMatch.Load(); TennisMatch = new vmMatch(); TennisMatch.Start(_vmNewMatch); } else { TennisMatch.NewPoint(); } vmMatchState _State = new vmMatchState(); _State.Fill(TennisMatch); await Tennis_Statistics.Helpers.LocalStorage.Save(_State.Serialize(), "tennismatchstate.json", false); localSettings.Values[Constants.TennisState] = "1"; System.Diagnostics.Debug.WriteLine("Tennis Match state stored"); _pc.Pebble._protocol.MessageReceived += this.TennisMessageReceived; Guid TennisWatchApp = Guid.Parse(Constants.TennisAppGuid); await _pc.Launch(TennisWatchApp); await SendPebbleTennisScore(_State, TennisMatch); // await SendPebbleTennisScore(_State); } } //A new state requested if (localSettings.Values.Keys.Contains(Constants.TennisState) && (string)localSettings.Values[Constants.TennisState] == "2") { await SaveMatchState(); } //Check for and process command if (localSettings.Values.Keys.Contains(Constants.TennisCommand) && TennisMatch != null) { String Command = (String)localSettings.Values[Constants.TennisCommand]; System.Diagnostics.Debug.WriteLine("Processing tennis command: " + Command); switch (Command) { case "switch": TennisMatch.cmdSwitchServer.Execute(null); AddToLog("Tennis: switch command"); break; case "stop": TennisMatch.Terminate(); PebbleConnector.ClearBackgroundTaskRunningStatus(PebbleConnector.Initiator.Tennis); AddToLog("Tennis: stop command"); break; case "suspend": TennisMatch.Pause(); PebbleConnector.ClearBackgroundTaskRunningStatus(PebbleConnector.Initiator.Tennis); AddToLog("Tennis: suspend command"); break; case "extend": TennisMatch.cmdExtendMatch.Execute(null); AddToLog("Tennis: extend command"); break; } localSettings.Values.Remove(Constants.TennisCommand); await SaveMatchState(); } }