static void Main(string[] args) { Messenger.MessageSent += MessengerOnMessageSent; AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; if (args.Length > 0) { try { var idx = 0; foreach (var arg in args.Where(arg => arg.StartsWith("-"))) { switch (arg) { case "-useconfig": case "--useconfig": idx++; LoadSettings(args[idx]); break; default: PrintHelp(); break; case "-setconfig": case "--setconfig": var alias = "Primary"; if (args.Length > idx + 1 && !args[idx + 1].StartsWith("-")) { idx++; alias = args[idx]; } RunConfiguration(alias); break; } idx++; } } catch (Exception e) { PrintHelp(); } } if (LoadedSetting == null) { LoadSettings("Primary"); } //everything should be initialized and ready to go now, time to run our listeners / connect to services var retry = false; do { Telegram.Run().ContinueWith((result) => retry = result.Result); } while (retry); Thread.Sleep(-1); }
private static void MessengerOnMessageSent(object sender, EventArgs e) { var args = (e as MessageSentEventArgs); Telegram.Send(args); }