private void ClearServer() { try { if (this._server != null) { this._server.Dispose(); } } catch { } this._server = null; }
private void CompileAndRun(DataContextInfo dcInfo) { try { object obj2; QueryCore core; lock ((obj2 = this._locker)) { core = this._query; if ((core == null) || this._cancelRequest) { return; } } if ((dcInfo != null) && (dcInfo.Error != null)) { this.OnQueryCompleted("Connection error", dcInfo.Error); } else { DataContextDriver driver = core.GetDriver(true); if ((driver != null) && (driver.AssembliesToAddError != null)) { this.OnQueryCompleted("Error loading custom driver assemblies", driver.AssembliesToAddError.Message); } else { QueryCompiler c = null; if (((this._lastCompilation != null) && (this._lastCompilation.AssemblyDLL != null)) && File.Exists(this._lastCompilation.AssemblyDLL.FullPath)) { c = this._lastCompilation.Compiler; if (!((((dcInfo != null) || (this._lastCompilation.DataContextDLL == null)) && ((dcInfo == null) || (this._lastCompilation.DataContextDLL != null))) ? (((dcInfo == null) || (this._lastCompilation.DataContextDLL == null)) || (dcInfo.AssemblyPath == this._lastCompilation.DataContextDLL)) : false)) { c = null; } } bool flag2 = false; if (c == null) { this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Compiling; c = QueryCompiler.Create(core, true); lock ((obj2 = this._locker)) { if (this._cancelRequest) { return; } } c.Compile(this._source, core, (dcInfo == null) ? null : dcInfo.AssemblyPath); lock ((obj2 = this._locker)) { if (this._cancelRequest) { return; } if (c.Errors.HasErrors) { this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Finished; this.QueryCompleted = null; this.PluginsReady = null; this.CustomClickComplete = null; } } this.OnQueryCompiled(new QueryCompilationEventArgs(c, (dcInfo == null) ? null : dcInfo.AssemblyPath, this._partialSource)); flag2 = true; } lock ((obj2 = this._locker)) { if ((this._cancelRequest || c.Errors.HasErrors) || this._compileOnly) { this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Finished; return; } } Server server = this._serverGenerator(this); if (server != null) { lock ((obj2 = this._locker)) { if (this._cancelRequest) { return; } if (this._server != server) { this.ClearServer(); } this._server = server; this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Executing; } bool flag7 = c.References.Any<string>(r => r.EndsWith(".winmd", StringComparison.InvariantCultureIgnoreCase)); server.WriteResultsToGrids = core.ToDataGrids; server.ExecuteClrQuery(this, core.Repository, c.OutputFile.FullPath, c.LineOffset, c.References.ToArray<string>(), Program.MTAMode || flag7, flag2 && c.Errors.HasWarnings, core.FilePath, core.Name, this._pluginWinManager, !UserOptionsLive.Instance.ExecutionTrackingDisabled); } } } } catch (Exception exception) { try { this.OnQueryCompleted("Unable to execute query", ""); } catch { } Program.ProcessException(exception); } }
public void Start() { ThreadStart start = null; object obj2; QueryCore core; lock ((obj2 = this._locker)) { core = this._query; if ((core == null) || this._cancelRequest) { return; } if (this._executionProgress != LINQPad.ExecutionModel.ExecutionProgress.Starting) { throw new InvalidOperationException("Cannot call Start twice on Client"); } } if ((core.QueryKind == QueryLanguage.SQL) || (core.QueryKind == QueryLanguage.ESQL)) { if (this._compileOnly) { this.OnQueryCompleted("", ""); } else { lock ((obj2 = this._locker)) { this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.Executing; } Server server = this._serverGenerator(this); lock ((obj2 = this._locker)) { if (this._cancelRequest || (server == null)) { return; } if (this._server != server) { this.ClearServer(); } this._server = server; } server.WriteResultsToGrids = core.ToDataGrids && (core.QueryKind == QueryLanguage.SQL); UniqueStringCollection source = new UniqueStringCollection(new FileNameComparer()); if (core.GetDriver(true) != null) { try { source.AddRange(core.Repository.GetDriverAssemblies()); if (!((core.QueryKind != QueryLanguage.ESQL) || string.IsNullOrEmpty(core.Repository.CustomAssemblyPath))) { source.Add(core.Repository.CustomAssemblyPath); } } catch { } } server.ExecuteSqlQuery(core.QueryKind, core.Repository, this._source, source.ToArray<string>(), this, this._pluginWinManager); } } else if ((core.Repository != null) && core.Repository.DynamicSchema) { lock ((obj2 = this._locker)) { this._executionProgress = LINQPad.ExecutionModel.ExecutionProgress.AwaitingDataContext; } DataContextManager.GetDataContextInfo(core.Repository, new DataContextCallback(this.GotDataContext), SchemaChangeTestMode.None); } else { if (start == null) { start = () => this.CompileAndRun(null); } new Thread(start) { Name = "Query Compiler", IsBackground = true }.Start(); } }
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(); }
private void StartQuery(QueryRunner runner) { object obj2; lock ((obj2 = this._statusLocker)) { if (this._cancelRequest) { return; } } _currentServer = this; this.ServerThread = Thread.CurrentThread; if ((this._repository != null) && this._repository.DriverLoader.IsValid) { this._dataContextDriver = this._repository.DriverLoader.Driver; } if ((this._dataContextDriver is EntityFrameworkDriver) || (this._dataContextDriver is EntityFrameworkDbContextDriver)) { this.InstallDbProviders(this._repository); } lock ((obj2 = this._statusLocker)) { if (this._cancelRequest) { return; } } if (_domainExceptionHandler != null) { System.AppDomain.CurrentDomain.UnhandledException -= _domainExceptionHandler; } System.AppDomain.CurrentDomain.UnhandledException += (_domainExceptionHandler = new UnhandledExceptionEventHandler(this.CurrentDomain_UnhandledException)); try { this.RunQuery(runner); } catch (ThreadAbortException) { } catch (Exception exception) { this.MessageLoopEnded = true; this.PostStatus(this.GetStatusArgs(exception, true, true)); this.PerformCompletionCleanup(true, false); this.PerformFinalCleanup(); } }
public SqlQueryRunner(Server server, string query) : base(server, query) { }
public ClrQueryRunner(Server server, bool executionTrackingEnabled) : base(server) { this._executionTrackingEnabled = executionTrackingEnabled; }