public int Compare(object x, object y) { DeployStatsTO a = x as DeployStatsTO; DeployStatsTO b = y as DeployStatsTO; if (a == null || b == null) { return(1); } if (a.Name == b.Name && a.Description == b.Description) { return(0); } return(1); }
/// <summary> /// Calculates the stastics from navigation item view models /// </summary> public void CalculateStats(IEnumerable <IExplorerItemModel> items, Dictionary <string, Func <IExplorerItemModel, bool> > predicates, ObservableCollection <DeployStatsTO> stats, out int deployItemCount) { deployItemCount = 0; var predicateCounts = new Dictionary <string, int>(); foreach (var predicate in predicates) { var deployStatsTo = stats.FirstOrDefault(s => s.Name == predicate.Key); if (deployStatsTo == null) { deployStatsTo = new DeployStatsTO(predicate.Key, ""); stats.Add(deployStatsTo); } predicateCounts.Add(predicate.Key, 0); } foreach (var treeNode in items) { var item = treeNode; foreach (var predicate in predicates) { if (!predicate.Value(item)) { continue; } predicateCounts[predicate.Key]++; break; } } foreach (var predicateCount in predicateCounts) { var deployStatsTo = stats.FirstOrDefault(s => s.Name == predicateCount.Key); if (deployStatsTo != null) { deployStatsTo.Description = predicateCount.Value.ToString(CultureInfo.InvariantCulture); deployItemCount += predicateCount.Value; } } }