예제 #1
0
파일: TestForm.cs 프로젝트: jdruin/F5Eagle
        ///////////////////////////////////////////////////////////////////////

        public void AsyncDispose()
        {
            CheckDisposed();

            if (CommonOps.IsValidHandle(CommonOps.GetHandle(this))) // HACK: Remove?
            {
                BeginInvoke(new SimpleDelegate(Dispose));
            }
        }
예제 #2
0
파일: TestForm.cs 프로젝트: jdruin/F5Eagle
        ///////////////////////////////////////////////////////////////////////

        private void btnCancel_Click(
            object sender,
            EventArgs e
            )
        {
            ReturnCode code;
            Result     error = null;

            code = Engine.CancelEvaluate(
                interpreter, null, CancelFlags.UnwindAndNotify, ref error);

            if (code != ReturnCode.Ok)
            {
                CommonOps.Complain(code, error);
            }
        }
예제 #3
0
파일: TestForm.cs 프로젝트: jdruin/F5Eagle
        ///////////////////////////////////////////////////////////////////////

        #region Form Event Handlers
        private void TestForm_KeyDown(
            object sender,
            KeyEventArgs e
            )
        {
            //
            // NOTE: The keystroke CTRL-F5 will open the host window
            //       for the script engine.
            //
            if (!e.Shift && e.Control && !e.Alt && (e.KeyCode == Keys.F5))
            {
                ReturnCode code;
                Result     error = null;

                code = Test.StartupInteractiveLoopThread(ref error);

                if (code != ReturnCode.Ok)
                {
                    CommonOps.Complain(code, error);
                }
            }
        }
예제 #4
0
파일: TestForm.cs 프로젝트: jdruin/F5Eagle
        ///////////////////////////////////////////////////////////////////////

        #region Control Event Handlers
        private void btnRun_Click(
            object sender,
            EventArgs e
            )
        {
            EnableControls(false);

            ReturnCode code;

            ScriptFlags scriptFlags = ScriptFlags.UserRequiredFile;
            IClientData clientData  = ClientData.Empty;

            Result result = null;

            code = interpreter.GetScript(
                CommonOps.ProgressScriptName, ref scriptFlags, ref clientData,
                ref result);

            if (code == ReturnCode.Ok)
            {
                string text = result;

                if (Utility.HasFlags(scriptFlags, ScriptFlags.File, true))
                {
                    code = Engine.ReadScriptFile(
                        interpreter, text, ref text, ref result);
                }

                if (code == ReturnCode.Ok)
                {
                    code = interpreter.SetArguments(
                        new StringList(arguments), ref result);

                    if (code == ReturnCode.Ok)
                    {
                        code = interpreter.QueueScript(
                            Utility.GetUtcNow(), text, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            //
                            // NOTE: Set the internal script (for tracking
                            //       purposes) to the script we just queued.
                            //
                            script = result;

#if !DAEMON
                            //
                            // NOTE: Start asynchronously processing queued
                            //       events in the interpreter until the queue
                            //       is empty if we are already processing
                            //       events due to being in dedicated daemon
                            //       mode (i.e. if DAEMON is defined).
                            //
                            /* IGNORED */
                            Engine.QueueWorkItem(
                                interpreter, AsyncProcessEvents, false);
#endif
                        }
                    }
                }
            }

            if (code != ReturnCode.Ok)
            {
                CommonOps.Complain(code, result);
            }
        }
예제 #5
0
        private void fillDGV()
        {
            List <MSO_Model> msoList = ScheduleDatabaseClassLibrary.GlobalConfig.Connection.GenericGetAll <MSO_Model>("tblMSO", "MSO");

            CommonOps.MakeMSO_StatusList(msoList, dgvMSO);
        }
예제 #6
0
 private void btnChange_Click(object sender, EventArgs e)
 {
     CommonOps.ToggleMSO_ActiveStatus(dgvMSO);
 }
