Пример #1
0
 // ReSharper disable once FunctionComplexityOverflow
 private void btnMetrics_Click(object sender, EventArgs e)
 {
     try
     {
         if (!MetricInfo.EntityMetricDictionary.ContainsKey(ConsumerGroupEntity))
         {
             return;
         }
         if (metricTabPageIndexList.Count > 0)
         {
             for (var i = 0; i < metricTabPageIndexList.Count; i++)
             {
                 mainTabControl.TabPages.RemoveByKey(metricTabPageIndexList[i]);
             }
             metricTabPageIndexList.Clear();
         }
         Cursor.Current = Cursors.WaitCursor;
         if (dataPointBindingList.Count == 0)
         {
             return;
         }
         foreach (var item in dataPointBindingList)
         {
             item.Entity = string.Format(ConsumerGroupPathFormat, consumerGroupDescription.EventHubPath, consumerGroupDescription.Name);
             item.Type   = ConsumerGroupEntity;
         }
         BindingList <MetricDataPoint> pointBindingList;
         var allDataPoint = dataPointBindingList.FirstOrDefault(m => string.Compare(m.Metric, "all", StringComparison.OrdinalIgnoreCase) == 0);
         if (allDataPoint != null)
         {
             pointBindingList = new BindingList <MetricDataPoint>();
             foreach (var item in MetricInfo.EntityMetricDictionary[ConsumerGroupEntity])
             {
                 if (string.Compare(item.Name, "all", StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     continue;
                 }
                 pointBindingList.Add(new MetricDataPoint
                 {
                     Entity          = allDataPoint.Entity,
                     FilterOperator1 = allDataPoint.FilterOperator1,
                     FilterOperator2 = allDataPoint.FilterOperator2,
                     FilterValue1    = allDataPoint.FilterValue1,
                     FilterValue2    = allDataPoint.FilterValue2,
                     Granularity     = allDataPoint.Granularity,
                     Graph           = allDataPoint.Graph,
                     Metric          = item.Name,
                     Type            = allDataPoint.Type
                 });
             }
         }
         else
         {
             pointBindingList = dataPointBindingList;
         }
         var uris = MetricHelper.BuildUriListForDataPointMetricQueries(MainForm.SingletonMainForm.SubscriptionId,
                                                                       serviceBusHelper.Namespace,
                                                                       pointBindingList);
         var uriList = uris as IList <Uri> ?? uris.ToList();
         if (uris == null || !uriList.Any())
         {
             return;
         }
         var metricData = MetricHelper.ReadMetricDataUsingTasks(uriList,
                                                                MainForm.SingletonMainForm.CertificateThumbprint);
         var metricList = metricData as IList <IEnumerable <MetricValue> > ?? metricData.ToList();
         if (metricData == null && metricList.Count == 0)
         {
             return;
         }
         for (var i = 0; i < metricList.Count; i++)
         {
             if (metricList[i] == null || !metricList[i].Any())
             {
                 continue;
             }
             var key          = string.Format(MetricTabPageKeyFormat, i);
             var metricInfo   = MetricInfo.EntityMetricDictionary[ConsumerGroupEntity].FirstOrDefault(m => m.Name == pointBindingList[i].Metric);
             var friendlyName = metricInfo != null ? metricInfo.DisplayName : pointBindingList[i].Metric;
             var unit         = metricInfo != null ? metricInfo.Unit : Unknown;
             mainTabControl.TabPages.Add(key, friendlyName);
             metricTabPageIndexList.Add(key);
             var tabPage = mainTabControl.TabPages[key];
             tabPage.BackColor = Color.FromArgb(215, 228, 242);
             tabPage.ForeColor = SystemColors.ControlText;
             var control = new MetricValueControl(writeToLog,
                                                  () => mainTabControl.TabPages.RemoveByKey(key),
                                                  metricList[i],
                                                  pointBindingList[i],
                                                  metricInfo)
             {
                 Location = new Point(0, 0),
                 Dock     = DockStyle.Fill,
                 Tag      = string.Format(GrouperFormat, friendlyName, unit)
             };
             mainTabControl.TabPages[key].Controls.Add(control);
             btnCloseTabs.Enabled = true;
         }
     }
     catch (Exception ex)
     {
         HandleException(ex);
     }
     finally
     {
         Cursor.Current = Cursors.Default;
     }
 }
Пример #2
0
        public async static Task GetMetricInfoListAsync(string ns, string entityType, string entityPath)
        {
            try
            {
                if (!retrieveMetrics)
                {
                    return;
                }
                if (string.IsNullOrWhiteSpace(ns) ||
                    string.IsNullOrEmpty(entityType) ||
                    string.IsNullOrWhiteSpace(entityPath) ||
                    !entityToUrlSegmentMapDictionary.ContainsKey(entityType) ||
                    EntityMetricDictionary.ContainsKey(entityType))
                {
                    return;
                }
                if (string.IsNullOrWhiteSpace(MainForm.SingletonMainForm.SubscriptionId) ||
                    string.IsNullOrWhiteSpace(MainForm.SingletonMainForm.CertificateThumbprint))
                {
                    if (!warningShown)
                    {
                        Trace.WriteLine(NoSubscriptionIdOrCertificateThumbprint);
                        warningShown = true;
                    }
                    return;
                }
                Trace.WriteLine(string.Format(RetrievingMetricsFormat, entityType));
                var uri = MetricHelper.BuildUriForDataPointDiscoveryQuery(MainForm.SingletonMainForm.SubscriptionId,
                                                                          ns,
                                                                          entityToUrlSegmentMapDictionary[entityType],
                                                                          entityPath);
                var enumerable = await MetricHelper.GetSupportedMetricsAsync(uri, MainForm.SingletonMainForm.CertificateThumbprint);

                if (enumerable == null)
                {
                    retrieveMetrics = false;
                    Trace.WriteLine(string.Format(NoMetricRetrievedFormat, entityType));
                    return;
                }
                var metricInfoList = enumerable.ToList();
                var count          = metricInfoList.Count;
                metricInfoList.Insert(0, new MetricInfo {
                    DisplayName = "All", Name = "all", Unit = "Requests", PrimaryAggregation = "Total"
                });
                foreach (var item in metricInfoList)
                {
                    item.DisplayName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(item.DisplayName.Replace('.', ' '));
                }
                if (!metricInfoList.Any())
                {
                    return;
                }
                EntityMetricDictionary[entityType] = new BindingList <MetricInfo>(metricInfoList.ToList())
                {
                    AllowEdit   = true,
                    AllowNew    = true,
                    AllowRemove = true
                };
                Trace.WriteLine(string.Format(MetricSuccessfullyRetrievedFormat, count, entityType));
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }