public Dictionary <string, string> classesList() { Dictionary <string, string> classes = new Dictionary <string, string>(); foreach (Type type in Assembly.GetCallingAssembly().GetTypes().Where(type => type.IsSubclassOf(this.GetType())).ToList()) { ServiceCommand cmd = (ServiceCommand)Activator.CreateInstance(type); string json = cmd.serialise(); List <string> parts = json.Substring(1, json.Length - 2).Split(',').ToList(); parts.Remove("\"label\":null"); parts.Remove("\"result\":null"); parts = parts.OrderBy(q => q).ToList(); int i = Array.FindIndex(parts.ToArray(), element => element.StartsWith("\"command\":")); if (i > 0) { string c = parts[i]; parts[i] = parts[0]; parts[0] = c; } classes.Add(type.Name, "{" + string.Join(",", parts) + "}"); } return(classes); }
static void Main(string[] args) { bool exit = false; for (int i = 0; i < args.Length; ++i) { switch (args[i]) { case "-token": case "-t": if(i < args.Length - 1) { ++i; accessToken = args[i].ToLower(); } break; case "-tg": case "-tokengen": accessToken = UUID.Random().ToString(); break; case "-l": case "-list": AutomatonCommand atm = new AutomatonCommand(); string[] lines = atm.classesList().Values.ToArray().OrderBy(q => q).ToArray(); File.WriteAllLines("automaton_commands.txt", lines, Encoding.UTF8); ServiceCommand svc = new ServiceCommand(); lines = svc.classesList().Values.ToArray(); File.WriteAllLines("service_commands.txt", lines, Encoding.UTF8); exit = true; break; case "-w": case "-web": webPage = true; break; } } Console.WriteLine("----==[Access Token]==----"); Console.WriteLine(accessToken); Console.WriteLine("--------------------------"); WebServer ws = null; if(!exit){ ws = new WebServer(GetHttpResponse, url); ws.Run(); Console.WriteLine("Starting Service on " + url + ". Press a key to quit."); } string arg; //#if DEBUG /* GridClient test = new GridClient() ; foreach (FieldInfo p in test.Settings.GetType().GetFields()) { if (p.GetValue(test.Settings) != null) { Console.WriteLine("{0} : {1}", p.Name, p.GetValue(test.Settings).ToString()); } } test = null; */ //Process.Start(url); //#endif timer = new Timer(timer_tick, null, 0, 1000); while (!exit) { arg = Console.ReadLine(); if (arg == "exit") exit = true; else if (arg == "help") Console.WriteLine("THIS APPLICATION USES A WEB API, USE IT FUCKWAD."); } if(ws != null)ws.Stop(); foreach (var pair in automatons) { pair.Value.Logout(); } timer.Dispose(); automatons.Clear(); }