private void HandleFetchButton(object sender, EventArgs e) { string accountName = GetSelectedAccountName(); string accountKey = GetSelectedAccountKey(); if (accountName == null) { MessageBox.Show(this, "Please select an account to fetch first..."); return; } string table = GetSelectedTableName(); if (table == null) { MessageBox.Show(this, "Please select a table to fetch first..."); return; } DateTime from = fromDate.Value; DateTime to = toDate.Value; OrderBy order = (OrderBy)Enum.Parse(typeof(OrderBy), orderByCombo.SelectedItem + ""); IList<WadTableEntity> entities = null; PerformBG(this, () => { // Find results for this period in time entities = new LogFetcher(accountName, accountKey).FetchLogs(table, from, to); switch (order) { case OrderBy.New_to_Old: entities = entities.OrderByDescending(i => i.EventTickCount).ThenByDescending(i => i.Timestamp).ToList(); break; case OrderBy.Old_to_New: entities = entities.OrderBy(i => i.EventTickCount).ThenBy(i => i.Timestamp).ToList(); break; } // If there are no entities at all, add a dummy "no results" entity if (entities == null || entities.Count == 0) { entities = new List<WadTableEntity>(); var entity = new WadTableEntity { PartitionKey = "No results found. Try extending the from/to period." }; entity.Properties.Add("PartitionKey", entity.PartitionKey); entities.Add(entity); } // Determine the available property names by checking each entity string[] propertyNames = entities.SelectMany(entity => entity.Properties).Select(p => p.Key).Distinct().ToArray(); // If certain propertynames are available, we assume this is a Windows Azure Diagnostics table and we leave out some info if (propertyNames.Contains("EventTickCount") && propertyNames.Contains("RoleInstance") && propertyNames.Contains("Level") && propertyNames.Contains("Message")) { _loadedColumns = new string[] { "RoleInstance", "Timestamp", "Message" }; _loadedRows = (from i in entities select new[] { i.RoleInstance, i.Timestamp.ToString(), i.Message }).ToArray(); _filteredRows = _loadedRows; return; } else { _loadedColumns = (from propname in propertyNames select propname).ToArray(); _loadedRows = (from entity in entities select (from prop in entity.Properties select prop.Value).ToArray()).ToArray(); _filteredRows = _loadedRows; } }, () => { dataGridView1.ReadOnly = true; if (!dataGridView1.VirtualMode) { dataGridView1.VirtualMode = true; dataGridView1.CellValueNeeded += HandleCellValueNeeded; } dataGridView1.AllowUserToAddRows = false; dataGridView1.AllowUserToDeleteRows = false; dataGridView1.AllowUserToResizeColumns = true; // Resizen mag wel dataGridView1.AllowUserToResizeRows = false; dataGridView1.AllowUserToOrderColumns = false; dataGridView1.Columns.Clear(); dataGridView1.Rows.Clear(); foreach (var column in _loadedColumns) { dataGridView1.Columns.Add(column, column); } // Vind van elke kolom de langste waarde string[] dummyvals = Enumerable.Repeat("", _loadedColumns.Length).ToArray(); for (int i = 0; i < _loadedColumns.Length; i++) { string longest = (from item in _loadedRows select item[i]).Aggregate("", (max, cur) => max.Length > cur.Length ? max : cur); //longest = new string('#', longest.Length); dummyvals[i] = longest; } // Voeg een dummy record toe dataGridView1.VirtualMode = false; dataGridView1.Rows.Add(dummyvals); // Autosize alle kolommen dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; // Breedtes van kolommen vastzetten foreach (DataGridViewColumn column in dataGridView1.Columns) { int width = column.Width + 15; // Compensate character width a little, so we don't get "..." on the slightest difference column.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; column.Width = width; } // Haal de autosize weer weg dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; // Rowcount goed zetten dataGridView1.Rows.Clear(); dataGridView1.VirtualMode = true; dataGridView1.RowCount = _loadedRows.Length; // Als er een filter is, pas het filter toe... if (GetFilterText() != null) HandleFilterKeyup(this, EventArgs.Empty); }); }
private void HandleFetchButton(object sender, EventArgs e) { string accountName = GetSelectedAccountName(); string accountKey = GetSelectedAccountKey(); if (accountName == null) { MessageBox.Show(this, "Please select an account to fetch first..."); return; } string table = GetSelectedTableName(); if (table == null) { MessageBox.Show(this, "Please select a table to fetch first..."); return; } DateTime from = fromDate.Value; DateTime to = toDate.Value; OrderBy order = (OrderBy)Enum.Parse(typeof(OrderBy), orderByCombo.SelectedItem + ""); IList <WadTableEntity> entities = null; statusStrip1.Visible = true; PerformBG(this, () => { // Find results for this period in time _currentFetcher = new LogFetcher(accountName, accountKey) { UseWADPerformanceOptimization = Configuration.Instance.UseWADPerformanceOptimization, UseKarellPartitionKey = Configuration.Instance.UseKarellPartitionKey, UseKarellRowKey = Configuration.Instance.UseKarellRowKey }; _currentFetcher.RetrievedPage += HandleRetrievedPage; entities = _currentFetcher.FetchLogs(table, from, to); switch (order) { case OrderBy.New_to_Old: entities = entities.OrderByDescending(i => i.EventTickCount).ThenByDescending(i => i.Timestamp).ToList(); break; case OrderBy.Old_to_New: entities = entities.OrderBy(i => i.EventTickCount).ThenBy(i => i.Timestamp).ToList(); break; } var index = 0; foreach (var item in entities) { item.LineNumber = index++; } // If there are no entities at all, add a dummy "no results" entity if (entities == null || entities.Count == 0) { entities = new List <WadTableEntity>(); var entity = new WadTableEntity { PartitionKey = "No results found. Try extending the from/to period. If you were expecting results, you could try disabling 'Use optimized queries for WAD tables'.", RowKey = "" }; entities.Add(entity); } // Determine the available property names by checking each entity string[] propertyNames = entities.SelectMany(entity => entity.Properties).Select(p => p.Key).Distinct().ToArray(); // If certain propertynames are available, we assume this is a Windows Azure Diagnostics table and we leave out some info if ("WADLogsTable".Equals(table) && propertyNames.Contains("DeploymentId") && propertyNames.Contains("RoleInstance") && propertyNames.Contains("EventTickCount") && propertyNames.Contains("Message")) { _loadedColumns = new string[] { "", "DeploymentId", "RoleInstance", "EventTickCount", "Message" }; _loadedRows = (from i in entities select new[] { i.LineNumber.ToString(), i.DeploymentId, i.RoleInstance, new DateTime(i.EventTickCount).ToString("yyyy-MM-dd HH:mm:ss.fff"), i.Message }).ToArray(); _filteredRows = _loadedRows; } else if ("WADPerformanceCountersTable".Equals(table) && propertyNames.Contains("Timestamp") && propertyNames.Contains("EventTickCount") && propertyNames.Contains("DeploymentId") && propertyNames.Contains("RoleInstance") && propertyNames.Contains("CounterName") && propertyNames.Contains("CounterValue")) { _loadedColumns = new string[] { "Timestamp", "EventTickCount", "DeploymentId", "RoleInstance", "CounterName", "CounterValue" }; _loadedRows = (from i in entities select new[] { i.Timestamp.ToString(), new DateTime(i.EventTickCount).ToString("yyyy-MM-dd HH:mm:ss.fff"), i.DeploymentId, i.Properties["RoleInstance"], i.Properties["CounterName"], i.Properties["CounterValue"] }).ToArray(); _filteredRows = _loadedRows; } else { _loadedColumns = new[] { "PartitionKey", "RowKey", "Timestamp" }.Concat(from propname in propertyNames select propname).ToArray(); _loadedRows = (from entity in entities select(new[] { entity.PartitionKey, entity.RowKey, entity.Timestamp.ToString("yyyy-MM-dd HH:mm:ss.fff") }.Concat(from prop in entity.Properties select GetPropertyValue(prop))).ToArray()).ToArray(); _filteredRows = _loadedRows; } }, () => { if ("WADPerformanceCountersTable".Equals(table) && _loadedRows.Length > 1 /* the dummy if empty */ && Configuration.Instance.ShowPerformanceCountersAsChart) { ShowPerformanceCountersChart(); } else { ShowDataGridView(); } statusStrip1.Visible = false; }); }