Exemplo n.º 1
0
        private void UpdateStatistics()
        {
            StatsData = ApplicationModel.Database.Value.Statistics;
            Statistics.Clear();
            ViewOptions.Clear();
            ViewOptions.Add("All");
            ViewOptions.Add("Single Items");

            if (StatsData.Value == null)
            {
                Thread.Sleep(100);
                UpdateStatistics();
                return;
            }

            foreach (var propertyInfo in StatsData.Value.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var enumerable = propertyInfo.GetValue(StatsData.Value, null) as IEnumerable <object>;

                if (enumerable != null)
                {
                    var list = enumerable as List <object> ?? enumerable.ToList();
                    if (list.Count == 0)
                    {
                        continue;
                    }

                    if ((list.First() is string == false) && (list.First() is IndexStats == false))
                    {
                        continue;
                    }

                    var statInfo = new StatInfo
                    {
                        IsList    = true,
                        ListItems = new List <StatInfoItem>(),
                    };

                    foreach (var item in list)
                    {
                        var statInfoItem = new StatInfoItem(item);

                        if (statInfoItem.ItemType == typeof(IndexStats))
                        {
                            AddIndexStat(statInfoItem);
                        }

                        statInfo.ListItems.Add(statInfoItem);
                    }

                    Statistics.Add(propertyInfo.Name, statInfo);
                    ViewOptions.Add(propertyInfo.Name);
                }
                else
                {
                    if (string.IsNullOrEmpty(propertyInfo.GetValue(StatsData.Value, null).ToString()) || propertyInfo.GetValue(StatsData.Value, null).ToString() == "0")
                    {
                        continue;
                    }

                    Statistics.Add(propertyInfo.Name, new StatInfo
                    {
                        Message = GetValueWithFormat(propertyInfo.GetValue(StatsData.Value, null))
                    });
                }
            }

            OnPropertyChanged(() => StatsData);
            UpdateView();
        }
        private void UpdateStatistics()
        {
            StatsData = ApplicationModel.Database.Value.Statistics;
            Statistics.Clear();
            ViewOptions.Clear();
            ViewOptions.Add("All");
            ViewOptions.Add("Single Items");

            if (StatsData.Value == null)
            {
                if (retries-- == 0)
                {
                    ApplicationModel.Current.Notifications.Add(new Notification("Could not load settings for database " + ApplicationModel.Database.Value.Name));
                    return;
                }
                Thread.Sleep(100);
                UpdateStatistics();
                return;
            }

            retries = 3;

            foreach (var propertyInfo in StatsData.Value.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var enumerable = propertyInfo.GetValue(StatsData.Value, null) as IEnumerable <object>;

                if (enumerable != null)
                {
                    var list = enumerable as List <object> ?? enumerable.ToList();
                    if (propertyInfo.Name == "StaleIndexes")
                    {
                        StaleIndexes = new List <object>(list);
                        if (list.Count == 0)
                        {
                            Statistics.Add(propertyInfo.Name, new StatInfo
                            {
                                Message     = "No Stale Indexes",
                                ToolTipData = "No Stale Indexes"
                            });
                        }
                        else if (list.Count > 1)
                        {
                            ViewOptions.Add("Stale Indexes");
                            Statistics.Add(propertyInfo.Name, new StatInfo
                            {
                                Message     = string.Format("There are {0} Stale Indexes: {1}", list.Count, string.Join(",", list)),
                                ToolTipData = string.Join(", ", list)
                            });
                        }
                        else                         // only one item
                        {
                            ViewOptions.Add("Stale Indexes");
                            Statistics.Add(propertyInfo.Name, new StatInfo
                            {
                                Message     = "There is 1 Stale Index: " + list[0],
                                ToolTipData = list[0].ToString()                                 // only one item, no need to call string.Join()
                            });
                        }

                        continue;
                    }

                    if (list.Count == 0)
                    {
                        continue;
                    }

                    if ((list.First() is string == false) && (list.First() is Abstractions.Data.IndexStats == false))
                    {
                        continue;
                    }

                    var statInfo = new StatInfo
                    {
                        IsList    = true,
                        ListItems = new List <StatInfoItem>(),
                    };

                    foreach (var item in list)
                    {
                        var statInfoItem = new StatInfoItem(item);

                        if (statInfoItem.ItemType == typeof(Abstractions.Data.IndexStats))
                        {
                            AddIndexStat(statInfoItem);
                        }

                        statInfo.ListItems.Add(statInfoItem);
                    }

                    Statistics.Add(propertyInfo.Name, statInfo);
                    ViewOptions.Add(propertyInfo.Name);
                }
                else
                {
                    if (string.IsNullOrEmpty(propertyInfo.GetValue(StatsData.Value, null).ToString()) || propertyInfo.GetValue(StatsData.Value, null).ToString() == "0")
                    {
                        continue;
                    }

                    Statistics.Add(propertyInfo.Name, new StatInfo
                    {
                        Message     = GetValueWithFormat(propertyInfo.GetValue(StatsData.Value, null)),
                        ToolTipData = GetValueWithFormat(propertyInfo.GetValue(StatsData.Value, null))
                    });
                }
            }

            OnPropertyChanged(() => StatsData);
            UpdateView();
        }