public void ExecuteClrQuery(Client client, LINQPad.Repository r, string assemblyPath, int lineOffset, string[] additionalRefs, bool mta, bool compilationHadWarnings, string queryPath, string queryName, LINQPad.UI.PluginWindowManager pluginWinManager, bool executionTrackingEnabled) { this.IsClrQuery = true; this._client = client; _currentServer = null; this._repository = r; this._assemblyPath = assemblyPath; this._lineOffset = lineOffset; this._additionalRefs = additionalRefs; this._compilationHadWarnings = compilationHadWarnings; this._lastLambdaLength = 0; this._lastSqlLogLength = 0; this._lastResultsLength = 0; this._cacheVersionAtStart = UserCache.CacheVersion; this.PluginWindowManager = pluginWinManager; CurrentQueryAdditionalRefs = this._additionalRefs; Util.Progress = null; Util.CurrentQueryPath = (queryPath == "") ? null : queryPath; Util.CurrentQueryName = queryName; PluginServer.CustomCount = 1; UserCache.ClearSession(); Thread thread = new Thread(() => this.StartQuery(new ClrQueryRunner(this, executionTrackingEnabled))) { IsBackground = true, Name = System.AppDomain.CurrentDomain.FriendlyName }; this._worker = thread; if (!mta) { this._worker.SetApartmentState(ApartmentState.STA); } this._worker.Start(); }
public void ExecuteSqlQuery(QueryLanguage language, LINQPad.Repository repository, string query, string[] refs, Client client, LINQPad.UI.PluginWindowManager pluginWinManager) { QueryRunner runner; this.IsClrQuery = false; Util.Progress = null; this._repository = repository; this._sqlQuery = query; this._client = client; this._additionalRefs = refs; CurrentQueryAdditionalRefs = this._additionalRefs; this.PluginWindowManager = pluginWinManager; if (language == QueryLanguage.ESQL) { runner = new ESqlQueryRunner(this, query); } else { runner = new SqlQueryRunner(this, query); } Thread thread = new Thread(() => this.StartQuery(runner)) { Name = ((language == QueryLanguage.ESQL) ? "E" : "") + "SQL Query Runner", IsBackground = true }; this._worker = thread; this._worker.SetApartmentState(ApartmentState.STA); this._worker.Start(); }
public void Cancel(bool onlyIfRunning, bool killAppDomain) { if (this._executionTrackSignal != null) { try { this._executionTrackSignal.Set(); } catch { } } Thread.MemoryBarrier(); if (!(!this._finishing || this._finished)) { Thread.Sleep(200); } lock (this._statusLocker) { if (this._finished && onlyIfRunning) { return; } this._finishing = true; this._finished = true; this._cancelRequest = true; this._client = null; if (!(((this._worker == null) || !this._worker.IsAlive) ? ((this._uiThread == null) || !this._uiThread.IsAlive) : false)) { this.WorkerThreadAborted = true; } if (this._executionTrackSignal != null) { try { this._executionTrackSignal.Set(); } catch { } } } Thread thread = new Thread(delegate { try { Monitor.TryEnter(this._cancelLocker, 0x1388); this.End(killAppDomain); } catch { } finally { try { Monitor.Exit(this._cancelLocker); } catch { } } }) { IsBackground = true, Name = "Server Cancel" }; thread.Start(); }
public void Dispose() { this._disposed = true; this.EndMessageLoop(); this._client = null; this.PluginWindowManager = null; if (this._executionTrackSignal != null) { try { this._executionTrackSignal.Set(); } catch { } } try { RemotingServices.Disconnect(this); } catch { } }
public void Run(string querySelection, bool compileOnly, QueryCompilationEventArgs lastCompiler, LINQPad.UI.PluginWindowManager winManager) { lock (this._executionLock) { FileWithVersionInfo[] infoArray; FileWithVersionInfo[] infoArray2; if (this.IsRunning) { return; } this.GetAssemblyReferenceMap(out infoArray, out infoArray2); bool flag2 = this.NeedsRefresh(this._lastVolatileRefs, infoArray); bool flag3 = this.NeedsRefresh(this._lastNonvolatileRefs, infoArray2); bool flag4 = (!flag2 && (this._lastVolatileRefs != null)) && (this._lastVolatileRefs.Length > infoArray.Length); this._lastVolatileRefs = infoArray; this._lastNonvolatileRefs = infoArray2; if (flag2 || flag3) { this.PolluteCachedDomain(true); } if (this._client != null) { if ((this._cachedDomainPolluted || Program.FreshAppDomains) || ((!Program.PreserveAppDomains && !this.IsUserCachePresent()) && (((this._loadedAssemblyCount > 40) || (this._cumulativeFootprint > 0x1312d00L)) || this._client.LastWorkerThreadAborted()))) { this._client.Cancel(false, true); this._cachedDomain = null; } this._client.Dispose(); } this._queryStarting = true; this._querySnapshot = this.GetSnapshotForExecution(); if ((querySelection != null) && (this._querySnapshot.QueryKind == QueryLanguage.Program)) { if (querySelection.TrimEnd(new char[0]).EndsWith(";")) { this._querySnapshot.QueryKind = QueryLanguage.Statements; } else if (!(querySelection.Trim().Contains("\n") && querySelection.Contains<char>('{'))) { this._querySnapshot.QueryKind = QueryLanguage.Expression; } } else if (((querySelection != null) && (this._querySnapshot.QueryKind == QueryLanguage.Statements)) && !querySelection.Contains<char>(';')) { this._querySnapshot.QueryKind = QueryLanguage.Expression; } this._client = new Client(this._querySnapshot, querySelection, compileOnly, lastCompiler, new Func<Client, Server>(this.CreateServer), winManager); this._client.QueryCompiled += new EventHandler<QueryCompilationEventArgs>(this._client_QueryCompiled); this._client.QueryCompleted += new EventHandler<QueryStatusEventArgs>(this._client_QueryCompleted); this._client.ReadLineRequested += new EventHandler<ReadLineEventArgs>(this._client_ReadLineRequested); this._client.PluginsReady += new EventHandler(this._client_PluginsReady); this._client.CustomClickComplete += new EventHandler(this._client_CustomClickComplete); if (this.AllowShadow()) { Stopwatch stopwatch = Stopwatch.StartNew(); if (flag2) { this.CreateShadow(); } else if (flag4) { this.UpdateShadow(); } stopwatch.Stop(); } } ThreadPool.QueueUserWorkItem(delegate (object _) { try { base.AutoSave(true); } catch { } }); new Thread(new ThreadStart(this._client.Start)) { IsBackground = true, Name = "Query Starter" }.Start(); this._queryWatch.Reset(); this._queryWatch.Start(); }
internal void ReadLineCompleted(Client client, string text) { lock (this._executionLock) { if (this._client == client) { this._client.ReadLineCompleted(text); } } }
internal Server CreateServer(Client client) { lock (this._executionLock) { if (client != this._client) { return null; } if (!_executeInLocalDomain) { if (this._cachedDomain == null) { this._cachedDomain = this.CreateAppDomain(base.Repository, base.Name); } try { return this.GetServer(); } catch (AppDomainUnloadedException) { this._cachedDomain = this.CreateAppDomain(base.Repository, base.Name); return this.GetServer(); } } return new Server(); } }
public void Cancel(bool onlyIfRunning, bool killAppDomain) { lock (this._executionLock) { if ((this._client != null) && (this.IsRunning || !onlyIfRunning)) { this._queryWatch.Stop(); this._client.Cancel(onlyIfRunning, killAppDomain); if (killAppDomain) { this._client.Dispose(); this._client = null; this._cachedDomain = null; } this._queryStarting = false; } } }
private void ShowReadLinePanel(Client client, string prompt, string defaultValue, string[] options) { this._readLinePanelVisible = true; if (this._readLinePanel == null) { ReadLinePanel panel = new ReadLinePanel { Dock = DockStyle.Bottom }; this._readLinePanel = panel; } this._readLinePanel.EntryMade = delegate (string text) { if (this.QueryRunning) { this.lblStatus.Text = "Executing"; } this.HideReadLinePanel(); this._query.ReadLineCompleted(client, text); }; if (this._readLinePanel.Parent != this) { base.SuspendLayout(); base.Controls.Add(this._readLinePanel); this._readLinePanel.SendToBack(); this.statusStrip.SendToBack(); base.ResumeLayout(); } this.lblStatus.Text = "Awaiting user input"; this._readLinePanel.Go(prompt, defaultValue, options); this.ScrollResults(VerticalScrollAmount.Document, true, true, false); }