private void ExecutorFinished(ErrorList messages, TimeSpan elapsedTime) { // Stop animation & update controls _workingAnimation.Visible = false; FExecuteLineMenuItem.Enabled = true; FExecuteMenuItem.Enabled = true; FExecuteButton.Enabled = true; FCancelExecuteMenuItem.Enabled = false; FCancelExecuteButton.Enabled = false; // Handler Error/Warnings ProcessErrors(messages); if (ScriptExecutionUtility.ContainsError(messages)) { SetStatus(Strings.ScriptFailed); } else { SetStatus(Strings.ScriptSuccessful); } // Handle execution time _executionTimeStatus.Text = elapsedTime.ToString(); _executor = null; }
private void ExecuteAsync() { try { ErrorList errors = null; TimeSpan elapsed = TimeSpan.Zero; try { ScriptExecutionUtility.ExecuteScript ( _process, _script, ScriptExecuteOption.All, out errors, out elapsed, (AStatistics, AResults) => Session.SafelyInvoke ( new ReportScriptProgressHandler(AsyncProgress), new object[] { AStatistics, AResults } ), _locator ); } finally { Session.SafelyInvoke(new ExecuteFinishedHandler(AsyncFinish), new object[] { errors, elapsed }); } } catch { // Don't allow exceptions to go unhandled... the framework will abort the application } }
public void Prepare() { _resultPanel.Clear(); PrepareForExecute(); var result = new StringBuilder(); var errors = new ErrorList(); try { using (var statusForm = new StatusForm(Strings.ProcessingQuery)) { bool attemptExecute = true; try { DateTime startTime = DateTime.Now; try { IServerScript script; IServerProcess process = DataSession.ServerSession.StartProcess( new ProcessInfo(DataSession.ServerSession.SessionInfo)); try { script = process.PrepareScript(GetTextToExecute()); try { if (ScriptExecutionUtility.ConvertParserErrors(script.Messages, errors)) { foreach (IServerBatch batch in script.Batches) { if (batch.IsExpression()) { IServerExpressionPlan plan = batch.PrepareExpression(null); try { attemptExecute &= ScriptExecutionUtility.ConvertCompilerErrors(plan.Messages, errors); if (attemptExecute) { result.AppendFormat ( Strings.PrepareSuccessful, new object[] { plan.PlanStatistics.PrepareTime.ToString(), plan.PlanStatistics.CompileTime.ToString(), plan.PlanStatistics.OptimizeTime.ToString(), plan.PlanStatistics.BindingTime.ToString() } ); result.Append("\r\n"); } } finally { batch.UnprepareExpression(plan); } } else { IServerStatementPlan plan = batch.PrepareStatement(null); try { attemptExecute &= ScriptExecutionUtility.ConvertCompilerErrors(plan.Messages, errors); if (attemptExecute) { result.AppendFormat ( Strings.PrepareSuccessful, new object[] { plan.PlanStatistics.PrepareTime.ToString(), plan.PlanStatistics.CompileTime.ToString(), plan.PlanStatistics.OptimizeTime.ToString(), plan.PlanStatistics.BindingTime.ToString() } ); result.Append("\r\n"); } } finally { batch.UnprepareStatement(plan); } } AppendResultPanel(result.ToString()); result.Length = 0; } } } finally { process.UnprepareScript(script); } } finally { DataSession.ServerSession.StopProcess(process); } } finally { TimeSpan elapsed = DateTime.Now - startTime; _executionTimeStatus.Text = elapsed.ToString(); } if (attemptExecute) { SetStatus(Strings.ScriptPrepareSuccessful); } else { SetStatus(Strings.ScriptPrepareFailed); } } catch (Exception exception) { SetStatus(Strings.ScriptFailed); errors.Add(exception); } } } finally { ProcessErrors(errors); } }
public int Run() { bool hasErrors = true; try { using (DataSession dataphorConnection = new DataSession()) { if (File != null) { using (StreamReader file = new StreamReader(File)) { Script = file.ReadToEnd(); } } if (Script == null) // Script was not in the commandline or specified in a file { Console.WriteLine("\r\nMissing D4 script; include on command line or use /File: switch.\r\n"); Console.WriteLine(CommandLine.Parser.ArgumentsUsage(this.GetType())); return(1); } if (AliasName == String.Empty) { ConnectionAlias alias = new ConnectionAlias(); alias.HostName = Host; alias.InstanceName = Instance; if (Port > 0) { alias.OverridePortNumber = Port; } dataphorConnection.Alias = alias; } else { dataphorConnection.AliasName = AliasName; } if (User != null) { dataphorConnection.SessionInfo.UserID = User; } if (Password != null) { if (PasswordEncrypted == true) { dataphorConnection.SessionInfo.UnstructuredData = Password; } else { dataphorConnection.SessionInfo.Password = Password; } } dataphorConnection.Open(); if (!Quiet) { Console.WriteLine("Executing D4 Script:\r\n{0}\r\n", Script); } ErrorList errors; TimeSpan timeSpan; ScriptExecutionUtility.ExecuteScript ( dataphorConnection.ServerSession, Script, Options, out errors, out timeSpan, delegate(PlanStatistics AStatistics, string AResults) { Console.WriteLine(AResults); }, File == null ? null : new DebugLocator("file:" + Path.GetFullPath(File), 1, 1) ); foreach (Exception exception in errors) { Console.WriteLine(exception.Message); } hasErrors = ScriptExecutionUtility.ContainsError(errors); if (!Quiet) { Console.WriteLine("Status: {0} Total Time: {1}", (hasErrors ? "Failed" : "Succeeded"), timeSpan); } } if (Prompt) { if (!Quiet) { Console.Write("Press any key to continue."); } Console.Read(); } } catch (Exception exception) { Console.WriteLine(exception.Message); } if (hasErrors) { return(1); } return(0); }