public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null) { return(GameTimeConverter.ToString((TimeSpan)value)); } else { return(null); } }
public string ToJson() { StringBuilder result = new StringBuilder(); result.Append('{'); result.Append("\"startTime\": \"" + (StartTime.HasValue ? StartTime.Value.ToString("HH:mm") : "--:--") + "\""); result.Append(", \"team1\": \"" + Team1 + "\""); if (!String.IsNullOrEmpty(Team1Flag)) { result.Append(", \"team1Flag\": \"" + Team1Flag + "\""); } result.Append(", \"team1Score\": " + Team1Score.ToString()); result.Append(", \"team2\": \"" + Team2 + "\""); if (!String.IsNullOrEmpty(Team2Flag)) { result.Append(", \"team2Flag\": \"" + Team2Flag + "\""); } result.Append(", \"team2Score\": " + Team2Score.ToString()); if (!String.IsNullOrEmpty(Pool)) { result.Append(", \"pool\": \"" + Pool + "\""); } else { result.Append(", \"pool\": \"\""); } if (Periods.CurrentPeriod != null) { result.Append(", \"period\": \"" + Periods.CurrentPeriod.Name + "\""); result.Append(", \"periodIsActive\": \"" + (Periods.CurrentPeriod.Status == GamePeriodStatus.Active ? "1" : "0") + "\""); result.Append(", \"timeRemaining\": \"" + GameTimeConverter.ToString(Periods.CurrentPeriod.TimeRemaining) + "\""); } else { result.Append(", \"period\": \"None\""); result.Append(", \"periodIsActive\": false"); result.Append(", \"timeRemaining\": \"0:00\""); } if (Parent != null && Parent.Parent != null) { result.Append(", \"shotClockTime\": \"" + Parent.Parent.ShotTime.ToString() + "\""); } else { result.Append(", \"shotClockTime\": \"0\""); } if (Result != GameResult.None) { result.Append(", \"hasCompleted\": true"); result.Append(", \"result\": \"" + ResultDescription + "\""); result.Append(", \"team1Points\": " + Team1Points.ToString()); result.Append(", \"team2Points\": " + Team2Points.ToString()); } else { result.Append(", \"hasCompleted\": false"); } result.Append('}'); return(result.ToString()); }