Example #1
0
        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;
        }
Example #2
0
        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);
        }