Exemplo n.º 1
0
        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) { UseWADPerformanceOptimization = Configuration.Instance.UseWADPerformanceOptimization }.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. If you were expecting results, you could try disabling 'Use optimized queries for WAD tables'."
                    };
                    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 ("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.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 = (from propname in propertyNames select propname).ToArray();
                    _loadedRows = (from entity in entities
                                   select (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();
                }
            });
        }
Exemplo n.º 2
0
        private void HandleAccountSelected(object sender, EventArgs e)
        {
            string accountname = GetSelectedAccountName();
            string accountkey = GetSelectedAccountKey();
            if (accountkey == null)
                return;
            IEnumerable<string> tableNames = null;

            PerformBG(this, () =>
            {
                tableNames = new LogFetcher(accountname, accountkey) { UseWADPerformanceOptimization = Configuration.Instance.UseWADPerformanceOptimization }.FetchTables();
            },
            () =>
            {
                string previousTable = GetSelectedTableName();
                tableSelection.Items.Clear();
                tableSelection.Items.Add("-- select table --");
                foreach (var tablename in tableNames)
                    tableSelection.Items.Add(tablename);
                if (tableNames.Contains(previousTable))
                    tableSelection.SelectedItem = previousTable;
                else
                    tableSelection.SelectedIndex = 0;
                UpdateAccountSelection();
            }, (ex) =>
            {
                if (MessageBox.Show(this, "Failed to retrieve tables for this storage account. Do you want to remove this account?", "Error", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    if (Configuration.Instance.Accounts.ContainsKey(GetSelectedAccountName()))
                        Configuration.Instance.Accounts.Remove(GetSelectedAccountName());
                }
                UpdateAccountSelection();
            });
        }