Ejemplo n.º 1
0
        static void SetupWebServer() {
            // TODO: Try multiple ports?
            const int maxTries = 10;
            const int timeOut = 1500;
            var tries = 0;

            var sslPort = Consts.SrvPort;
            var httpPort = Consts.SrvHttpPort;

            using (var pm = new ProcessManager()) {
                var si = new ServerInfo(pm);
                if (!si.SslRegistered())
                    sslPort = 0;
                if (!si.isHttpRegistered)
                    httpPort = 0;
            }

            retry:
            try {
                _webServer = Startup.Start(Consts.SrvAddress, sslPort, httpPort);
            } catch (TargetInvocationException ex) {
                var unwrapped = ex.UnwrapExceptionIfNeeded();
                if (!(unwrapped is HttpListenerException))
                    throw;

                if (tries++ >= maxTries)
                    throw GetCustomException(unwrapped, Consts.SrvPort);
                MainLog.Logger.Write(unwrapped.Format(), LogLevel.Warn);
                Thread.Sleep(timeOut);
                goto retry;
            } catch (HttpListenerException ex) {
                if (tries++ >= maxTries)
                    throw GetCustomException(ex, Consts.SrvPort);
                MainLog.Logger.Write(ex.Format(), LogLevel.Warn);
                Thread.Sleep(timeOut);
                goto retry;
            }
        }
Ejemplo n.º 2
0
 static void HandlePorts() {
     using (var pm = new ProcessManager()) {
         var si = new ServerInfo(pm);
         if (si.AllRegistered())
             return;
         SquirrelUpdater.SetupApiPort(ServerInfo.value, ServerInfo.valueHttp, pm);
         si = new ServerInfo(pm); // to output
     }
 }