From 5f8587adeae23d71d3bb2439011cd2ff05de431c Mon Sep 17 00:00:00 2001 From: Tomasz Masternak Date: Thu, 8 Nov 2018 12:49:09 +0100 Subject: [PATCH] detect existing sp instance port --- .../CustomAction.cs | 50 ++++++++++++++++++- .../ServicePulse.Install.CustomActions.csproj | 4 +- src/Setup/ServicePulse.aip | 10 ++-- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/ServicePulse.Install.CustomActions/CustomAction.cs b/src/ServicePulse.Install.CustomActions/CustomAction.cs index 8030d2a857..677c33000b 100644 --- a/src/ServicePulse.Install.CustomActions/CustomAction.cs +++ b/src/ServicePulse.Install.CustomActions/CustomAction.cs @@ -1,4 +1,6 @@ -namespace ServicePulse.Install.CustomActions +using System.Management; + +namespace ServicePulse.Install.CustomActions { using System; using System.Diagnostics; @@ -168,7 +170,51 @@ public static ActionResult CheckPulsePort(Session session) Log(session, "End custom action CheckPulsePort"); } } - + + [CustomAction] + public static ActionResult DetectExistingPulseInstancePort(Session session) + { + try + { + Log(session, "Start custom action DetectExistingPulseInstancePort"); + + var managementClass = new ManagementClass("Win32_Service"); + + foreach (var wmiService in managementClass.GetInstances()) + { + if (wmiService["Name"].ToString() == "Particular.ServicePulse") + { + var pathName = wmiService["PathName"].ToString(); + + var match = Regex.Match(pathName, @".*--url=""(?.+)"".*"); + var serviceUrlGroup = match.Groups["serviceurl"]; + + if (serviceUrlGroup.Success) + { + var url = serviceUrlGroup.Value; + + if (Uri.TryCreate(url, UriKind.Absolute, out var uri)) + { + var port = uri.Port; + + session.Set("INST_PORT_PULSE", port.ToString()); + } + } + } + } + } + catch (Exception ex) + { + Log(session, ex.ToString()); + } + finally + { + Log(session, "End custom action DetectExistingPulseInstancePort"); + } + + return ActionResult.Success; + } + [CustomAction] public static ActionResult ReadServiceControlUrlFromConfigJS(Session session) { diff --git a/src/ServicePulse.Install.CustomActions/ServicePulse.Install.CustomActions.csproj b/src/ServicePulse.Install.CustomActions/ServicePulse.Install.CustomActions.csproj index aeb8e985d4..c7cdcd09c1 100644 --- a/src/ServicePulse.Install.CustomActions/ServicePulse.Install.CustomActions.csproj +++ b/src/ServicePulse.Install.CustomActions/ServicePulse.Install.CustomActions.csproj @@ -40,7 +40,8 @@ 4 - + + @@ -48,6 +49,7 @@ + diff --git a/src/Setup/ServicePulse.aip b/src/Setup/ServicePulse.aip index d20206434c..655cec4974 100644 --- a/src/Setup/ServicePulse.aip +++ b/src/Setup/ServicePulse.aip @@ -360,13 +360,13 @@ - + - + - - + + @@ -384,6 +384,7 @@ + @@ -428,6 +429,7 @@ +