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