private bool Command(CommandModel cmd) { bool handled = false; if (cmd.IsCommand) { switch (cmd.Command.ToLower()) { case "help": CommandHelp(cmd); break; case "window": CommandWindow(cmd); handled = true; break; case "exit": Frontend.Quit(); handled = true; break; case "gc": #if LOG4NET _Logger.Debug("GC.Collect()"); #endif var msg = new MessageBuilder(). AppendEventPrefix(). AppendText("GCing..."). ToMessage(); cmd.FrontendManager.AddMessageToChat(cmd.Chat, msg); GC.Collect(); handled = true; break; case "generate_messages": CommandGenerateMessages(cmd); handled = true; break; } } return(handled); }
public static void Main(string[] args) { #if LOG4NET // initialize log level log4net.Repository.ILoggerRepository repo = log4net.LogManager.GetRepository(); repo.Threshold = log4net.Core.Level.Error; #endif bool debug = false; bool listEngines = false; string engine = "local"; InitLocale(); OptionSet parser = new OptionSet(); parser.Add( "d|debug", _("Enable debug output"), delegate(string value) { debug = true; } ); parser.Add( "e|engine=", _("Engine to connect to"), delegate(string value) { engine = value; } ); parser.Add( "l|list-engines", _("List available engines"), delegate(string value) { listEngines = true; } ); parser.Add( "h|help", _("Show this help"), delegate(string value) { Console.WriteLine(_("Usage: smuxi-frontend-stfl [options]")); Console.WriteLine(); Console.WriteLine(_("Options:")); parser.WriteOptionDescriptions(Console.Out); Environment.Exit(0); } ); parser.Add( "<>", delegate(string value) { throw new OptionException( String.Format( _("Unknown option: '{0}'"), value ), value ); } ); try { parser.Parse(args); #if LOG4NET if (debug) { repo.Threshold = log4net.Core.Level.Debug; } #endif } catch (OptionException ex) { Console.Error.WriteLine(_("Command line error: {0}"), ex.Message); Environment.Exit(1); } if (listEngines) { Console.WriteLine(_("Available Engines:")); var config = new FrontendConfig(Frontend.UIName); config.Load(); foreach (var entry in (string[])config["Engines/Engines"]) { Console.WriteLine("\t{0}", entry); } return; } if ((Environment.OSVersion.Platform == PlatformID.Unix) || (Environment.OSVersion.Platform == PlatformID.MacOSX)) { // Register shutdown handlers #if LOG4NET _Logger.Info("Registering signal handlers"); #endif UnixSignal[] shutdown_signals = { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGTERM), }; Thread signal_thread = new Thread(() => { var index = UnixSignal.WaitAny(shutdown_signals); #if LOG4NET _Logger.Info("Caught signal " + shutdown_signals[index].Signum.ToString() + ", shutting down"); #endif Frontend.Quit(); }); signal_thread.Start(); } try { Frontend.Init(engine); } catch (Exception e) { #if LOG4NET _Logger.Fatal(e); #endif if (SysDiag.Debugger.IsAttached) { throw; } } }