Example #1
0
 public HttpServer(NameValueCollection appSettings, ConnectorService connectorService, EventLog eventLog)
 {
     ConfigSaved       = false;
     FlashMessage      = "";
     AppSettings       = appSettings;
     _port             = int.Parse(appSettings["ConfigurationPort"]);
     _connectorService = connectorService;
     _configPage       = new ConfigPage(this);
     _statusPage       = new StatusPage(this);
     Logger            = eventLog;
 }
Example #2
0
        static int Main(string[] args)
        {
            bool install   = false,
                 uninstall = false,
                 console   = false,
                 rethrow   = false;

            try
            {
                foreach (string arg in args)
                {
                    switch (arg)
                    {
                    case "-i":
                    case "-install":
                        install = true;
                        break;

                    case "-u":
                    case "-uninstall":
                        uninstall = true;
                        break;

                    case "-c":
                    case "-console":
                        console = true;
                        break;

                    case "-t":
                        var x = new AmqpRegistrationParams();
                        Console.WriteLine(JsonConvert.SerializeObject(x));
                        return(0);

                    default:
                        Console.Error.WriteLine
                            ("Argument not expected: " + arg);
                        break;
                    }
                }

                if (uninstall)
                {
                    Install(true, args);
                }
                if (install)
                {
                    Install(false, args);
                }
                if (console)
                {
                    using (var process = new ConnectorService())
                    {
                        Console.WriteLine("Starting...");
                        process.Startup();
                        Console.WriteLine("System running; press any key to stop");
                        Console.ReadKey(true);
                        process.Shutdown();
                        Console.WriteLine("System stopped");
                    }
                }
                else if (!(install || uninstall))
                {
                    rethrow = true; // so that windows sees error...
                    ServiceBase[] services =
                    { new ConnectorService() };
                    ServiceBase.Run(services);
                    rethrow = false;
                }
                return(0);
            }
            catch (Exception ex)
            {
                if (rethrow)
                {
                    throw;
                }
                Console.Error.WriteLine(ex.Message);
                return(-1);
            }
        }