Dev2.Studio.Deploy.DeployStatsCalculator.CalculateStats C# (CSharp) Method

CalculateStats() public method

Calculates the stastics from navigation item view models
public CalculateStats ( IEnumerable items, bool>.Dictionary predicates, ObservableCollection stats, int &deployItemCount ) : void
items IEnumerable
predicates bool>.Dictionary
stats ObservableCollection
deployItemCount int
return void
        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;
                }
            }
        }