diff --git a/Step.Config/serverConfig.xml b/Step.Config/serverConfig.xml index e9e033b5..94e9d057 100644 --- a/Step.Config/serverConfig.xml +++ b/Step.Config/serverConfig.xml @@ -1,7 +1,7 @@ - 2 + 1 10.69.36.33 8193 diff --git a/Step/App_Start/Startup.cs b/Step/App_Start/Startup.cs index 980d0c76..39b5971e 100644 --- a/Step/App_Start/Startup.cs +++ b/Step/App_Start/Startup.cs @@ -12,7 +12,10 @@ using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Hubs; using Step.Attributes; using Step.Utils; +using static Step.Config.StartupConfig; using System.IO; +using System.Net.NetworkInformation; +using System.Net; [assembly: OwinStartup(typeof(Step.App_Start.Startup))] @@ -53,6 +56,10 @@ namespace Step.App_Start }; app.UseFileServer(options); + if (!ServerPortIsAvailable(ServerConfig.ServerPort)) + { + ExceptionManager.Manage(Constants.ERROR_LEVEL.FATAL, "Server port is already in use by another process"); + } } private void ConfigureWebApiOAuth(IAppBuilder app) @@ -93,5 +100,24 @@ namespace Step.App_Start //}); app.MapSignalR(); } + + private bool ServerPortIsAvailable(int port) + { + bool isAvailable = true; + + IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties(); + IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners(); + + foreach (IPEndPoint endPoint in ipEndPoints) + { + if (endPoint.Port == port) + { + isAvailable = false; + break; + } + } + + return isAvailable; + } } }