/// <summary> /// Populate the datarequest for sharing. The match status will be published /// </summary> /// <param name="_Request"></param> public async void PopulateDataRequest(DataRequest _Request) { Tennis_Statistics.Helpers.Settings _Settings = Tennis_Statistics.Helpers.Settings.GetInstance(); bool ShareLocation = _Settings.GetBoolean("ShareLocation", false); bool ShareSetScores = _Settings.GetBoolean("ShareSetScores", true); bool ShareDuration = _Settings.GetBoolean("ShareDuration", true); await PopulateDataRequest(_Request, ShareLocation, ShareSetScores, ShareDuration, false); }
/// <summary> /// Populate the datarequest for sharing. The match status will be published /// </summary> /// <param name="_Request"></param> public async void PopulateDataRequest(DataRequest _Request) { try { Tennis_Statistics.Helpers.Settings _Settings = Tennis_Statistics.Helpers.Settings.GetInstance(); if (Match.Status != TennisMatch.MatchStatus.InProgress) { bool ShareLocation = _Settings.GetBoolean("ShareLocation", false); bool ShareSetScores = _Settings.GetBoolean("ShareSetScores", true); bool ShareDuration = _Settings.GetBoolean("ShareDuration", true); String Location = ""; String SetScores = ""; String Duration = ""; if (ShareLocation) { Location = String.Format(" at {0}", Match.Location); } if (ShareDuration) { TimeSpan tsDuration = Match.Duration.Duration; Duration = String.Format("The match lasted {0}:{1:D2}. ", ((tsDuration.Days * 24) + tsDuration.Hours), tsDuration.Minutes); } if (ShareSetScores) { if (Match.Sets.Count == 1) { SetScores = String.Format("The score is {0}. ", Match.PrintableScore()); } else { SetScores = String.Format("The sets are {0}. ", Match.PrintableScore()); } } String LocalPlayer = Match.Contestant1.getName(); if (Match.Contestant2.ContainsLocalPlayer) { LocalPlayer = Match.Contestant2.getName(); } String Title = String.Format("{0} completed a tennis match.", LocalPlayer); String Message; if (Match.Winner != 0 /*Match.Status == TennisMatch.MatchStatus.Completed*/) { Message = String.Format("{0} won the tennis match against {1}{2}. {3}{4}", Match.GetContestant(Match.Winner).getName(), Match.GetContestant(3 - Match.Winner).getName(), Location, SetScores, Duration ); } else { String OtherPlayer = LocalPlayer == Match.Contestant1.getName() ? Match.Contestant2.getName() : Match.Contestant1.getName(); if (ShareLocation) { Location = "It was played" + Location + ". "; } Message = String.Format("The match against {0} was terminated. {1}{2}{3}", OtherPlayer, Location, SetScores, Duration); } if (!Helpers.Purchases.Available("HASHTAG")) { Message += "Recorded with #TennisStatistics for Windows Phone."; } _Request.Data.Properties.Title = Title; _Request.Data.SetText(Message); if (AddAttachmentToDataRequest) { DataRequestDeferral deferral = _Request.GetDeferral(); await Save("export.xml"); IStorageFile Attachment = await Tennis_Statistics.Helpers.LocalStorage.GetFile("export.xml"); List <IStorageItem> storageItems = new List <IStorageItem>(); storageItems.Add(Attachment); _Request.Data.SetStorageItems(storageItems); deferral.Complete(); } //_Request.Data.SetWebLink(new Uri("http://www.nu.nl")); //_Request.Data.Properties.Description = "HTML!"; // string htmlFormat = HtmlFormatHelper.CreateHtmlFormat(Message); //_Request.Data.SetHtmlFormat(htmlFormat); } } catch (Exception e) { _Request.Data.Properties.Title = "Error"; _Request.Data.SetText("An error occurred: " + e.InnerException); } }