public void CreateMenu() { string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); string filename = Path.Combine(path, "Data.xml"); string content; //If local menu exists load it, otherwise create new menu if (File.Exists(filename)) { using (var streamReader = new StreamReader(filename)) { content = streamReader.ReadToEnd(); } menu = menuFactory.GetMenu(content); } else { menu = new MenuNode(); UpdateMenu(); } }
public BaseMenuItem UpdateMenu(MenuItemType? type = null, BaseMenuItem item = null) { foreach(var game in menu.Games) { foreach(var character in game.Characters) { character.Opponents = character.Opponents.OrderBy(x => x.Title).ToList(); } game.Characters = game.Characters.OrderBy(x => x.Title).ToList(); } menu.Games = menu.Games.OrderBy(x => x.Title).ToList(); XmlSerializer serializer = new XmlSerializer(typeof(MenuNode)); string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); string filename = Path.Combine(path, "Data.xml"); using (var streamWriter = new StreamWriter(filename)) { serializer.Serialize(streamWriter, menu); } string content; using (var streamReader = new StreamReader(filename)) { content = streamReader.ReadToEnd(); } menu = menuFactory.GetMenu(content); if(type.HasValue && item != null) { switch(type.Value) { case MenuItemType.PlayerCharacter: PlayerCharacterNode pCharacter = (PlayerCharacterNode)item; return menu.Games.Where(x => x.Title == pCharacter.Parent.Title).First(); case MenuItemType.Opponent: OpponentMatchupNode oMatchup = (OpponentMatchupNode)item; return menu.Games.Where(x => x.Title == oMatchup.Parent.Parent.Title).First() .Characters.Where(y => y.Title == oMatchup.Parent.Title).First(); } } return null; }