/// <summary> /// Fill properties from the current match /// </summary> /// <param name="_CurrentMatch"></param> public void Fill(vmMatch _CurrentMatch) { CurrentPointDescription = _CurrentMatch.CurrentPointDescription; NamePlayer1 = _CurrentMatch.NamePlayer1; NamePlayer2 = _CurrentMatch.NamePlayer2; ScorePlayer1 = _CurrentMatch.ScorePlayer1; ScorePlayer2 = _CurrentMatch.ScorePlayer2; PrintableScore = _CurrentMatch.Match.PrintableScore(); Status = _CurrentMatch.Status; MatchType = _CurrentMatch.MatchType; Surface = _CurrentMatch.Surface; Duration = _CurrentMatch.Duration; Server = _CurrentMatch.Server; Winner = _CurrentMatch.Winner; InProgress = _CurrentMatch.InProgress; Completed = _CurrentMatch.Completed; Paused = !_CurrentMatch.Match.Duration.SessionInProgress; IsExtendPossible = _CurrentMatch.IsExtendPossible; Undo = _CurrentMatch.Undo; Switch = _CurrentMatch.Switch; TotalSets = new vmSetScore(_CurrentMatch.TotalSets); CurrentSetScore = new vmSetScore(_CurrentMatch.CurrentSetScore); StatisticsCollection = _CurrentMatch.StatisticsCollection; Notify(); }
/// <summary> /// Store the current match to the local datastore /// </summary> public async Task StoreMatch(vmMatch _vmMatch) { //Store the match await StoredMatches.Update(_vmMatch); //Save the stored matches await StoredMatches.Save(); //Update and save total statistics TotalStatistics.Add(_vmMatch); await TotalStatistics.Save(); //Fire event OnMatchStored(EventArgs.Empty); }
/// <summary> /// /// </summary> /// <param name="Match"></param> /// <returns></returns> public async Task <bool> Update(vmMatch Match) { vmStoredMatch StoredMatch = new vmStoredMatch(Match.Match); //Remove an existing match with the same ID Remove(Match); //Add the new or updated match this.Insert(0, StoredMatch); //Reorder the collection by start time this.OrderByDescending(x => x.StartTime); //It worked, return true; return(true); }
/// <summary> /// Create a new match and start it /// </summary> public async Task NewMatch() { //Save the settings to the local storage, do not wait for it (no await) try { String StoreSettingsNewMatch = Helpers.Serializer.SerializeAndCompress(vmNewMatch); await Helpers.LocalStorage.Save(StoreSettingsNewMatch, "newmatchsettings.gz", false); } catch (Exception) { } //Start the new match CurrentMatch = new vmMatch(); CurrentMatch.Start(vmNewMatch); }
/// <summary> /// Resume the match identified by the given Guid. /// </summary> /// <param name="MatchId"></param> public async Task ResumeMatch(Guid MatchId) { try { vmMatch resumeMatch = new vmMatch(); await resumeMatch.Load(MatchId); CurrentMatch = resumeMatch; resumeMatch.CurrentPoint.LogLevel = resumeMatch.Match.LogLevel; TotalStatistics.Remove(CurrentMatch); resumeMatch.NewPoint(); } catch (Exception) { throw new Exception("An unexpected error occured while resuming match."); } }
/// <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(); } }
/// <summary> /// Remove the match from the collection of total statistics /// </summary> /// <param name="Match"></param> public void Remove(vmMatch Match) { Statistics.Remove(Match.Match); }
/// <summary> /// Add the match to the collection of total statistics /// </summary> /// <param name="Match"></param> public void Add(vmMatch Match) { Statistics.Add(Match.Match); }
/// <summary> /// Remove a match from the collection with the same ID as the given match /// </summary> /// <param name="Match"></param> public void Remove(vmMatch Match) { Remove(Match.Match.ID); }
/// <summary> /// Remove a match from the collection with the same ID as the given match /// </summary> /// <param name="Match"></param> public async Task RemoveAndDelete(vmMatch Match) { await RemoveAndDelete(Match.Match.ID); }