Esempio n. 1
0
        private static void ProcessQueryPlan(string planXml, QueryPlanUserControl control)
        {
            if (string.IsNullOrEmpty(planXml))
            {
                ShowError("Cannot retrieve query plan");
                return;
            }

            var queryPlanProcessor = new QueryPlanProcessor(planXml);

            var indexes  = queryPlanProcessor.GetMissingIndexes();
            var planHtml = queryPlanProcessor.ConvertPlanToHtml();

            var files = ExtractFiles();

            files.Add(planHtml);

            var html = string.Format(Resources.template, files.ToArray());

            control.DisplayExecutionPlanDetails(planXml, html, indexes);
        }
        private static void DumpPlanInternal <T>(IQueryable <T> queryable, bool dumpData, bool addNewPanel)
        {
            if (Util.CurrentDataContext != null && !(Util.CurrentDataContext.Connection is SqlConnection))
            {
                ShowError("Query Plan Visualizer supports only Sql Server");
                return;
            }

            var databaseHelper = DatabaseHelper.Create(Util.CurrentDataContext, queryable);

            if (dumpData)
            {
                queryable.Dump();
            }

            try
            {
                var planXml = databaseHelper.GetSqlServerQueryExecutionPlan(queryable);

                if (string.IsNullOrEmpty(planXml))
                {
                    ShowError("Cannot retrieve query plan");
                    return;
                }

                var queryPlanProcessor = new QueryPlanProcessor(planXml);

                var indexes  = queryPlanProcessor.GetMissingIndexes();
                var planHtml = queryPlanProcessor.ConvertPlanToHtml();


                var files = ExtractFiles();
                files.Add(planHtml);

                var html = string.Format(Resources.template, files.ToArray());

                var control = PanelManager.GetOutputPanel(ExecutionPlanPanelTitle)?.GetControl() as QueryPlanUserControl;

                if (control == null || addNewPanel)
                {
                    control = new QueryPlanUserControl()
                    {
                        DatabaseHelper = databaseHelper
                    };

                    control.IndexCreated += (sender, args) =>
                    {
                        if (MessageBox.Show("Index created. Refresh query plan?", "", MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            DumpPlanInternal(queryable, false, false);
                        }
                    };

                    PanelManager.DisplayControl(control, ExecutionPlanPanelTitle);
                }
                control.DisplayExecutionPlanDetails(planXml, html, indexes);
            }
            catch (Exception exception)
            {
                ShowError(exception.ToString());
            }
        }