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 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); }