/Tools/LinqPad/LINQPad/UI/QueryControl.cs
C# | 5227 lines | 4971 code | 255 blank | 1 comment | 1166 complexity | f9b8f29f0fabf30d488ecc21c7e86f1b MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.0, Apache-2.0
Large files files are truncated, but you can click here to view the full file
- namespace LINQPad.UI
- {
- using ActiproBridge;
- using ActiproSoftware.Drawing;
- using ActiproSoftware.SyntaxEditor;
- using ActiproSoftware.SyntaxEditor.Addons.CSharp;
- using ActiproSoftware.SyntaxEditor.Addons.DotNet.Ast;
- using LINQPad;
- using LINQPad.ExecutionModel;
- using LINQPad.Properties;
- using Microsoft.Win32;
- using mscorlib;
- using System;
- using System.CodeDom.Compiler;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Windows.Forms;
- using System.Xml.Linq;
- [ComVisible(true)]
- public class QueryControl : UserControl
- {
- private Timer _autoSaveTimer;
- private volatile bool _autoSaving;
- private bool? _autoScrollResultsFromQuery;
- private bool _browserHidden;
- private Timer _clockTimer;
- private bool _compileOnly;
- private List<BitmapBookmarkLineIndicator> _currentExecutionStack;
- private DataResultsWebBrowser _dataBrowser;
- private BrowserBorder _dataPanel;
- private DocumentManager _docMan;
- private QueryEditor _editor;
- private bool _enableUseCurrentDb;
- private Color? _errorSquigglyColor;
- private QueryLanguage _executingQueryLanguage;
- private bool _executingQueryOptimized;
- private Timer _executionTrackingTimer;
- private bool _firstExecutionTrack;
- private bool _firstResultsShow;
- private bool _gotPluginsReadyMessage;
- private volatile bool _gotQueryCompletionMessage;
- private Timer _ieComExceptionTimer;
- private ResultsWebBrowser _ilBrowser;
- private MemoryStream _ilData;
- private bool _ilDirty;
- private BrowserBorder _ilPanel;
- private ResultsWebBrowser _lambdaBrowser;
- private MemoryStream _lambdaData;
- private BrowserBorder _lambdaPanel;
- private bool? _lastAutoScrollResultsFromQuery;
- private QueryCompilationEventArgs _lastCompilation;
- private static string _lastDefaultQueryFolder;
- private int _lastExecutionLine;
- private int _lastExecutionLineCount;
- private ExecutionProgress? _lastExecutionProgress;
- private int _lastExecutionTrackCost1;
- private int _lastExecutionTrackCost2;
- private QueryLanguage _lastQueryKind;
- private string _lastRanSourceSelection;
- private static string _lastSaveFolder;
- private DateTime _lastServerAction;
- private ExecutionTrackInfo _lastTrackInfo;
- private long _memoryAtStart;
- private bool _modifiedWhenRunning;
- private MemoryStream _msData;
- private double _oldHorizontalSplitFraction;
- private double _oldVerticalSplitFraction;
- private bool _optimizeTipShown;
- private string _outputInfoMessage;
- private bool _pendingReflection;
- private bool _pendingResultsShow;
- private string _pendingSqlTranslation;
- private ContextMenuStrip _pluginWinButtonMenu;
- private List<ToolStripButton> _pluginWinButtons;
- private PluginWindowManager _pluginWinManager;
- private volatile bool _processingProvisionalData;
- private RunnableQuery _query;
- private int _queryCount;
- private int _querySelectionStartCol;
- private int _querySelectionStartRow;
- private Random _random;
- private ReadLinePanel _readLinePanel;
- private bool _readLinePanelVisible;
- private int _refreshTicksOnResults;
- private Timer _refreshTimer;
- private byte[] _resultsContent;
- private SchemaTree _schemaTree;
- private bool _splitterMovingViaToolStrip;
- private int _suppressPullCount;
- private bool _uberCancelMessage;
- private static bool _warnedAboutOptimizationTracking;
- private Color? _warningSquigglyColor;
- private ToolStripMenuItem btn1NestingLevel;
- private ToolStripMenuItem btn2NestingLevels;
- private ToolStripMenuItem btn3NestingLevels;
- private ToolStripButton btnActivateAutocompletion;
- private ToolStripMenuItem btnAllNestingLevels;
- private ToolStripDropDownButton btnAnalyze;
- private ToolStripDropDownButton btnArrange;
- private ImageButton btnCancel;
- private ClearButton btnClose;
- private ImageButton btnExecute;
- private ToolStripDropDownButton btnExport;
- private ToolStripMenuItem btnExportExcel;
- private ToolStripMenuItem btnExportExcelNoFormat;
- private ToolStripMenuItem btnExportHtml;
- private ToolStripMenuItem btnExportWord;
- private ToolStripMenuItem btnExportWordNoFormat;
- private ToolStripDropDownButton btnFormat;
- private ClearButton btnGrids;
- private ToolStripButton btnIL;
- private ToolStripButton btnLambda;
- private ClearButton btnPin;
- private ToolStripMenuItem btnResultFormattingPreferences;
- private ToolStripButton btnResults;
- private ToolStripButton btnSql;
- private ClearButton btnText;
- private ComboBox cboDb;
- private ComboBox cboLanguage;
- private IContainer components;
- private Label lblDb;
- private ToolStripStatusLabel lblElapsed;
- private ToolStripStatusLabel lblExecTime;
- private ToolStripStatusLabel lblFill;
- private ToolStripStatusLabel lblMiscStatus;
- private ToolStripStatusLabel lblOptimize;
- private ToolStripStatusLabel lblStatus;
- private Label lblSyncDb;
- private Label lblType;
- private ToolStripStatusLabel lblUberCancel;
- private FixedLinkLabel llDbUseCurrent;
- private ToolStripMenuItem miArrangeVertical;
- private ToolStripMenuItem miAutoScroll;
- private ToolStripMenuItem miHideResults;
- private ToolStripMenuItem miKeyboardShortcuts;
- private ToolStripMenuItem miOpenInSSMS;
- private ToolStripMenuItem miOpenSQLQueryNewTab;
- private ToolStripMenuItem miScrollEnd;
- private ToolStripMenuItem miScrollStart;
- private ToolStripMenuItem miUndock;
- private Panel panBottom;
- private Panel panCloseButton;
- private Panel panEditor;
- private Panel panError;
- private Panel panMain;
- private PanelEx panOutput;
- private Panel panTop;
- private TableLayoutPanel panTopControls;
- private ToolStripProgressBar queryProgressBar;
- private SplitContainer splitContainer;
- private StatusStrip statusStrip;
- private ToolStripSeparator toolStripMenuItem1;
- private ToolStripSeparator toolStripMenuItem2;
- private ToolStripSeparator toolStripMenuItem3;
- private ToolStripSeparator toolStripMenuItem4;
- private ToolStripSeparator toolStripSeparator1;
- private ToolTip toolTip;
- private ToolStripEx tsOutput;
- private TextBox txtError;
- private ActiproSoftware.SyntaxEditor.SyntaxEditor txtSQL;
- internal event EventHandler NextQueryRequest;
- internal event EventHandler PreviousQueryRequest;
- internal event EventHandler QueryClosed;
- internal QueryControl(RunnableQuery q, SchemaTree schemaTree)
- {
- EventHandler onClick = null;
- EventHandler handler2 = null;
- EventHandler handler3 = null;
- EventHandler handler4 = null;
- SplitterCancelEventHandler handler5 = null;
- this._browserHidden = true;
- Timer timer = new Timer {
- Interval = 0x2710,
- Enabled = true
- };
- this._autoSaveTimer = timer;
- this._executionTrackingTimer = new Timer();
- this._pluginWinButtons = new List<ToolStripButton>();
- this._query = new RunnableQuery();
- this.NextQueryRequest = delegate (object sender, EventArgs e) {
- };
- this.PreviousQueryRequest = delegate (object sender, EventArgs e) {
- };
- this._lambdaData = new MemoryStream();
- this._ilDirty = true;
- this._ilData = new MemoryStream();
- this._queryCount = 0;
- Timer timer2 = new Timer {
- Interval = 200
- };
- this._refreshTimer = timer2;
- Timer timer3 = new Timer {
- Interval = 200
- };
- this._clockTimer = timer3;
- this._firstResultsShow = true;
- this._lastQueryKind = QueryLanguage.SQL;
- this._suppressPullCount = 0;
- this._random = new Random();
- this.components = null;
- this._query = q;
- this._schemaTree = schemaTree;
- try
- {
- this.Font = FontManager.GetDefaultFont();
- }
- catch
- {
- }
- this.InitializeComponent();
- this.CheckIsMyExtensions();
- this._pluginWinManager = new PluginWindowManager(this);
- this._pluginWinButtonMenu = new ContextMenuStrip(this.components);
- if (onClick == null)
- {
- onClick = (sender, e) => this.CloseCurrentVisualizer();
- }
- this._pluginWinButtonMenu.Items.Add("Close visualizer (Shift+F4 or Middle-Click or Ctrl+Click)", Resources.Delete, onClick);
- if (this.btnExecute.Height > 0x20)
- {
- this.btnExecute.Height -= 3;
- this.cboLanguage.Margin = new Padding(this.cboLanguage.Margin.Left, 2, this.cboLanguage.Margin.Right, 4);
- this.cboDb.Margin = new Padding(this.cboDb.Margin.Left, 2, this.cboDb.Margin.Right, 4);
- }
- else if (this.btnExecute.Height > 0x1d)
- {
- this.btnExecute.Height -= 2;
- }
- else if (this.btnExecute.Height > 0x18)
- {
- this.btnExecute.Height--;
- }
- this.btnCancel.Height = this.btnExecute.Height;
- this.btnText.Height = this.btnGrids.Height = this.btnExecute.Height - 1;
- if ((IntPtr.Size == 4) && (this.btnExecute.Height > 0x1b))
- {
- Padding margin = this.cboLanguage.Margin;
- this.cboLanguage.Margin = new Padding(margin.Left, margin.Top, margin.Right, margin.Bottom - 1);
- margin = this.cboDb.Margin;
- this.cboDb.Margin = new Padding(margin.Left, margin.Top, margin.Right, margin.Bottom - 1);
- }
- if (this.btnExecute.Height > 40)
- {
- this.btnExecute.Image = ControlUtil.ResizeImage(this.btnExecute.Image, this.btnExecute.Width, this.btnExecute.Height, true);
- this.btnCancel.Image = ControlUtil.ResizeImage(this.btnCancel.Image, this.btnCancel.Width, this.btnCancel.Height, true);
- this.btnGrids.Image = ControlUtil.ResizeImage(this.btnGrids.Image, (this.btnGrids.Width * 3) / 4, (this.btnGrids.Height * 3) / 4, true);
- this.btnText.Image = ControlUtil.ResizeImage(this.btnText.Image, (this.btnText.Width * 3) / 4, (this.btnText.Height * 3) / 4, true);
- }
- this.UpdateAutocompletionMsg();
- try
- {
- this.txtError.Font = new Font("Verdana", 8.25f);
- this.txtSQL.Font = new Font("Verdana", 9.5f);
- this.btnActivateAutocompletion.Font = new Font("Verdana", 8f, FontStyle.Bold);
- this.lblOptimize.Font = new Font("Verdana", 7f, FontStyle.Bold);
- }
- catch
- {
- }
- this.txtSQL.get_Document().set_Language(DocumentManager.GetDynamicLanguage("SQL", SystemColors.Window.GetBrightness()));
- this.txtSQL.get_Document().get_Outlining().set_Mode(2);
- this.txtSQL.set_BracketHighlightingVisible(true);
- this.txtSQL.get_Document().set_ReadOnly(true);
- VisualStudio2005SyntaxEditorRenderer renderer = new VisualStudio2005SyntaxEditorRenderer();
- SimpleBorder border = new SimpleBorder();
- border.set_Style(0);
- renderer.set_Border(border);
- VisualStudio2005SyntaxEditorRenderer renderer2 = renderer;
- this.txtSQL.set_Renderer(renderer2);
- this._docMan = new DocumentManager(this._query, this);
- this.CreateEditor();
- this.PropagateOptions();
- this.UpdateEditorZoom();
- this.CreateBrowser();
- this._browserHidden = true;
- this.panBottom.BorderStyle = BorderStyle.None;
- this.tsOutput.BackColor = Color.Transparent;
- this.tsOutput.Renderer = new OutputToolsRenderer();
- this.statusStrip.BackColor = Color.Transparent;
- this.statusStrip.Padding = new Padding(this.statusStrip.Padding.Left, this.statusStrip.Padding.Top, this.statusStrip.Padding.Left, this.statusStrip.Padding.Bottom);
- this.PullData(QueryChangedEventArgs.Refresh);
- this.ToggleResultsCollapse();
- this._query.QueryCompiled += new EventHandler<QueryCompilationEventArgs>(this._query_QueryCompiled);
- this._query.PluginsReady += new EventHandler(this._query_PluginsReady);
- this._query.CustomClickCompleted += new EventHandler(this._query_CustomClickCompleted);
- this._query.QueryCompleted += new EventHandler<QueryStatusEventArgs>(this._query_QueryCompleted);
- this._query.QueryChanged += new EventHandler<QueryChangedEventArgs>(this._query_QueryChanged);
- this._query.ReadLineRequested += new EventHandler<ReadLineEventArgs>(this._query_ReadLineRequested);
- this._editor.TextChanged += new EventHandler(this._editor_TextChanged);
- this._editor.add_SelectionChanged(new SelectionEventHandler(this, (IntPtr) this._editor_SelectionChanged));
- this._editor.RepositoryDropped += new EventHandler<QueryEditor.RepositoryEventArgs>(this._editor_RepositoryDropped);
- this._schemaTree.AfterSelect += new TreeViewEventHandler(this._schemaTree_AfterSelect);
- this._docMan.CheckForRepositoryChange();
- this._refreshTimer.Tick += new EventHandler(this.RefreshTimer_Tick);
- this._clockTimer.Tick += new EventHandler(this.ClockTimer_Tick);
- this._autoSaveTimer.Tick += new EventHandler(this.AutoSaveTimer_Tick);
- if (handler2 == null)
- {
- handler2 = (sender, e) => this.ReportMainThreadPosition();
- }
- this._executionTrackingTimer.Tick += handler2;
- if (SystemColors.Window.GetBrightness() < 0.5f)
- {
- this.llDbUseCurrent.ForeColor = SystemColors.HotTrack;
- }
- this.ExtendOutputSplitter();
- if (handler3 == null)
- {
- handler3 = (sender, e) => this.UpdateErrorHeight();
- }
- this.panError.SizeChanged += handler3;
- this.statusStrip.Parent = null;
- base.Controls.Add(this.statusStrip);
- this.statusStrip.SendToBack();
- if (handler4 == null)
- {
- handler4 = (sender, e) => this.RequestWinManagerRelocation();
- }
- EventHandler handler6 = handler4;
- this.panOutput.Resize += handler6;
- for (Control control = this.panOutput; control != null; control = control.Parent)
- {
- control.Move += handler6;
- }
- this._query.PluginWindowManager = this._pluginWinManager;
- this.queryProgressBar.Margin = new Padding(3, 3, 0, 1);
- this.tsOutput.Padding = new Padding(0, 0, 0, 2);
- this.splitContainer.SplitterWidth--;
- if (handler5 == null)
- {
- handler5 = delegate (object sender, SplitterCancelEventArgs e) {
- if (Control.MouseButtons == MouseButtons.Left)
- {
- MainForm.Instance.IsSplitting = true;
- }
- if ((this.panOutput.BackColor == MainForm.Instance.TransparencyKey) && (this.panOutput.BackColor != Program.LightTransparencyKey))
- {
- this.panOutput.BackColor = MainForm.Instance.TransparencyKey = Program.LightTransparencyKey;
- }
- };
- }
- this.splitContainer.SplitterMoving += handler5;
- this.panOutput.BorderStyle = BorderStyle.None;
- this.panOutput.BorderColor = Color.FromArgb(160, 160, 160);
- this.lblSyncDb.Cursor = Cursors.Hand;
- this.toolTip.ShowAlways = true;
- this.EnableControls();
- this.panBottom.Layout += new LayoutEventHandler(this.panBottom_Layout);
- }
- private void _browser_LinqClicked(object sender, LinqClickEventArgs e)
- {
- WebHelper.LaunchBrowser(e.Uri.ToString());
- }
- private void _browser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
- {
- if (e.KeyData == Keys.F5)
- {
- e.IsInputKey = true;
- this.Run();
- }
- else if (e.KeyData == (Keys.Control | Keys.Shift | Keys.E))
- {
- MainForm.Instance.ToggleAutoScrollResults(true);
- }
- }
- private void _editor_RepositoryDropped(object sender, QueryEditor.RepositoryEventArgs e)
- {
- Func<LinkedDatabase, bool> predicate = null;
- if (!this._query.IsMyExtensions)
- {
- this.CheckToFromProgramLanguage(this._query.QueryKind, this._query.QueryKind, this._query.Repository != null, e.Repository != null);
- if (!((this._query.Repository != null) && e.Copy))
- {
- this._query.Repository = e.Repository;
- }
- else
- {
- if ((!e.Repository.IsSqlServer || !this._query.Repository.IsSqlServer) || (e.Repository.Server.ToLowerInvariant() != this._query.Repository.Server.ToLowerInvariant()))
- {
- MessageBox.Show("Multi-database queries are supported only for SQL Server databases on the same server (or linked servers).", "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- return;
- }
- if (this._query.Repository.IsAzure || e.Repository.IsAzure)
- {
- MessageBox.Show("SQL Azure does not permit cross-database queries.", "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- return;
- }
- if (this._query.Repository.Database == e.Repository.Database)
- {
- return;
- }
- if (predicate == null)
- {
- predicate = d => string.IsNullOrEmpty(d.Server) && (d.Database == e.Repository.Database);
- }
- if (this._query.Repository.LinkedDatabases.Any<LinkedDatabase>(predicate))
- {
- return;
- }
- if (this._query.Repository.Parent != null)
- {
- Repository r = this._query.Repository.Clone();
- r.ID = Guid.NewGuid();
- r.ShowServer = false;
- r.Persist = false;
- r.LinkedDatabases = r.LinkedDatabases.Concat<LinkedDatabase>(new LinkedDatabase[] { new LinkedDatabase(e.Repository.Database) });
- this._schemaTree.AddCx(r, false, false);
- this._query.Repository = r;
- }
- else
- {
- this._query.Repository.LinkedDatabases = this._query.Repository.LinkedDatabases.Concat<LinkedDatabase>(new LinkedDatabase[] { new LinkedDatabase(e.Repository.Database) });
- this._schemaTree.UpdateRepository(this._query.Repository);
- }
- }
- this._editor.Focus();
- }
- }
- private void _editor_SelectionChanged(object sender, EventArgs e)
- {
- this.ClearQueryHighlight();
- if (this._docMan.ExecutedSelectionLayer.get_Count() > 0)
- {
- this._docMan.ExecutedSelectionLayer.Clear();
- }
- }
- private void _editor_TextChanged(object sender, EventArgs e)
- {
- this._modifiedWhenRunning = true;
- using (this.SuppressPull())
- {
- this._query.Source = this._editor.Text;
- }
- this.btnPin.Checked = this._query.Pinned;
- this.ClearQueryHighlight();
- if (this._docMan.StackTraceLayer.get_Count() > 0)
- {
- this._docMan.StackTraceLayer.Clear();
- }
- this.ClearExecutionTrackingIndicators();
- }
- private void _query_CustomClickCompleted(object sender, EventArgs e)
- {
- this._outputInfoMessage = null;
- }
- private void _query_PluginsReady(object sender, EventArgs e)
- {
- this.BeginInvoke(delegate {
- this._gotPluginsReadyMessage = true;
- foreach (PluginControl control in this._pluginWinManager.GetControls())
- {
- this.CreatePluginWinButton(control, false, false);
- }
- if (this._pluginWinButtons.Any<ToolStripButton>())
- {
- bool flag = MainForm.Instance.CurrentQueryControl == this;
- if (this.btnResults.Checked && !this.panError.Visible)
- {
- if (flag)
- {
- base.FindForm().Activate();
- }
- this.SelectOutputPanel(this._pluginWinButtons[0], false);
- }
- else
- {
- this.UpdateOutputToolStripLayout();
- }
- if (flag)
- {
- base.FindForm().Activate();
- }
- else
- {
- this._pluginWinManager.Hide();
- }
- }
- });
- }
- private void _query_QueryChanged(object sender, QueryChangedEventArgs e)
- {
- this.KillIEComExceptionTimer();
- this.PullData(e);
- }
- private void _query_QueryCompiled(object sender, QueryCompilationEventArgs e)
- {
- this.BeginInvoke(delegate {
- try
- {
- this.QueryCompiled(e);
- }
- catch (Exception exception)
- {
- Program.ProcessException(exception);
- }
- });
- }
- private void _query_QueryCompleted(object sender, QueryStatusEventArgs e)
- {
- if (e.ExecutionComplete)
- {
- this._clockTimer.Stop();
- }
- this.BeginInvoke(() => this.QueryCompleted(e));
- }
- private void _query_ReadLineRequested(object sender, ReadLineEventArgs e)
- {
- int num = this._queryCount;
- while (this._readLinePanelVisible)
- {
- Thread.Sleep(100);
- if (this._queryCount != num)
- {
- return;
- }
- }
- base.BeginInvoke(() => this.ShowReadLinePanel(e.Client, e.Prompt, e.DefaultValue, e.Options));
- }
- private void _schemaTree_AfterSelect(object sender, TreeViewEventArgs e)
- {
- this.UpdateFocusedRepository();
- }
- internal void ActivateAndKillDomain()
- {
- base.FindForm().Activate();
- Program.RunOnWinFormsTimer(() => this.Cancel(true), 0x7d0);
- }
- internal void ActivateHelp()
- {
- if (!(MainForm.Instance.ShowLicensee || !(this._editor.get_SelectedView().get_SelectedText() == "")))
- {
- MessageBox.Show("This feature requires an Autocompletion license.", "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- }
- else
- {
- MemberHelpInfo memberHelpInfo = this.GetMemberHelpInfo();
- string str = ((memberHelpInfo == null) || !memberHelpInfo.HasStrongName) ? null : memberHelpInfo.get_HelpSearchString();
- if (string.IsNullOrEmpty(str))
- {
- str = (this._editor.get_SelectedView().get_SelectedText() ?? "").Trim();
- if (str.Length == 0)
- {
- return;
- }
- if (this._query.QueryKind <= QueryLanguage.Program)
- {
- str = "C# " + str;
- }
- else if (this._query.QueryKind.ToString().StartsWith("VB"))
- {
- str = "VB " + str;
- }
- else if (this._query.QueryKind.ToString().StartsWith("FSharp"))
- {
- str = "F# " + str;
- }
- else if (this._query.QueryKind == QueryLanguage.SQL)
- {
- str = "\"SQL Server\" " + str;
- }
- else
- {
- str = this._query.QueryKind + " " + str;
- }
- }
- WebHelper.LaunchBrowser("http://www.google.com/search?hl=en&q=" + Uri.EscapeDataString(str));
- }
- }
- public void ActivateReflector()
- {
- if (!MainForm.Instance.ShowLicensee)
- {
- MessageBox.Show("This feature requires an Autocompletion license.", "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- }
- else
- {
- MemberHelpInfo memberHelpInfo = this.GetMemberHelpInfo();
- if ((memberHelpInfo != null) && !string.IsNullOrEmpty(memberHelpInfo.get_ReflectorCodeUri()))
- {
- ReflectorAgent.ActivateReflector(memberHelpInfo);
- }
- }
- }
- internal void AncestorMoved()
- {
- this.RequestWinManagerRelocation();
- }
- internal bool AreResultsCollapsed()
- {
- return (this.panEditor.Parent == this.panMain);
- }
- internal bool AreResultsDetached()
- {
- return (this.panBottom.Parent != this.splitContainer.Panel2);
- }
- internal bool AreResultsVisible()
- {
- return (!this.AreResultsCollapsed() || this.AreResultsDetached());
- }
- internal void AttachResultsControl(Control c)
- {
- c.Parent = this.splitContainer.Panel2;
- if (this.AreResultsCollapsed())
- {
- this.ToggleResultsCollapse();
- }
- this.UpdateOutputVisibility();
- }
- private void AutoSaveTimer_Tick(object sender, EventArgs e)
- {
- if (!base.IsDisposed && !(!this._query.IsModified || this._autoSaving))
- {
- ThreadPool.QueueUserWorkItem(delegate (object param0) {
- if (!this._autoSaving)
- {
- this._autoSaving = true;
- try
- {
- this._query.AutoSave(false);
- }
- catch
- {
- }
- finally
- {
- this._autoSaving = false;
- }
- }
- });
- }
- }
- private void BeginInvoke(Action a)
- {
- base.BeginInvoke(a);
- }
- private void btn1NestingLevel_Click(object sender, EventArgs e)
- {
- this.CollapseResultsTo(1);
- }
- private void btn2NestingLevels_Click(object sender, EventArgs e)
- {
- this.CollapseResultsTo(2);
- }
- private void btn3NestingLevels_Click(object sender, EventArgs e)
- {
- this.CollapseResultsTo(3);
- }
- private void btnActivateAutocompletion_Click(object sender, EventArgs e)
- {
- MainForm.Instance.ActivateAutocompletion();
- }
- private void btnAllNestingLevels_Click(object sender, EventArgs e)
- {
- this.CollapseResultsTo(null);
- }
- private void btnArrange_DropDownOpening(object sender, EventArgs e)
- {
- this.miUndock.Checked = MainForm.Instance.ResultsDockForm.AreResultsTorn;
- this.miArrangeVertical.Checked = MainForm.Instance.VerticalResultsLayout;
- this.miUndock.Enabled = MainForm.Instance.ResultsDockForm.AreResultsTorn || (Screen.AllScreens.Length > 1);
- this.miAutoScroll.Checked = MainForm.Instance.AutoScrollResults;
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.Cancel(false);
- this._editor.Focus();
- }
- private void btnClose_Click(object sender, EventArgs e)
- {
- this.TryClose();
- }
- private void btnExecute_Click(object sender, EventArgs e)
- {
- this.Run();
- }
- private void btnExpandTypes_CheckedChanged(object sender, EventArgs e)
- {
- }
- private void btnExportExcel_Click(object sender, EventArgs e)
- {
- if ((this._msData != null) && (this._msData.Length > 0L))
- {
- this.OpenExcel(this.ExportResults(false));
- }
- }
- private void btnExportExcelNoFormat_Click(object sender, EventArgs e)
- {
- if ((this._msData != null) && (this._msData.Length > 0L))
- {
- this.OpenExcel(this.ExportResults(true));
- }
- }
- private void btnExportHtml_Click(object sender, EventArgs e)
- {
- if ((this._msData != null) && (this._msData.Length != 0L))
- {
- using (SaveFileDialog dialog = new SaveFileDialog())
- {
- dialog.Title = "Save Results";
- dialog.DefaultExt = "html";
- dialog.Filter = "HTML files (*.html)|*.html";
- if ((dialog.ShowDialog() == DialogResult.OK) && !string.IsNullOrEmpty(dialog.FileName))
- {
- try
- {
- using (FileStream stream = File.Create(dialog.FileName))
- {
- this._msData.WriteTo(stream);
- }
- }
- catch (Exception exception)
- {
- MessageBox.Show("Cannot write file: " + exception.Message);
- }
- }
- }
- }
- }
- private void btnExportWord_Click(object sender, EventArgs e)
- {
- if ((this._msData != null) && (this._msData.Length > 0L))
- {
- this.OpenWord(this.ExportResults(false));
- }
- }
- private void btnExportWordNoFormat_Click(object sender, EventArgs e)
- {
- if ((this._msData != null) && (this._msData.Length > 0L))
- {
- this.OpenWord(this.ExportResults(true));
- }
- }
- private void btnGrids_Click(object sender, EventArgs e)
- {
- this._query.ToDataGrids = true;
- }
- private void btnIL_Click(object sender, EventArgs e)
- {
- this.SelectILPanel(true);
- }
- private void btnLambda_Click(object sender, EventArgs e)
- {
- this.SelectLambdaPanel(true);
- }
- private void btnPin_Click(object sender, EventArgs e)
- {
- this._query.Pinned = !this._query.Pinned;
- }
- private void btnResultFormattingPreferences_Click(object sender, EventArgs e)
- {
- using (OptionsForm form = new OptionsForm(2))
- {
- if (form.ShowDialog(MainForm.Instance) == DialogResult.OK)
- {
- this.PropagateOptions();
- }
- }
- }
- private void btnResults_Click(object sender, EventArgs e)
- {
- this.SelectResultsPanel(true);
- }
- private void btnSql_Click(object sender, EventArgs e)
- {
- this.SelectSqlPanel(true);
- }
- private void btnText_Click(object sender, EventArgs e)
- {
- this._query.ToDataGrids = false;
- }
- internal void Cancel(bool uberMode)
- {
- if (!base.IsDisposed)
- {
- this._outputInfoMessage = null;
- this._executionTrackingTimer.Stop();
- this.ClearExecutionTrackingIndicators();
- if (this._editor.get_Document().get_LineIndicators().get_Count() == 0)
- {
- this._editor.set_IndicatorMarginVisible(false);
- }
- if ((((this._query.QueryKind != QueryLanguage.SQL) && (this._query.QueryKind != QueryLanguage.ESQL)) || this.btnCancel.Enabled) || uberMode)
- {
- this.HideReadLinePanel();
- this._pendingReflection = false;
- if (!((uberMode || Program.PreserveAppDomains) || this._query.IsRunning))
- {
- uberMode = true;
- }
- if (uberMode)
- {
- this.ResetPluginManager(true);
- this._query.Cancel(false, true);
- }
- else
- {
- this._query.Cancel(true, false);
- }
- if (this.btnCancel.Enabled || uberMode)
- {
- this.EnableControls();
- this.lblElapsed.Visible = false;
- this.lblStatus.Text = uberMode ? "Application Domain Unloaded" : "Query canceled";
- this.lblUberCancel.Visible = false;
- }
- }
- }
- }
- private void cboDb_DropDown(object sender, EventArgs e)
- {
- int num;
- this.UpdateRepositoryItems(true);
- Func<object, float> selector = null;
- using (Graphics g = this.cboDb.CreateGraphics())
- {
- if (selector == null)
- {
- selector = item => g.MeasureString(item.ToString(), this.cboDb.Font).Width;
- }
- num = (((int) this.cboDb.Items.Cast<object>().Max<object>(selector)) + SystemInformation.VerticalScrollBarWidth) + 2;
- }
- Rectangle workingArea = Screen.FromControl(this.cboDb).WorkingArea;
- this.cboDb.DropDownWidth = Math.Max(this.cboDb.Width, Math.Min((workingArea.Right - this.cboDb.PointToScreen(Point.Empty).X) - 3, num));
- }
- private void cboDb_DropDownClosed(object sender, EventArgs e)
- {
- this._editor.Focus();
- }
- private void cboDb_Enter(object sender, EventArgs e)
- {
- if (Control.ModifierKeys == Keys.Alt)
- {
- this.cboDb.DroppedDown = true;
- }
- }
- private void cboDb_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.cboDb.SelectedItem != null)
- {
- using (this.SuppressPull())
- {
- this.CheckToFromProgramLanguage();
- if (this.cboDb.SelectedItem is string)
- {
- if ((((string) this.cboDb.SelectedItem) == "<None>") && (this._query.Repository != null))
- {
- this._query.Repository = null;
- }
- else
- {
- this.cboDb.SelectedIndex = 0;
- }
- }
- Repository selectedItem = this.cboDb.SelectedItem as Repository;
- if (selectedItem != null)
- {
- this._query.Repository = selectedItem;
- }
- this.lblSyncDb.Visible = this._query.Repository != null;
- }
- this.btnPin.Checked = this._query.Pinned;
- this.UpdateFocusedRepository();
- this._docMan.CheckForRepositoryChange();
- this._schemaTree.UpdateSqlMode(this._query);
- }
- }
- private void cboLanguage_SelectionChangeCommitted(object sender, EventArgs e)
- {
- this.CheckToFromProgramLanguage();
- this._schemaTree.UpdateSqlMode(this._query);
- }
- private void cboType_DropDownClosed(object sender, EventArgs e)
- {
- this._editor.Focus();
- }
- private void cboType_Enter(object sender, EventArgs e)
- {
- if (Control.ModifierKeys == Keys.Alt)
- {
- this.cboLanguage.DroppedDown = true;
- }
- }
- private void cboType_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (this._editor.get_IntelliPrompt().get_MemberList().get_Visible())
- {
- this._editor.get_IntelliPrompt().get_MemberList().Abort();
- }
- QueryLanguage language = this.IndexToQueryLanguage(this.cboLanguage.SelectedIndex);
- if (language != this._query.QueryKind)
- {
- this._query.QueryKind = language;
- }
- }
- private bool CheckAndPromptQueryDriver()
- {
- if ((this._query.Repository == null) || this._query.Repository.DriverLoader.IsValid)
- {
- return true;
- }
- if (MessageBox.Show("The database for this query relies on the following custom driver which has not been installed:\r\n\r\n " + this._query.Repository.DriverLoader.SimpleAssemblyName + " (" + this._query.Repository.DriverLoader.PublicKeyToken + ")\r\n\r\nWould you like to view the publicly available drivers?", "LINQPad", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- using (BrowseDriversForm form = new BrowseDriversForm(true))
- {
- form.ShowDialog(MainForm.Instance);
- if (form.DoRestart)
- {
- MainForm.Instance.Restart();
- }
- }
- }
- return false;
- }
- internal void CheckAutocompletionCache()
- {
- this._docMan.ConfigureResolver();
- }
- private void CheckIsMyExtensions()
- {
- if (this._query.IsMyExtensions)
- {
- if (this.cboLanguage.Items.Count > 1)
- {
- this.cboLanguage.Items.Clear();
- this.cboLanguage.Items.Add("C# Program");
- }
- this.cboDb.Enabled = false;
- }
- }
- private void CheckQueryRepositoryWithSchemaTree()
- {
- if ((this._query.Repository != null) && (this._query.Repository != this._schemaTree.GetCurrentRepository(true)))
- {
- bool isModified = this._query.IsModified;
- this._schemaTree.RegisterRepository(this._query, false, false);
- if (!(isModified || !this._query.IsModified))
- {
- this._query.IsModified = false;
- }
- }
- }
- internal void CheckToFromProgramLanguage()
- {
- this.CheckToFromProgramLanguage(this._query.QueryKind, this.IndexToQueryLanguage(this.cboLanguage.SelectedIndex), this._query.Repository != null, this.cboDb.SelectedIndex > 0);
- }
- internal void CheckToFromProgramLanguage(QueryLanguage oldLanguage, QueryLanguage newLanguage, bool oldDC, bool newDC)
- {
- string str2;
- bool flag = (oldLanguage == QueryLanguage.FSharpProgram) && oldDC;
- bool flag2 = (newLanguage == QueryLanguage.FSharpProgram) && newDC;
- string str = UserOptions.Instance.ConvertTabsToSpaces ? "".PadRight(UserOptions.Instance.TabSizeActual) : "\t";
- if ((oldLanguage == QueryLanguage.Program) && (newLanguage != QueryLanguage.Program))
- {
- if (this._editor.Text.StartsWith("void Main", StringComparison.Ordinal) && this._editor.Text.TrimEnd(new char[0]).EndsWith("// Define other methods and classes here", StringComparison.Ordinal))
- {
- str2 = Regex.Replace(Regex.Replace(this._editor.Text, @"^void Main\s*\(\s*\)\s*{\s*", ""), @"\s*}\s*// Define other methods and classes here\s*$", "").Replace("\n" + str, "\n");
- this._editor.Text = str2;
- }
- }
- else if ((oldLanguage == QueryLanguage.VBProgram) && (newLanguage != QueryLanguage.VBProgram))
- {
- if (this._editor.Text.StartsWith("Sub Main", StringComparison.OrdinalIgnoreCase) && this._editor.Text.TrimEnd(new char[0]).EndsWith("' Define other methods and classes here", StringComparison.OrdinalIgnoreCase))
- {
- str2 = Regex.Replace(Regex.Replace(this._editor.Text, @"^Sub Main\s*", "", RegexOptions.IgnoreCase), @"\s*End Sub\s*' Define other methods and classes here\s*$", "", RegexOptions.IgnoreCase).Replace("\n" + str, "\n");
- this._editor.Text = str2;
- }
- }
- else if (!(!flag || flag2) && this._editor.Text.StartsWith("let dc = new TypedDataContext()", StringComparison.Ordinal))
- {
- this._editor.Text = this._editor.Text.Substring("let dc = new TypedDataContext()".Length).TrimStart(new char[0]);
- }
- if ((oldLanguage != QueryLanguage.Program) && (newLanguage == QueryLanguage.Program))
- {
- if (!((this._editor.Text.Contains("void Main") || this._editor.Text.ToUpperInvariant().Contains("SUB MAIN")) || this._editor.Text.Contains("Task Main")))
- {
- this._editor.Text = "void Main()\n{\n" + str + this._query.Source.Replace("\n", "\n" + str) + "\n}\n\n// Define other methods and classes here\n";
- this._editor.get_SelectedView().get_Selection().set_TextRange(new TextRange(14 + str.Length));
- }
- }
- else if ((oldLanguage != QueryLanguage.VBProgram) && (newLanguage == QueryLanguage.VBProgram))
- {
- if (!(this._editor.Text.ToUpperInvariant().Contains("SUB MAIN") || this._editor.Text.Contains("void Main")))
- {
- this._editor.Text = "Sub Main\n" + str + this._query.Source.Replace("\n", "\n" + str) + "\nEnd Sub\n\n' Define other methods and classes here\n";
- this._editor.get_SelectedView().get_Selection().set_TextRange(new TextRange(9 + str.Length));
- }
- }
- else if (!(flag || !flag2) && !this._editor.Text.Contains("let dc = new TypedDataContext()"))
- {
- this._editor.Text = "let dc = new TypedDataContext()\r\n\r\n" + this._query.Source;
- this._editor.get_SelectedView().get_Selection().set_TextRange(new TextRange("let dc = new TypedDataContext()".Length + 2));
- }
- }
- private void ClearExecutionTrackingIndicators()
- {
- if (this._currentExecutionStack != null)
- {
- foreach (BitmapBookmarkLineIndicator indicator in this._currentExecutionStack)
- {
- this._editor.get_Document().get_LineIndicators().Remove(indicator);
- }
- this._currentExecutionStack = null;
- }
- }
- private void ClearQueryHighlight()
- {
- if (this._editor.get_CurrentLineHighlightingVisible())
- {
- this._editor.set_CurrentLineHighlightingVisible(false);
- }
- }
- private void ClearRegion()
- {
- }
- private void ClockTimer_Tick(object sender, EventArgs e)
- {
- this.UpdateElapsed();
- }
- internal void Close()
- {
- this._query.ClearAutoSave();
- this.KillIEComExceptionTimer();
- if (this.QueryClosed != null)
- {
- this.QueryClosed(this, EventArgs.Empty);
- }
- }
- internal void CloseCurrentVisualizer()
- {
- this.CloseVisualizer(this.GetSelectedPluginControl());
- }
- internal void CloseVisualizer(PluginControl c)
- {
- if (c != null)
- {
- ToolStripButton button = (this.GetSelectedPluginControl() == c) ? this._pluginWinButtons.FirstOrDefault<ToolStripButton>(b => (b.Tag == c)) : null;
- int num = (button == null) ? -1 : this.tsOutput.Items.IndexOf(button);
- ToolStripButton selectedButton = (num < 1) ? null : (this.tsOutput.Items[num - 1] as ToolStripButton);
- try
- {
- this._pluginWinManager.DisposeControl(c);
- if (selectedButton != null)
- {
- this.SelectOutputPanel(selectedButton, false);
- }
- }
- catch
- {
- }
- }
- }
- internal void CollapseResultsTo(int? depth)
- {
- this._dataBrowser.CollapseTo(depth);
- }
- internal void CompleteParam()
- {
- if (this._editor.get_Document().get_Language() is CSharpSyntaxLanguage)
- {
- this._editor.get_Document().get_Language().ShowIntelliPromptParameterInfo(this._editor);
- }
- }
- internal void CompleteWord()
- {
- if (this._editor.get_Document().get_Language() is CSharpSyntaxLanguage)
- {
- this._editor.get_Document().get_Language().IntelliPromptCompleteWord(this._editor);
- }
- }
- internal void CopyPlain()
- {
- this._editor.CopyPlain();
- }
- private void CreateBrowser()
- {
- this._dataBrowser = new DataResultsWebBrowser();
- this._lambdaBrowser = new ResultsWebBrowser();
- this._ilBrowser = new ResultsWebBrowser();
- this._dataBrowser.PreviewKeyDown += new PreviewKeyDownEventHandler(this._browser_PreviewKeyDown);
- this._dataBrowser.LinqClicked += new EventHandler<LinqClickEventArgs>(this._browser_LinqClicked);
- this._lambdaBrowser.PreviewKeyDown += new PreviewKeyDownEventHandler(this._browser_PreviewKeyDown);
- this._ilBrowser.PreviewKeyDown += new PreviewKeyDownEventHandler(this._browser_PreviewKeyDown);
- this._dataPanel = new BrowserBorder();
- BrowserBorder border = new BrowserBorder {
- BackColor = Control.DefaultBackColor
- };
- this._lambdaPanel = border;
- BrowserBorder border2 = new BrowserBorder {
- BackColor = Control.DefaultBackColor
- };
- this._ilPanel = border2;
- this._dataPanel.Controls.Add(this._dataBrowser);
- this._dataPanel.Dock = DockStyle.Fill;
- this._dataPanel.Hide();
- this._lambdaPanel.Controls.Add(this._lambdaBrowser);
- this._lambdaPanel.Dock = DockStyle.Fill;
- this._lambdaPanel.Hide();
- this._ilPanel.Controls.Add(this._ilBrowser);
- this._ilPanel.Dock = DockStyle.Fill;
- this._ilPanel.Hide();
- this.panOutput.Controls.Add(this._dataPanel);
- this.panOutput.Controls.Add(this._lambdaPanel);
- this.panOutput.Controls.Add(this._ilPanel);
- this._dataBrowser.ObjectForScripting = this;
- }
- private void CreateEditor()
- {
- EventHandler handler = null;
- EventHandler handler2 = null;
- EventHandler handler3 = null;
- this._editor = new QueryEditor();
- this._editor.UriLayer = this._docMan.UriLayer;
- this._editor.WarningsLayer = this._docMan.WarningsLayer;
- this._editor.MainErrorLayer = this._docMan.MainErrorLayer;
- this._editor.StackTraceLayer = this._docMan.StackTraceLayer;
- this._editor.set_Document(this._docMan.Document);
- if (Program.PresentationMode)
- {
- if (handler == null)
- {
- handler = (sender, e) => this.NextQueryRequest(this, EventArgs.Empty);
- }
- this._editor.NextQueryRequest += handler;
- if …
Large files files are truncated, but you can click here to view the full file