private void btnMetrics_Click(object sender, EventArgs e) { try { Cursor.Current = Cursors.WaitCursor; if (dataPointBindingList.Count == 0) { return; } foreach (var item in dataPointBindingList) { item.Entity = topicDescription.Path; item.Type = MetricsTopicEntity; } var uris = MetricHelper.BuildUriListForDataPointMetricQueries(MainForm.SingletonMainForm.SubscriptionId, serviceBusHelper.Namespace, dataPointBindingList); 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) { continue; } var key = string.Format(MetricTabPageKeyFormat, tabIndex++); var metricInfo = MetricInfo.MetricInfos.FirstOrDefault(m => m.Name == dataPointBindingList[i].Metric); var friendlyName = metricInfo != null ? metricInfo.FriendlyName : dataPointBindingList[i].Metric; var unit = metricInfo != null ? metricInfo.Unit : Unknown; mainTabControl.TabPages.Add(key, friendlyName); 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], dataPointBindingList[i], metricInfo) { Location = new Point(0, 0), Dock = DockStyle.Fill, Tag = string.Format(GrouperFormat, friendlyName, unit) }; mainTabControl.TabPages[key].Controls.Add(control); } } catch (Exception ex) { HandleException(ex); } finally { Cursor.Current = Cursors.Default; } }
private void btnMetrics_Click(object sender, EventArgs e) { try { if (!MetricInfo.EntityMetricDictionary.ContainsKey(SubscriptionEntity)) { 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(SubscriptionPathFormat, subscriptionWrapper.SubscriptionDescription.TopicPath, subscriptionWrapper.SubscriptionDescription.Name); item.Type = SubscriptionEntity; } 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[SubscriptionEntity]) { 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[SubscriptionEntity].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; } }
// 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; } }
private void btnGet_Click(object sender, EventArgs e) { try { Cursor.Current = Cursors.WaitCursor; if (dataPointBindingList.Count == 0) { return; } if (existingEntity) { foreach (var item in dataPointBindingList) { item.Entity = entityName; item.Type = entityType; } } var uris = MetricHelper.BuildUriListForDataPointMetricQueries(MainForm.SingletonMainForm.SubscriptionId, serviceBusHelper.Namespace, dataPointBindingList); 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; } // Common Graph var graphDataPoints = dataPointBindingList.Where(d => d.Graph); if (graphDataPoints.Any()) { if (mainTabControl.TabPages.ContainsKey(GraphTabPage)) { mainTabControl.TabPages.RemoveByKey(GraphTabPage); } mainTabControl.TabPages.Add(GraphTabPage, "Main Graph"); var tabPage = mainTabControl.TabPages[GraphTabPage]; tabPage.BackColor = Color.FromArgb(215, 228, 242); tabPage.ForeColor = SystemColors.ControlText; var metricGraphControl = new MetricGraphControl(writeToLog, () => mainTabControl.TabPages.RemoveByKey(GraphTabPage), metricList, dataPointBindingList.ToList()) { Location = new Point(0, 0), Dock = DockStyle.Fill }; mainTabControl.TabPages[GraphTabPage].Controls.Add(metricGraphControl); } // Individual Metrics for (var i = 0; i < metricList.Count; i++) { if (metricList[i] == null) { continue; } var metricInfo = MetricInfo.MetricInfos.FirstOrDefault(m => m.Name == dataPointBindingList[i].Metric); var friendlyName = metricInfo != null ? metricInfo.FriendlyName : dataPointBindingList[i].Metric; var unit = metricInfo != null ? metricInfo.Unit : Unknown; var entity = dataPointBindingList[i].Type == SubscriptionEntity ? new Uri(string.Format("http://x/{0}", dataPointBindingList[i].Entity)).Segments[3] : dataPointBindingList[i].Entity; var key = !existingEntity ? string.Format(@"{0}\{1}", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(entity), friendlyName) : friendlyName; if (mainTabControl.TabPages.ContainsKey(key)) { mainTabControl.TabPages.RemoveByKey(key); } mainTabControl.TabPages.Add(key, key); var tabPage = mainTabControl.TabPages[key]; tabPage.BackColor = Color.FromArgb(215, 228, 242); tabPage.ForeColor = SystemColors.ControlText; var metricValueControl = new MetricValueControl(writeToLog, () => mainTabControl.TabPages.RemoveByKey(key), metricList[i], dataPointBindingList[i], metricInfo) { Location = new Point(0, 0), Dock = DockStyle.Fill, Tag = !existingEntity ? string.Format(GrouperFormat1, entity, friendlyName, unit) : string.Format(GrouperFormat2, friendlyName, unit) }; mainTabControl.TabPages[key].Controls.Add(metricValueControl); } if (mainTabControl.TabPages.ContainsKey(GraphTabPage)) { mainTabControl.SelectTab(GraphTabPage); return; } if (metricList.Count > 0) { mainTabControl.SelectTab(1); } } catch (Exception ex) { HandleException(ex); } finally { Cursor.Current = Cursors.Default; } }
private void btnGet_Click(object sender, EventArgs e) { try { Cursor.Current = Cursors.WaitCursor; if (dataPointBindingList.Count == 0) { return; } if (existingEntity) { foreach (var item in dataPointBindingList) { item.Entity = entityName; item.Type = entityType; } } var allDataPoints = dataPointBindingList.Where(m => string.Compare(m.Metric, "all", StringComparison.OrdinalIgnoreCase) == 0); var allDataPointList = allDataPoints as IList<MetricDataPoint> ?? allDataPoints.ToList(); BindingList<MetricDataPoint> pointBindingList; if (allDataPointList.Any()) { pointBindingList = new BindingList<MetricDataPoint>(); foreach (var allDataPoint in allDataPointList) { if (allDataPoint == null || string.IsNullOrWhiteSpace(allDataPoint.Type) || !MetricInfo.EntityMetricDictionary.ContainsKey(allDataPoint.Type)) { continue; } foreach (var item in MetricInfo.EntityMetricDictionary[allDataPoint.Type]) { 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; } // Common Graph var graphDataPoints = pointBindingList.Where(d => d.Graph); if (graphDataPoints.Any()) { if (mainTabControl.TabPages.ContainsKey(GraphTabPage)) { mainTabControl.TabPages.RemoveByKey(GraphTabPage); } mainTabControl.TabPages.Add(GraphTabPage, "Main Graph"); var tabPage = mainTabControl.TabPages[GraphTabPage]; tabPage.BackColor = Color.FromArgb(215, 228, 242); tabPage.ForeColor = SystemColors.ControlText; var metricGraphControl = new MetricGraphControl(writeToLog, () => mainTabControl.TabPages.RemoveByKey(GraphTabPage), metricList, pointBindingList.ToList()) { Location = new Point(0, 0), Dock = DockStyle.Fill }; mainTabControl.TabPages[GraphTabPage].Controls.Add(metricGraphControl); } // Individual Metrics for (var i = 0; i < metricList.Count; i++) { if (metricList[i] == null || !metricList[i].Any() || pointBindingList[i] == null || string.IsNullOrWhiteSpace(pointBindingList[i].Type) || !MetricInfo.EntityMetricDictionary.ContainsKey(pointBindingList[i].Type)) { continue; } var metricInfo = MetricInfo.EntityMetricDictionary[pointBindingList[i].Type].FirstOrDefault(m => m.Name == pointBindingList[i].Metric); if (metricInfo == null) { continue; } var friendlyName = metricInfo.DisplayName; var unit = metricInfo.Unit; var entity = pointBindingList[i].Type == SubscriptionEntity ? new Uri(string.Format("http://x/{0}", pointBindingList[i].Entity)).Segments[3] : pointBindingList[i].Entity; var key = !existingEntity ? string.Format(@"{0}\{1}", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(entity), friendlyName) : friendlyName; if (mainTabControl.TabPages.ContainsKey(key)) { mainTabControl.TabPages.RemoveByKey(key); } mainTabControl.TabPages.Add(key, key); var tabPage = mainTabControl.TabPages[key]; tabPage.BackColor = Color.FromArgb(215, 228, 242); tabPage.ForeColor = SystemColors.ControlText; var metricValueControl = new MetricValueControl(writeToLog, () => mainTabControl.TabPages.RemoveByKey(key), metricList[i], pointBindingList[i], metricInfo) { Location = new Point(0, 0), Dock = DockStyle.Fill, Tag = !existingEntity ? string.Format(GrouperFormat1, entity, friendlyName, unit) : string.Format(GrouperFormat2, friendlyName, unit) }; mainTabControl.TabPages[key].Controls.Add(metricValueControl); } if (mainTabControl.TabPages.ContainsKey(GraphTabPage)) { mainTabControl.SelectTab(GraphTabPage); return; } if (metricList.Count > 0) { mainTabControl.SelectTab(1); } } catch (Exception ex) { HandleException(ex); } finally { Cursor.Current = Cursors.Default; } }