Example #1
0
        internal static void Start(string host, ushort port)
        {
            if (string.IsNullOrEmpty(host) || (port == 0))
            {
                ASF.ArchiLogger.LogNullError(nameof(host) + " || " + nameof(port));
                return;
            }

            if (!HttpListener.IsSupported)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningFailedWithError, "!HttpListener.IsSupported"));
                return;
            }

            switch (host)
            {
            case "0.0.0.0":
            case "::":
                // Silently map INADDR_ANY to match HttpListener expectations
                host = "*";
                break;
            }

            string url = "http://" + host + ":" + port + "/";

            HttpListener = new HttpListener {
                IgnoreWriteExceptions = true
            };

            try {
                ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.IPCStarting, url));

                HttpListener.Prefixes.Add(url);
                HttpListener.Start();
            } catch (Exception e) {
                // HttpListener can dispose itself on error, so don't keep it around
                HttpListener = null;
                ASF.ArchiLogger.LogGenericException(e);
                return;
            }

            Logging.InitHistoryLogger();
            Utilities.StartBackgroundFunction(HandleRequests);
            ASF.ArchiLogger.LogGenericInfo(Strings.IPCReady);
        }
Example #2
0
        internal static void Start(HashSet <string> prefixes)
        {
            if ((prefixes == null) || (prefixes.Count == 0))
            {
                ASF.ArchiLogger.LogNullError(nameof(prefixes));
                return;
            }

            if (!HttpListener.IsSupported)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningFailedWithError, "!HttpListener.IsSupported"));
                return;
            }

            HttpListener = new HttpListener {
                IgnoreWriteExceptions = true
            };

            try {
                foreach (string prefix in prefixes)
                {
                    ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.IPCStarting, prefix));
                    HttpListener.Prefixes.Add(prefix);
                }

                HttpListener.Start();
            } catch (Exception e) {
                // HttpListener can dispose itself on error, so don't keep it around
                HttpListener = null;
                ASF.ArchiLogger.LogGenericException(e);
                return;
            }

            Logging.InitHistoryLogger();
            Utilities.StartBackgroundFunction(HandleRequests);
            ASF.ArchiLogger.LogGenericInfo(Strings.IPCReady);
        }