private void UpdateFavoritesList() { // TODO: This is O(n^2) _favorites.RemoveAll(p => !_cfg.FavoriteServers.Items.Contains(p.Favorite)); // TODO: This is also O(n^2) foreach (var favoriteServer in _cfg.FavoriteServers.Items) { if (_favorites.Any(f => f.Favorite == favoriteServer)) { continue; } var serverEntryViewModel = new ServerEntryViewModel(_statusCache, _cfg, _updater, _loginMgr, favoriteServer); serverEntryViewModel.DoInitialUpdate(); _favorites.Add(serverEntryViewModel); } _favorites.Sort((a, b) => string.Compare(a.Favorite !.Name, b.Favorite !.Name, StringComparison.CurrentCulture)); var alt = false; foreach (var favorite in _favorites) { favorite.IsAltBackground = alt; alt ^= true; } Favorites.Clear(); Favorites.AddRange(_favorites); FavoritesEmpty = Favorites.Count == 0; }
private async Task LoadFavoritesAsync() { var favs = await FileSystem.DeserializeObject <List <FavoriteNavigationLink> >(FAVORITE_FILE_NAME) ?? new List <FavoriteNavigationLink>(); foreach (var fav in favs) { fav.MoveDownCommand = FavNavLinkDownCmd; fav.MoveUpCommand = FavNavLinkUpCmd; fav.RemoveCommand = FavNavLinkRemoveCmd; } for (int i = 0; i < favs.Count; i++) { NavigationItems.Insert(i, favs[i]); } Favorites.AddRange(favs); }
/// <summary> /// Load from props and JSON /// </summary> public void Load() { _CheckInterval = Properties.Settings.Default.CheckInterval; foreach (var i in AlertNames) { string path = SettingsStoreDirectoryManager.FavoritesPath + System.IO.Path.DirectorySeparatorChar + i + ".json"; if (System.IO.File.Exists(path)) { using (System.IO.Stream s = System.IO.File.Open(path, System.IO.FileMode.Open)) { Favorite[] favs = Codeplex.Data.DynamicJson.Parse(s); Favorites.AddRange(favs); } } } }