public void Delete() { Settings.LeageWikiTemplates.Remove(SelectedTemplate); MarkAllValid(); _IsInNewMode = false; Settings.LogDeleted(SelectedTemplate); SelectedTemplate = null; }
/// <summary> /// Versucht den übergebenen Vorlagencode in eine <see cref="LeagueWikiTemplate"/> zu parsen. Übernimmt die ID der optional übergebenen <see cref="LeagueWikiTemplate"/>. /// Wird keine übergeben, wird die nächsthöhere ID aus <see cref="Settings.LeageWikiTemplates"/> genutzt. /// </summary> /// <param name="templateCode">Vorlagencode</param> /// <param name="oldTemplate"><see cref="LeagueWikiTemplate"/> deren ID übernommen werden soll</param> /// <returns>Eine <see cref="LeagueWikiTemplate"/>-Instanz, wenn Vorlage nicht geparst werden konnte, <c>null</c></returns> public static LeagueWikiTemplate ParseLeagueTemplate(string templateCode, LeagueWikiTemplate oldTemplate = null) { try { var id = (oldTemplate == null || oldTemplate == LeagueWikiTemplate.NoneTemplate) ? Settings.LeageWikiTemplates.GetNewID() : oldTemplate.ID; bool isDate = HasLeagueTemplateDate(templateCode); bool isLocation = HasLeagueTemplateLocation(templateCode); var teamRegex = new Regex(Settings.WikiStrings.TemplateLeagueTeamRegexString); var teamsCount = teamRegex.Matches(templateCode).Count; var nameRegex = new Regex(WikiStrings.TemplateNameRegexString); var name = RemoveNewLines(nameRegex.Match(templateCode).Value); return new LeagueWikiTemplate(id, name, templateCode, teamsCount, isDate, isLocation); } catch { return null; } }
/// <summary> /// Generiert den Code für die Darstellung der Ergebnisse der angegebenen <see cref="FootballLeague"/> und nutzt dazu die angegebene <see cref="LeagueWikiTemplate"/> /// </summary> /// <param name="league"><see cref="FootballLeague"/> der darzustellenden Ergebnisse</param> /// <param name="template"><see cref="LeagueWikiTemplate"/> der darzustellenden Ergebnisse</param> /// <returns>Generierten Ergebniscode</returns> public static string GenerateResultsCode(FootballLeague league, LeagueWikiTemplate template) { if(template == null) throw new NotImplementedException("Results output without template not implemented"); var templateRegex = new Regex(WikiStrings.TemplateRegexString); var teamRegex = new Regex(@"(A\d+)"); var teamIndexRegex = new Regex(@"(\d+)"); var templateCode = Regex.Replace(template.TemplateCode, @"\r\n?|\n", String.Empty); string[] templateLines = templateCode.Split('|'); string[] filledLines = new string[templateLines.Length + 1]; // Vorlagenzeilen einzeln durchgehen for(int i = 0; i < templateLines.Length; i++) { var line = templateLines[i].Replace(WikiStrings.TemplateEnd, String.Empty); var templateMatch = templateRegex.Match(line); var teamMatches = teamRegex.Matches(line); // Wenn nur ein Team enthalten ist: Teamnamen if(teamMatches.Count == 1) { var index = Int32.Parse(teamMatches[0].Value.Substring(1)); var team = league.Teams[index - 1]; line = String.Format("{0}{1}{2}", WikiStrings.TemplateVariableStartRegexString, line, team.Name); } // Wenn 2 Teams enthalten sind: Ergebnisse oder Zusatzdaten else if(teamMatches.Count == 2) { var index1 = Int32.Parse(teamMatches[0].Value.Substring(1)); var team1 = league.Teams[index1 - 1]; var index2 = Int32.Parse(teamMatches[1].Value.Substring(1)); var team2 = league.Teams[index2 - 1]; var match = league.Matches.Where(x => x.TeamA == team1 && x.TeamB == team2).FirstOrDefault(); line = String.Format("{0}{1}", WikiStrings.TemplateVariableStartRegexString, line); // Datumsangabe if(HasLeagueTemplateDate(line)) { line += match.Date.ToShortDateString(); } // Ortsangabe else if(HasLeagueTemplateLocation(line)) { line += match.TeamA.Stadium.City; } // Spielergebnis else { line += String.Format("{0}:{1}", match.ResultA, match.ResultB); } } // Wenn nicht benötigte Variable else if(templateMatch.Success) { line = (line.StartsWith(WikiStrings.TemplateVariableStartRegexString) ? line : String.Format("{0}{1}", WikiStrings.TemplateVariableStartRegexString, line)); } filledLines[i] = line; } filledLines[filledLines.Length - 1] = WikiStrings.TemplateEnd; return String.Join(Environment.NewLine, filledLines); }
/// <summary> /// Generiert den Code für die Darstellung der Ergebnisse der angegebenen <see cref="FootballLeague"/> und nutzt dazu die angegebene <see cref="LeagueWikiTemplate"/> asynchron /// </summary> /// <param name="league"><see cref="FootballLeague"/> der darzustellenden Ergebnisse</param> /// <param name="template"><see cref="LeagueWikiTemplate"/> der darzustellenden Ergebnisse</param> /// <returns>Generierten Ergebniscode</returns> public async static Task<string> GenerateResultsCodeAsync(FootballLeague league, LeagueWikiTemplate template) { return await Task.Run(() => GenerateResultsCode(league, template)); }
private void Create() { Settings.LeageWikiTemplates.Add(WikiHelper.ParseLeagueTemplate(WikiCodeTextBox.Text)); _IsInNewMode = false; SelectedTemplate = Settings.LeageWikiTemplates.Last(); Settings.LogObjCreated(SelectedTemplate); }
private void SaveData() { SelectedTemplate = WikiHelper.ParseLeagueTemplate(WikiCodeTextBox.Text, SelectedTemplate); Settings.LogObjSaved(SelectedTemplate); }