예제 #1
0
        public List <CountByType> GetByType()
        {
            var subscriptions = subscriptionRepository.GetSubscriptions();
            var count         = subscriptions.Count - 1;
            Dictionary <TypeSubscription, int> types = new Dictionary <TypeSubscription, int>();
            List <CountByType> statistics            = new List <CountByType>();

            foreach (var type in Enum.GetValues(typeof(TypeSubscription)))
            {
                foreach (var sub in subscriptions)
                {
                    if (types.ContainsKey((TypeSubscription)type))
                    {
                        if (sub.Type.Equals((TypeSubscription)type))
                        {
                            types[(TypeSubscription)type] += 1;
                        }
                    }
                    else
                    {
                        types.Add((TypeSubscription)type, 0);
                    }
                }
                CountByType element = new CountByType();
                element.Type    = (TypeSubscription)type;
                element.Count   = types[(TypeSubscription)type];
                element.Percent = Math.Round(types[(TypeSubscription)type] * 100.0 / count);
                statistics.Add(element);
            }

            return(statistics);
        }
        public HeapSnapshot(ClrHeap heap, int topTypes)
        {
            var query = from address in heap.EnumerateObjectAddresses()
                        let type = heap.GetObjectType(address)
                                   where type != null && !type.IsFree
                                   let size = type.GetSize(address)
                                              group size by type.Name into g
                                              let totalSize                         = g.Sum(v => (long)v)
                                                                          let count = g.Count()
                                                                                      orderby totalSize descending
                                                                                      select new { Type = g.Key, Size = totalSize, Count = count };

            foreach (var typeStats in query.Take(topTypes))
            {
                SizeByType.Add(typeStats.Type, typeStats.Size);
                CountByType.Add(typeStats.Type, typeStats.Count);
            }
        }
예제 #3
0
        public List <CountByType> GetByTypeWithDate(DateTime from, DateTime to)
        {
            var subscriptions = subscriptionRepository.GetSubscriptions();

            Dictionary <TypeSubscription, int> types = new Dictionary <TypeSubscription, int>();
            List <CountByType> statistics            = new List <CountByType>();

            foreach (var type in Enum.GetValues(typeof(TypeSubscription)))
            {
                foreach (var sub in subscriptions)
                {
                    if (types.ContainsKey((TypeSubscription)type))
                    {
                        if (sub.Type.Equals((TypeSubscription)type) && sub.Register_Date != null && from < sub.Register_Date && sub.Register_Date < to)
                        {
                            types[(TypeSubscription)type] += 1;
                        }
                    }
                    else
                    {
                        types.Add((TypeSubscription)type, 0);
                    }
                }
            }
            int count = types.Sum(t => t.Value);

            for (int i = 0; i < types.Count; i++)
            {
                CountByType element = new CountByType();
                element.Type    = types.ElementAt(i).Key;
                element.Count   = types.ElementAt(i).Value;
                element.Percent = Math.Round(types.ElementAt(i).Value * 100.0 / count);
                statistics.Add(element);
            }

            return(statistics);
        }