using Profiler.Data; using Profiler.InfrastructureMvvm; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Profiler.ViewModels { class MemoryStatsViewModel : BaseViewModel { public class StatsItem : BaseViewModel { public DataResponse.Type ResponseType { get; set; } public UInt64 TotalMemory { get; set; } public UInt64 TotalCount { get; set; } public void Add(UInt64 size) { TotalMemory = TotalMemory + size; TotalCount = TotalCount + 1; } } Dictionary StatsDictionary { get; set; } = new Dictionary(); private List _stats = null; public List Stats { get { return _stats; } set { SetProperty(ref _stats, value); OnPropertyChanged("TotalMemory"); } } public UInt64 TotalMemory { get { UInt64 total = 0; Stats.ForEach(s => total += s.TotalMemory); return total; } } public void Load(DataResponse response) { StatsItem item = null; if (!StatsDictionary.TryGetValue(response.ResponseType, out item)) { item = new StatsItem() { ResponseType = response.ResponseType }; StatsDictionary.Add(response.ResponseType, item); } item.Add((UInt64)response.Reader.BaseStream.Length); } public void Update() { List items = new List(StatsDictionary.Values); items.Sort((a, b) => -a.TotalMemory.CompareTo(b.TotalMemory)); Stats = items; } } }