Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Debug.WriteLine("Provide path or file that contains the JSON configuration. If file does not exit then default one will be created.");
                return;
            }

            if (!File.Exists(args[0]))
            {
                ProgramConfig defcfg = new ProgramConfig
                {
                    auth_url           = "(required) The HTTP or HTTPS URL to the authentication service.",
                    db_url             = "(required) The HTTP or HTTPS URL to the database service.",
                    port               = 80,
                    web_resources_path = "(required) The path to the web resources to serve.",
                };

                var defcfgfp = File.CreateText(args[1]);
                defcfgfp.Write(JsonConvert.SerializeObject(defcfg, Formatting.Indented));
                defcfgfp.Dispose();

                Debug.WriteLine("Default configuration created at location specified.");
                return;
            }

            var cfgfp = File.OpenText(args[0]);

            var cfg = JsonConvert.DeserializeObject <ProgramConfig>(cfgfp.ReadToEnd());

            cfgfp.Dispose();

            var server_state = new ServerCore(cfg);

            var handlers = new Dictionary <String, SimpleServer <ServerCore> .SimpleHTTPHandler>();

            handlers.Add("/", Handlers.Index);
            handlers.Add("/utility", Handlers.Utility);
            handlers.Add("/get-config", Handlers.GetConfig);

            var server_task = SimpleServer <ServerCore> .Create(
                server_state,
                handlers,
                cfg.port,
                cfg.ssl_cert_path,
                cfg.ssl_cert_pass
                );

            server_task.Wait();
        }
Exemplo n.º 2
0
 public ServerCore(
     ProgramConfig cfg
     )
 {
     this.cfg = cfg;
 }