예제 #7
0
파일: Report.cs 프로젝트: jdruin/F5Eagle
        ///////////////////////////////////////////////////////////////////////

        #region IExecute Members
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            if (interpreter == null)
            {
                result = "invalid interpreter";
                return(ReturnCode.Error);
            }

            if (arguments == null)
            {
                result = "invalid argument list";
                return(ReturnCode.Error);
            }

            if (arguments.Count < 2)
            {
                result = String.Format(
                    "wrong # args: should be \"{0} option ?arg ...?\"",
                    this.Name);

                return(ReturnCode.Error);
            }

            ReturnCode code;
            string     subCommand = arguments[1];
            bool       tried      = false;

            code = Utility.TryExecuteSubCommandFromEnsemble(
                interpreter, this, clientData, arguments, true,
                false, ref subCommand, ref tried, ref result);

            if ((code == ReturnCode.Ok) && !tried)
            {
                switch (subCommand)
                {
                case "alert":
                {
                    if (arguments.Count == 3)
                    {
                        result = CommonOps.Complain(arguments[2]);
                        code   = ReturnCode.Ok;
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} string\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "append":
                {
                    if (arguments.Count == 3)
                    {
                        _Forms.TestForm form = _Shell.Test.mainForm;

                        if (form != null)
                        {
                            /* NO RESULT */
                            form.AsyncAppendStatusText(arguments[2],
                                                       true);

                            result = String.Empty;
                            code   = ReturnCode.Ok;
                        }
                        else
                        {
                            result = "invalid main form";
                            code   = ReturnCode.Error;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} string\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "clear":
                {
                    if (arguments.Count == 2)
                    {
                        _Forms.TestForm form = _Shell.Test.mainForm;

                        if (form != null)
                        {
                            /* NO RESULT */
                            form.AsyncClearTestItems();

                            /* NO RESULT */
                            form.AsyncClearStatusText();

                            result = String.Empty;
                            code   = ReturnCode.Ok;
                        }
                        else
                        {
                            result = "invalid main form";
                            code   = ReturnCode.Error;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1}\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "progress":
                {
                    if (arguments.Count == 3)
                    {
                        int value = 0;

                        code = Value.GetInteger2(
                            (IGetValue)arguments[2], ValueFlags.AnyInteger,
                            interpreter.CultureInfo, ref value, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            _Forms.TestForm form = _Shell.Test.mainForm;

                            if (form != null)
                            {
                                /* NO RESULT */
                                form.AsyncSetProgressValue(value);

                                result = String.Empty;
                                code   = ReturnCode.Ok;
                            }
                            else
                            {
                                result = "invalid main form";
                                code   = ReturnCode.Error;
                            }
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} value\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "result":
                {
                    if (arguments.Count == 4)
                    {
                        object enumValue = Utility.TryParseEnum(
                            typeof(TestResult), arguments[3],
                            true, true);

                        if (enumValue is TestResult)
                        {
                            TestResult      testResult = (TestResult)enumValue;
                            _Forms.TestForm form       = _Shell.Test.mainForm;

                            if (form != null)
                            {
                                /* NO RESULT */
                                form.AsyncAddTestItem(String.Format(
                                                          "{0}{1}{2}", arguments[2],
                                                          Characters.HorizontalTab,
                                                          testResult.ToString().ToUpper()));

                                result = String.Empty;
                                code   = ReturnCode.Ok;
                            }
                            else
                            {
                                result = "invalid main form";
                                code   = ReturnCode.Error;
                            }
                        }
                        else
                        {
                            result = Utility.BadValue(
                                null, "test result", arguments[3],
                                Enum.GetNames(typeof(TestResult)),
                                null, null);

                            code = ReturnCode.Error;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} name result\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "send":
                {
                    if (arguments.Count >= 3)
                    {
                        OptionDictionary options = new OptionDictionary(
                            new IOption[] {
                                new Option(null, OptionFlags.None, 1,
                                           Index.Invalid, "-asynchronous", null),
                                new Option(null,
                                           OptionFlags.MustHaveIntegerValue,
                                           1, Index.Invalid, "-timeout", null),
                                new Option(null, OptionFlags.None,
                                           Index.Invalid, Index.Invalid,
                                           Option.EndOfOptions, null)
                            });

                        int argumentIndex = Index.Invalid;

                        code = interpreter.GetOptions(
                            options, arguments, 0, 2, Index.Invalid,
                            true, ref argumentIndex, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            if ((argumentIndex != Index.Invalid) &&
                                ((argumentIndex + 1) == arguments.Count))
                            {
                                bool asynchronous = false;

                                if (options.IsPresent("-asynchronous"))
                                {
                                    asynchronous = true;
                                }

                                Variant value   = null;
                                int     timeout = _Timeout.Infinite;

                                if (options.IsPresent("-timeout", ref value))
                                {
                                    timeout = (int)value.Value;
                                }

                                _Forms.TestForm form = _Shell.Test.mainForm;

                                if (form != null)
                                {
                                    if (asynchronous)
                                    {
                                        /* NO RESULT */
                                        form.AsyncEvaluateScript(
                                            arguments[argumentIndex], null);
                                    }
                                    else
                                    {
                                        result = Utility.CreateSynchronizedResult(null);

                                        /* NO RESULT */
                                        form.AsyncEvaluateScript(
                                            arguments[argumentIndex], result);

                                        if (Utility.WaitSynchronizedResult(result, timeout))
                                        {
                                            if (Utility.GetSynchronizedResult(result, ref code,
                                                                              ref result, ref result) != ReturnCode.Ok)
                                            {
                                                code = ReturnCode.Error;
                                            }
                                        }
                                        else
                                        {
                                            result = String.Format(
                                                "timeout, {0} milliseconds",
                                                timeout);

                                            code = ReturnCode.Error;
                                        }
                                    }
                                }
                                else
                                {
                                    result = "invalid main form";
                                    code   = ReturnCode.Error;
                                }
                            }
                            else
                            {
                                if ((argumentIndex != Index.Invalid) &&
                                    Option.LooksLikeOption(arguments[argumentIndex]))
                                {
                                    result = OptionDictionary.BadOption(
                                        options, arguments[argumentIndex]);
                                }
                                else
                                {
                                    result = String.Format(
                                        "wrong # args: should be \"{0} {1} ?options? script\"",
                                        this.Name, subCommand);
                                }

                                code = ReturnCode.Error;
                            }
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} ?options? script\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                default:
                {
                    result = Utility.BadSubCommand(
                        interpreter, null, null, subCommand, this, null, null);

                    code = ReturnCode.Error;
                    break;
                }
                }
            }

            return(code);
        }
예제 #8
0
        static void Main(string[] args)
        {
            string command;
            string fileName;

            int parallelFactor = ConfigHelper.ParallelFactor;

            var sw = new Stopwatch();

            sw.Start();

            if (args.Length == 4)
            {
                command  = args[0];
                fileName = args[1];
                var containerName = args[2];
                var blobName      = args[3];
                var azureOps      = new AzureOps();

                switch (command)
                {
                case "upload":
                    var bytesUploaded = azureOps.UploadFile(containerName, blobName, fileName, parallelFactor);
                    Console.WriteLine("Uploaded {0} bytes", bytesUploaded);
                    break;

                case "download":
                    var bytesDownloaded = azureOps.DownloadBlob(containerName, blobName, fileName, parallelFactor);
                    Console.WriteLine("Downloaded {0} bytes", bytesDownloaded);
                    break;

                case "estimate":
                    var estimate = azureOps.CalculateDeltaSize(containerName, blobName, fileName);
                    Console.WriteLine(string.Format("Estimate to upload {0} bytes", estimate));
                    break;

                default:
                    ShowExamples();
                    break;
                }
            }
            else if (args.Length == 3)
            {
                command  = args[0];
                fileName = args[1];
                var localSigPath = args[2];
                var azureOps     = new AzureOps();

                switch (command)
                {
                case "estimatelocal":
                    var estimatelocal = azureOps.CalculateDeltaSizeFromLocalSig(localSigPath, fileName);
                    Console.WriteLine(string.Format("Estimate to upload {0} bytes", estimatelocal));
                    break;

                case "createdeltasig":
                    var sig = azureOps.GenerateDeltaSigFromLocalResources(localSigPath, fileName);

                    var sigFileName = fileName + ".sig";
                    using (Stream s = new FileStream(sigFileName, FileMode.Create))
                    {
                        SerializationHelper.WriteBinarySizedBasedSignature(sig, s);
                    }
                    break;

                case "showblocklist":

                    azureOps.GetBlockListInfo(args[1], args[2]);
                    break;

                case "defrag":
                    azureOps.DefragBlob(args[1], args[2]);
                    break;


                default:
                    ShowExamples();
                    break;
                }
            }
            else
            if (args.Length == 2)
            {
                command  = args[0];
                fileName = args[1];
                var azureOps = new AzureOps();
                switch (command)
                {
                case "createsig":
                    var sig = CommonOps.CreateSignatureForLocalFile(fileName);

                    var sigFileName = fileName + ".sig";
                    using (Stream s = new FileStream(sigFileName, FileMode.Create))
                    {
                        SerializationHelper.WriteBinarySizedBasedSignature(sig, s);
                    }

                    break;

                case "showsig":
                    using (var fs = new FileStream(fileName, FileMode.Open))
                    {
                        var loadedSig = SerializationHelper.ReadSizeBasedBinarySignature(fs);

                        foreach (var sigSize in loadedSig.Signatures)
                        {
                            foreach (var s in sigSize.Value.SignatureList.OrderBy(s => s.Offset))
                            {
                                Console.WriteLine(string.Format("{0}:{1}", s.Offset, s.Size));
                            }
                        }
                    }
                    break;

                case "defraglocal":
                    azureOps.DefragBlob(args[1]);
                    break;

                default:
                    ShowExamples();
                    break;
                }
            }
            else
            {
                ShowExamples();
            }

            sw.Stop();
            Console.WriteLine("Took {0}s", (double)sw.ElapsedMilliseconds / 1000.0);
        }
예제 #9
0
        [STAThread()] /* WinForms */
        private static int Main(string[] args)
        {
            #region Shell Debugging Support (Optional)
            //
            // NOTE: Pause for them to attach a debugger, if requested.
            //       This cannot be done inside the Interpreter class
            //       because they may want to debug its initializers.
            //
            if (Environment.GetEnvironmentVariable(EnvVars.Break) != null)
            {
                //
                // NOTE: Prevent further breaks into the debugger.
                //
                Environment.SetEnvironmentVariable(EnvVars.Break, null);

#if CONSOLE
                //
                // NOTE: Display the prompt and then wait for the user to
                //       press a key.
                //
                Console.WriteLine(String.Format(
                                      _Constants.Prompt.Debugger, GetProcessId()));

                try
                {
                    Console.ReadKey(true);        /* throw */
                }
                catch (InvalidOperationException) // Console.ReadKey
                {
                    // do nothing.
                }
#endif

                Debugger.Break(); /* throw */
            }
            #endregion

            ///////////////////////////////////////////////////////////////////

            #region Interpreter Creation Flags (Optional)
            //
            // NOTE: Start with default shell flags.
            //
            CreateFlags flags = CreateFlags.ShellUse;

#if CONSOLE
            //
            // NOTE: The console is enabled and we are going to use our custom
            //       host which inherits from it; therefore, prevent a default
            //       host from being created for the interpreter.
            //
            flags |= CreateFlags.NoHost;
#endif

            //
            // NOTE: Get the effective interpreter creation flags for the shell
            //       from the environment, etc.
            //
            flags = Interpreter.GetStartupCreateFlags(
                args, flags, OptionOriginFlags.Shell, true, true);
            #endregion

            ///////////////////////////////////////////////////////////////////

            //
            // NOTE: We need a return code and result variable now (in case
            //       querying the interpreter library path fails).
            //
            ReturnCode code   = ReturnCode.Ok;
            Result     result = null;

            ///////////////////////////////////////////////////////////////////

            #region Interpreter Pre-Initialize Text (Optional)
            //
            // NOTE: Start with the default pre-initialize text.
            //
            string text = null;

            //
            // NOTE: Get the effective interpreter pre-initialize text for the
            //       shell from the environment, etc.
            //
            if (code == ReturnCode.Ok)
            {
                code = Interpreter.GetStartupPreInitializeText(
                    args, flags, OptionOriginFlags.Shell, true,
                    true, ref text, ref result);
            }
            #endregion

            ///////////////////////////////////////////////////////////////////

            #region Interpreter Library Path (Optional)
            //
            // NOTE: Start with the default library path.
            //
            string libraryPath = null;

            //
            // NOTE: Get the effective interpreter library path for the shell
            //       from the environment, etc.
            //
            if (code == ReturnCode.Ok)
            {
                code = Interpreter.GetStartupLibraryPath(
                    args, flags, OptionOriginFlags.Shell, true,
                    true, ref libraryPath, ref result);
            }
            #endregion

            ///////////////////////////////////////////////////////////////////

            if (code == ReturnCode.Ok)
            {
                //
                // NOTE: Create an interpreter now inside of a using block so
                //       that we can be relatively sure it will be finalized
                //       on this thread.
                //
                using (interpreter = Interpreter.Create(
                           args, flags, text, libraryPath, ref result))
                {
                    //
                    // NOTE: Make sure the interpreter was actually created.
                    //       This can, in theory, be a problem if the
                    //       ThrowOnError flag ends up getting removed somehow
                    //       prior to the call to create the interpreter.
                    //
                    if (interpreter != null)
                    {
                        //
                        // NOTE: Fetch the interpreter host now for error
                        //       reporting purposes.
                        //
                        IHost host = interpreter.Host;

                        ///////////////////////////////////////////////////////

                        #region Interpreter Startup Options (Optional)
                        //
                        // NOTE: By default, initialize the script library for
                        //       the interpreter.
                        //
                        bool initialize = true;

                        //
                        // NOTE: Process all the remaining startup options
                        //       (i.e. the ones that do not modify the
                        //       interpreter creation flags) now.
                        //
                        code = Interpreter.ProcessStartupOptions(
                            interpreter, args, flags, OptionOriginFlags.Shell,
                            true, true, ref initialize, ref result);
                        #endregion

                        ///////////////////////////////////////////////////////

                        if (code == ReturnCode.Ok)
                        {
                            #region Command Line Arguments (Optional)
#if CONSOLE
                            //
                            // NOTE: In debug mode, show the command line
                            //       arguments just as we received them.
                            //
                            if (interpreter.Debug)
                            {
                                Console.WriteLine("The command line is: {0}",
                                                  Utility.BuildCommandLine(args, true));
                            }
#endif

                            //
                            // NOTE: Save the intial arguments for later use.
                            //
                            mainArguments = args;
                            #endregion

                            ///////////////////////////////////////////////////

                            #region Host - Window Preference (Optional)
                            //
                            // NOTE: By default, show the host window?
                            //
                            // TODO: Make this an argument?
                            //
                            bool console = DefaultConsole;

                            //
                            // NOTE: Do we want the initial (auto-created) host
                            //       window to be visible?
                            //
                            if (console)
                            {
                                if (Utility.GetEnvironmentVariable(
                                        EnvVars.NoConsole, true, false) != null)
                                {
#if CONSOLE
                                    Console.WriteLine(
                                        _Constants.Prompt.NoConsole);
#endif

                                    console = false;
                                }
                            }
                            else
                            {
                                if (Utility.GetEnvironmentVariable(
                                        EnvVars.Console, true, false) != null)
                                {
#if CONSOLE
                                    Console.WriteLine(
                                        _Constants.Prompt.Console);
#endif

                                    console = true;
                                }
                            }
                            #endregion

                            ///////////////////////////////////////////////////

                            #region Resource Manager Creation
                            //
                            // NOTE: Create our resource manager (the host and
                            //       the form will both use this).
                            //
                            ResourceManager resourceManager =
                                new ResourceManager(resourceBaseName,
                                                    packageAssembly);
                            #endregion

                            ///////////////////////////////////////////////////

                            #region Host - Custom Creation (Optional)
#if CONSOLE
                            //
                            // NOTE: Create a custom IHost bound to the
                            //       interpreter.
                            //
                            host = new _Hosts.Custom(new HostData(null, null,
                                                                  null, ClientData.Empty, typeof(_Hosts.Custom).Name,
                                                                  interpreter, resourceManager, null,
                                                                  Utility.HasFlags(flags, CreateFlags.UseAttach, true),
                                                                  Utility.HasFlags(flags, CreateFlags.NoColor, true),
                                                                  Utility.HasFlags(flags, CreateFlags.NoTitle, true),
                                                                  Utility.HasFlags(flags, CreateFlags.NoIcon, true),
                                                                  Utility.HasFlags(flags, CreateFlags.NoProfile, true),
                                                                  Utility.HasFlags(flags, CreateFlags.NoCancel, true)));

                            ///////////////////////////////////////////////////

                            interpreter.Host = host;
#endif
                            #endregion

                            ///////////////////////////////////////////////////

                            #region Interpreter Initialization
                            //
                            // NOTE: Attempt to initialize the interpreter.
                            //
                            if (initialize)
                            {
                                code = interpreter.Initialize(false, ref result);
                            }
                            else
                            {
                                code = ReturnCode.Ok;
                            }
                            #endregion

                            ///////////////////////////////////////////////////

                            #region Application-Specific Startup
                            //
                            // NOTE: If initialization failed, no point in
                            //       continuing.
                            //
                            if (code == ReturnCode.Ok)
                            {
                                Application.EnableVisualStyles();
                                Application.SetCompatibleTextRenderingDefault(false);

                                mainForm = new _Forms.TestForm(interpreter, args);

#if NOTIFY || NOTIFY_OBJECT
                                Assembly     assembly     = Assembly.GetExecutingAssembly();
                                AssemblyName assemblyName = assembly.GetName();
                                string       fileName     = assembly.Location;
                                string       typeName     = typeof(_Plugins.TestForm).FullName;
                                Uri          uri          = Utility.GetAssemblyUri(assembly);

                                IPlugin plugin = new _Plugins.TestForm(mainForm,
                                                                       new PluginData(Utility.FormatPluginName(
                                                                                          assemblyName.FullName, typeName), null, null,
                                                                                      ClientData.Empty, PluginFlags.None,
                                                                                      assemblyName.Version, uri,
                                                                                      interpreter.GetAppDomain(), assembly,
                                                                                      assemblyName, fileName, typeName, null, null,
                                                                                      null, null, null, null, resourceManager, null,
                                                                                      0));

                                code = Utility.PrepareStaticPlugin(
                                    plugin, ref result);

                                if (code == ReturnCode.Ok)
                                {
                                    code = interpreter.AddPlugin(
                                        plugin, null, ref pluginToken, ref result);
                                }
#endif
                            }
                            #endregion

                            ///////////////////////////////////////////////////

                            #region Host - Window Startup
                            if (code == ReturnCode.Ok)
                            {
                                if (console)
                                {
                                    //
                                    // NOTE: Create and start the interpreter
                                    //       loop thread.
                                    //
                                    code = StartupInteractiveLoopThread(
                                        ref result);
                                }
                                else if (host.IsOpen())
                                {
                                    //
                                    // NOTE: Close the initial host window.
                                    //
                                    code = host.Close(ref result);
                                }
                            }
                            #endregion

                            ///////////////////////////////////////////////////

                            if (code == ReturnCode.Ok)
                            {
                                #region WinForms Specific
                                //
                                // NOTE: Show the primary user interface form
                                //       for the application.
                                //
                                Application.Run(mainForm);
                                #endregion

                                ///////////////////////////////////////////////

                                #region Host - Window Shutdown
                                //
                                // NOTE: If there is an interactive loop thread,
                                //       we do not want to exit until it is no
                                //       longer running.
                                //
                                if (interactiveLoopThread != null)
                                {
                                    interactiveLoopThread.Join();
                                }
                                #endregion
                            }

                            ///////////////////////////////////////////////////

                            #region Startup Error Handling
                            //
                            // NOTE: Was there any kind of failure above?
                            //
                            if (code != ReturnCode.Ok)
                            {
                                #region WinForms Specific Code
                                if (mainForm != null)
                                {
                                    mainForm.Dispose();
                                    mainForm = null;
                                }
                                #endregion

                                ///////////////////////////////////////////////

                                if (host != null)
                                {
                                    host.WriteResultLine(
                                        code, result, interpreter.ErrorLine);
                                }

                                CommonOps.Complain(code, result);

                                exitCode = Utility.ReturnCodeToExitCode(
                                    code, true);
                            }
                            #endregion
                        }
                        else
                        {
                            if (host != null)
                            {
                                host.WriteResultLine(code, result);
                            }

                            exitCode = Utility.ReturnCodeToExitCode(
                                code, true);
                        }
                    }
                    else
                    {
#if CONSOLE
                        //
                        // NOTE: Creation of the interpreter failed.
                        //
                        Console.WriteLine(Utility.FormatResult(
                                              ReturnCode.Error, result));
#endif

                        exitCode = Utility.FailureExitCode();
                    }
                }
            }
            else
            {
#if CONSOLE
                //
                // NOTE: Querying the interpreter library path failed.
                //
                Console.WriteLine(Utility.FormatResult(code, result));
#endif

                exitCode = Utility.ReturnCodeToExitCode(code, true);
            }

            return((int)exitCode);
        }