private static IEnumerable <ITranslator> CreateTranslators() { //yield return new DecoratingTranslator(new NullTranslator(), "%%"); string transDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Locales"); foreach (string file in Directory.GetFiles(transDir, "*.xml")) { ITranslator t = null; try { // TODO: english should be fallback!! t = new FallbackTranslator(new XmlTranslator(File.OpenRead(file)), new NullTranslator()); } catch (Exception ex) { HtLog.Warn(string.Format("Cannot parse file {0} ({1})", file, ex.ToString())); } if (t != null) { yield return(t); } } }
public IDictionary <Player, IList <MatchAppearance> > GetMatchesOfPlayers(int teamId, bool addTeamItem = false) { IDictionary <Player, IList <MatchAppearance> > ret2 = new Dictionary <Player, IList <MatchAppearance> >(); foreach (MatchDetails md in Matches.SafeEnum()) { Team myTeam; if (md.HomeTeam.ID == teamId) { myTeam = md.HomeTeam; } else if (md.AwayTeam.ID == teamId) { myTeam = md.AwayTeam; } else { HtLog.Warn("Received a bad match ({0})", md); continue; } IDictionary <Player, MatchAppearance> thisMatchAppearances = new Dictionary <Player, MatchAppearance>(); if (addTeamItem) { AddTeamDummyPlayer(myTeam, thisMatchAppearances, md); AddTeamDummyGoals(myTeam, thisMatchAppearances, md); } AddLineupPlayers(myTeam, thisMatchAppearances, md); AddDisappearedPlayers(myTeam, thisMatchAppearances, md); AddGoals(myTeam, thisMatchAppearances, md); AddReplacements(myTeam, thisMatchAppearances, md); AddBestPlayer(myTeam, thisMatchAppearances, md); AddYellowCards(myTeam, thisMatchAppearances, md); AddBruisedAndInjured(myTeam, thisMatchAppearances, md); // add items to return value foreach (var v in thisMatchAppearances) { if (!ret2.ContainsKey(v.Key)) { ret2.Add(v.Key, new List <MatchAppearance>()); } ret2[v.Key].Add(v.Value); } } return(ret2); }
private static void AddGoals(Team myTeam, IDictionary <Player, MatchAppearance> thisMatchAppearances, MatchDetails md) { foreach (Goal g in md.Goals) { if (myTeam.ID != g.Team.ID) { continue; // ignore opponent goals } if (g.Scorer.ID == 0) { continue; // ignore neighbourhood players } if (!thisMatchAppearances.ContainsKey(g.Scorer)) { HtLog.Warn("Scorer is not part of lineup. This is very odd."); continue; } thisMatchAppearances[g.Scorer].Goals.Add(g); } }
private static void AddLineupPlayers(Team myTeam, IDictionary <Player, MatchAppearance> ret, MatchDetails md) { IEnumerable <Lineup.LineupItem> items = null; if (md.HomeTeam.ID == myTeam.ID) { myTeam = md.HomeTeam; items = md.HomeLineup.LineupItems; } else if (md.AwayTeam.ID == myTeam.ID) { items = md.AwayLineup.LineupItems; } else { HtLog.Warn("Received a bad match ({0})", md); return; } foreach (Lineup.LineupItem item in items.SafeEnum()) { if (!item.Role.IsActive()) { continue; } if (item.Player.ID == 0) { continue; // ignore neighbourhood players } if (!ret.ContainsKey(item.Player)) { ret.Add(item.Player, new MatchAppearance(item.Player, myTeam, md, item.Role, item.RatingStars)); } else { throw new Exception(string.Format("Tried to add Player {0} twice", item.Player)); } } }
private void Form1_Load(object sender, EventArgs e) { try { //if (File.Exists(SettingsFile)) { SaveDo(() => { _settings.Load(SettingsFile); }); } SetTranslator(); this.Translate(_translator); //menuStrip.Translate(_translator); languageToolStripMenuItem.DropDownItems.Clear(); foreach (ITranslator translator in Translation.TranslatorFactory.Translators.SafeEnum()) { ToolStripMenuItem item = new ToolStripMenuItem(translator.ToString(), null, OnLanguageChanged); item.Tag = translator; item.Name = "noTr_" + Guid.NewGuid().ToString(); languageToolStripMenuItem.DropDownItems.Add(item); } SetOnlineMode(); SetColumns(_settings.ActiveColumnSet); RefreshColumnSetComboBox(); ThreadPool.QueueUserWorkItem(this.DoUpdateStartCallback); try { string team; _settings.TryGetValue("team", out team); if (!string.IsNullOrEmpty(team)) { _teamId = int.Parse(team); } } catch { HtLog.Error("Cannot parse team id"); } ChangeTeam(ref _teamId); matchFilterControl.FilterChanged += UpdateAll; string lastVersion; if (!_settings.TryGetValue("lastVersion", out lastVersion) || lastVersion != GetVersionString()) { ShowWhatsNewBox(); _settings["lastVersion"] = GetVersionString(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }