private void SetTraceFlags()
        {
            string sql = @"dbcc tracestatus();";

            using (Dal dal = new Dal(_connection))
            {
                using (DataTable table = dal.ExecuteQueryOneResultSet(sql))
                {
                    List <int> discoveredTraceFlags = new List <int>();
                    foreach (DataRow row in table.Rows)
                    {
                        int  traceFlagNumber   = (int)(short)row["TraceFlag"];
                        bool enabledForSession = (short)row["Session"] != 0;

                        discoveredTraceFlags.Add(traceFlagNumber);
                        TraceFlag traceFlag = ViewerSettings.Instance.TraceFlags.FirstOrDefault(tf => tf.TraceFlagNumber == traceFlagNumber);
                        if (traceFlag != null)
                        {
                            if (traceFlag.Enabled != enabledForSession)
                            {
                                ToggleTraceFlag(traceFlagNumber, traceFlag.Enabled);
                            }
                        }
                    }

                    if (ViewerSettings.Instance.TraceFlags != null)
                    {
                        // Handle trace flags that are enabled in options but not returned by dbcc tracestatus
                        List <TraceFlag> traceFlags = ViewerSettings.Instance.TraceFlags.Where(tf => tf.Enabled && discoveredTraceFlags.Contains(tf.TraceFlagNumber) == false).ToList();
                        traceFlags.ForEach(tf => ToggleTraceFlag(tf.TraceFlagNumber, true));
                    }
                }
            }
        }
Example #2
0
        private void TraceFlagGrid_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (_inChangeHandler == false)
            {
                try
                {
                    _inChangeHandler = true;
                    traceFlagGrid.CommitEdit(DataGridViewDataErrorContexts.Commit);

                    int row = traceFlagGrid.CurrentCell.RowIndex;
                    DataGridViewCell cell = traceFlagGrid["TF", row];
                    int  traceFlagNumber  = (int)cell.Value;
                    bool enabled          = (bool)traceFlagGrid.CurrentCell.Value;

                    TraceFlag traceFlag = _boundTraceFlags.FirstOrDefault(tf => tf.TraceFlagNumber == traceFlagNumber);

                    // Check that any parent trace flags are also enabled
                    if (enabled == true)
                    {
                        if (traceFlag.ParentTraceFlag != null)
                        {
                            TraceFlag parentTraceFlag = _boundTraceFlags.FirstOrDefault(tf => tf.TraceFlagNumber == traceFlag.ParentTraceFlag.Value);
                            if (parentTraceFlag != null)
                            {
                                if (parentTraceFlag.Enabled == false)
                                {
                                    parentTraceFlag.Enabled = true;
                                    _boundTraceFlags.ResetBindings();
                                }
                            }
                        }
                    }

                    // Check that any child trace flags are disabled
                    if (enabled == false)
                    {
                        List <TraceFlag> childTraceFlags = _boundTraceFlags.Where(tf => tf.ParentTraceFlag == traceFlag.TraceFlagNumber).ToList();
                        int itemsChanged = 0;
                        foreach (TraceFlag childTraceFlag in childTraceFlags)
                        {
                            if (childTraceFlag.Enabled == true)
                            {
                                childTraceFlag.Enabled = false;
                                itemsChanged++;
                            }
                        }
                        if (itemsChanged > 0)
                        {
                            _boundTraceFlags.ResetBindings();
                        }
                    }
                }
                finally
                {
                    _inChangeHandler = false;
                }
            }
        }
        public override bool Equals(object obj)
        {
            TraceFlag that = obj as TraceFlag;

            if (that == null)
            {
                return(false);
            }

            return(this.TraceFlagNumber == that.TraceFlagNumber);
        }
Example #4
0
        private void SyncTraceFlagsToDefault()
        {
            if (ViewerSettings.Clone.TraceFlags == null)
            {
                ViewerSettings.Clone.TraceFlags = new List <TraceFlag>();
            }

            foreach (TraceFlag traceFlag in TraceFlag.DefaultTraceFlagList)
            {
                TraceFlag existingTraceFlag = ViewerSettings.Clone.TraceFlags.FirstOrDefault(tf => tf.TraceFlagNumber == traceFlag.TraceFlagNumber);
                if (existingTraceFlag != null)
                {
                    existingTraceFlag.Description = traceFlag.Description;
                }
                else
                {
                    ViewerSettings.Clone.TraceFlags.Add(traceFlag);
                }
            }

            // Delete any trace flag entries not in the default list.
            ViewerSettings.Clone.TraceFlags.Except(TraceFlag.DefaultTraceFlagList).ToList().ForEach(tf => ViewerSettings.Clone.TraceFlags.Remove(tf));
        }