public void SetSource(TennisStatistics Source) { _Source = Source; Children.Clear(); var allValues = (vmStatistic.StatisticElement[])Enum.GetValues(typeof(vmStatistic.StatisticElement)); vmStatistic LastHeader = null; TennisMatch.LogLevelEnum _LogLevel = Source.currentMatch.LogLevel; foreach (var element in allValues) { if (VisibleLogLevel(_LogLevel, element)) { vmStatistic newElement = new vmStatistic(); newElement.Statistic = element; newElement.Source = Source; newElement.Visible = true; // _StatisticElements.Add(newElement); if (newElement.Header) { LastHeader = newElement; _StatisticElements.Add(newElement); Children.Add(LastHeader); } else { if (LastHeader != null) { LastHeader.Children.Add(newElement); } } } } }
/// <summary> /// Return true if element is visible in the current LogLevel /// </summary> /// <param name="Element"></param> /// <returns></returns> private bool VisibleLogLevel(TennisMatch.LogLevelEnum LogLevel, vmStatistic.StatisticElement Element) { switch (LogLevel) { case TennisMatch.LogLevelEnum.Placement: case TennisMatch.LogLevelEnum.Shots: return(true); case TennisMatch.LogLevelEnum.Errors: switch (Element) { case vmStatistic.StatisticElement.ShotsHeader: case vmStatistic.StatisticElement.ForehandWinner: case vmStatistic.StatisticElement.ForehandForcedError: case vmStatistic.StatisticElement.ForehandUnforcedError: case vmStatistic.StatisticElement.BackhandWinner: case vmStatistic.StatisticElement.BackhandForcedError: case vmStatistic.StatisticElement.BackhandUnforcedError: case vmStatistic.StatisticElement.VolleyWinner: case vmStatistic.StatisticElement.VolleyForcedError: case vmStatistic.StatisticElement.VolleyUnforcedError: return(false); default: return(true); } case TennisMatch.LogLevelEnum.Points: switch (Element) { case vmStatistic.StatisticElement.ShotsHeader: case vmStatistic.StatisticElement.ForehandWinner: case vmStatistic.StatisticElement.ForehandForcedError: case vmStatistic.StatisticElement.ForehandUnforcedError: case vmStatistic.StatisticElement.BackhandWinner: case vmStatistic.StatisticElement.BackhandForcedError: case vmStatistic.StatisticElement.BackhandUnforcedError: case vmStatistic.StatisticElement.VolleyWinner: case vmStatistic.StatisticElement.VolleyForcedError: case vmStatistic.StatisticElement.VolleyUnforcedError: case vmStatistic.StatisticElement.TotalWinners: case vmStatistic.StatisticElement.TotalUnforcedErrors: case vmStatistic.StatisticElement.TotalForcedErrors: return(false); default: return(true); } // return true; } return(false); }