PowerShellHtmlConsole.PSWrapper.TryExecute C# (CSharp) Method

TryExecute() public method

public TryExecute ( string cmd ) : void
cmd string
return void
        public void TryExecute(string cmd)
        {
            try
            {
                Execute(cmd);
            }
            catch (RuntimeException rte)
            {
                ReportException(rte);
            }
            finally
            {
                _buffers.QueueOutCommand(OutCommand.CreateReadLine(false, null));
            }
        }

Usage Example

        static void Main(string[] args)
        {
            XmlConfigurator.Configure();

            string listenAddress = null;
            string script = null;
            bool help = false;
            var options = new OptionSet
                        {
                            {"listen=", x => listenAddress = x },
                            {"script=", x => script = x },
                            {"h|?|help", x => help = x != null},
                        };

            options.Parse(args);
            if (listenAddress == null || help)
            {
                PrintUsage();
                return;
            }

            var buffers = new InputOutputBuffers();

            Log.Info("Initializing PowerShell");
            var powerShell = new PSWrapper(buffers, () => ExitEvent.Set());

            buffers.RegisterForInCommand((cmd, scope) => powerShell.TryExecute(cmd.TextLine));

            var config = new HttpSelfHostConfiguration(listenAddress);
            config.Services.Insert(typeof(IHttpControllerActivator), 0, new ControllerActivator(buffers));

            config.Routes.MapHttpRoute("session", "session", new { controller = "Session" });
            config.Routes.MapHttpRoute("content", "{contentFile}", new { controller = "Content" });

            var server = new HttpSelfHostServer(config);
            Log.InfoFormat("Staring HTTP listener at {0}", listenAddress);
            server.OpenAsync().Wait();

            if (script != null)
            {
                RunScript(script, powerShell);
            }
            else
            {
                StartInteractivePrompt(buffers);
            }
            Log.InfoFormat("System ready");
            ExitEvent.Wait();
            server.CloseAsync().Wait();

            powerShell.Dispose();
        }
All Usage Examples Of PowerShellHtmlConsole.PSWrapper::TryExecute