/// <summary> /// Main entry point. /// </summary> /// <param name="args"></param> public static void Main(string[] args) { // make the server HttpServer server = new HttpServer(); // parse the args FlagParser parser = new FlagParser(); try { parser.ParseFlags(ref server, args); server.Initialize(); } catch (Exception e) { Console.WriteLine("ERROR\n\t"+e.Message); } }
static void Main(string[] args) { var s = new HttpServer(80); Console.ReadLine(); }
/// <summary> /// Parses the flags. /// </summary> /// <param name="server">Reference to Server to be modified by args.</param> /// <param name="args">arg list from Main.</param> public void ParseFlags(ref HttpServer server, string[] args) { Dictionary<string, string> usedFlags = new Dictionary<string, string>(); Queue<string> queue = new Queue<string>(args); while (queue.Count > 0) { string current = queue.Dequeue(); if (Flags.ContainsKey(current)) { // Every flag expects a parameter, if there is no strings left to be the parameter // of if the next string is a flag, throw an exception. if (queue.Count == 0 || Flags.ContainsKey(queue.Peek())) { throw new MalformedFlagException("Flag: \"" + current + "\" expects an argument, recieved none"); } else { string next = queue.Dequeue(); Flags[current].Callback(ref server, next); if (usedFlags.ContainsKey(current)) { Console.WriteLine("WARNING! flag: \"" + current + "\" declared multiple times, " + "happily overriding previous value of " + usedFlags[current] + " with " + next + "."); usedFlags.Remove(current); } usedFlags.Add(current, next); } } else { throw new InvalidFlagException(current); } } }