11namespace ServiceControlInstaller . Engine . Configuration . ServiceControl
22{
3+ using System ;
4+ using System . Collections . Generic ;
5+ using System . Data . Common ;
36 using System . IO ;
7+ using System . Linq ;
48 using Instances ;
59
610 public class ServiceControlAppConfig : AppConfig
@@ -12,7 +16,7 @@ public ServiceControlAppConfig(IServiceControlInstance instance) : base(Path.Com
1216
1317 protected override void UpdateSettings ( )
1418 {
15- Config . ConnectionStrings . ConnectionStrings . Set ( "NServiceBus/Transport" , details . ConnectionString ) ;
19+ Config . ConnectionStrings . ConnectionStrings . Set ( "NServiceBus/Transport" , UpdateConnectionString ( ) ) ;
1620 var settings = Config . AppSettings . Settings ;
1721 var version = details . Version ;
1822 settings . Set ( ServiceControlSettings . InstanceName , details . InstanceName , version ) ;
@@ -37,6 +41,9 @@ protected override void UpdateSettings()
3741 settings . RemoveIfRetired ( ServiceControlSettings . AuditLogQueue , version ) ;
3842 settings . RemoveIfRetired ( ServiceControlSettings . ForwardAuditMessages , version ) ;
3943 settings . RemoveIfRetired ( ServiceControlSettings . InternalQueueName , version ) ;
44+ settings . RemoveIfRetired ( ServiceControlSettings . RabbitMqManagementApiUrl , version ) ;
45+ settings . RemoveIfRetired ( ServiceControlSettings . RabbitMqManagementApiUsername , version ) ;
46+ settings . RemoveIfRetired ( ServiceControlSettings . RabbitMqManagementApiPassword , version ) ;
4047
4148 RemoveRavenDB35Settings ( settings , version ) ;
4249 }
@@ -62,6 +69,47 @@ public override void SetTransportType(string transportTypeName)
6269 settings . Set ( ServiceControlSettings . TransportType , transportTypeName , version ) ;
6370 }
6471
65- IServiceControlInstance details ;
72+ string UpdateConnectionString ( )
73+ {
74+ var kvpList = new DbConnectionStringBuilder { ConnectionString = details . ConnectionString }
75+ . OfType < KeyValuePair < string , object > > ( )
76+ . Select ( kvp => new KeyValuePair < string , string > ( kvp . Key , kvp . Value . ToString ( ) ) )
77+ . ToList ( ) ;
78+
79+ MigrateRabbitMqManagementApiSettings ( kvpList ) ;
80+
81+ return string . Join ( ";" , kvpList . Select ( kvp => $ "{ kvp . Key } ={ kvp . Value } ") ) ;
82+ }
83+
84+ void MigrateRabbitMqManagementApiSettings ( IList < KeyValuePair < string , string > > connectionStringPairs )
85+ {
86+ if ( ! details . TransportPackage . Name . Contains ( "rabbitmq" , StringComparison . OrdinalIgnoreCase ) ||
87+ connectionStringPairs . Any ( kvp => kvp . Key . Equals ( "ManagementApiUrl" , StringComparison . OrdinalIgnoreCase ) || kvp . Key . Equals ( "ManagementApiUserName" , StringComparison . OrdinalIgnoreCase ) ) )
88+ {
89+ return ;
90+ }
91+
92+ var settings = Config . AppSettings . Settings ;
93+
94+ var legacySetting = settings [ "LicensingComponent/RabbitMQ/ApiUrl" ] ;
95+ if ( legacySetting is not null )
96+ {
97+ connectionStringPairs . Add ( new KeyValuePair < string , string > ( "ManagementApiUrl" , legacySetting . Value ) ) ;
98+ }
99+
100+ legacySetting = settings [ "LicensingComponent/RabbitMQ/UserName" ] ;
101+ if ( legacySetting is not null )
102+ {
103+ connectionStringPairs . Add ( new KeyValuePair < string , string > ( "ManagementApiUserName" , legacySetting . Value ) ) ;
104+ }
105+
106+ legacySetting = settings [ "LicensingComponent/RabbitMQ/Password" ] ;
107+ if ( legacySetting is not null )
108+ {
109+ connectionStringPairs . Add ( new KeyValuePair < string , string > ( "ManagementApiPassword" , legacySetting . Value ) ) ;
110+ }
111+ }
112+
113+ readonly IServiceControlInstance details ;
66114 }
67115}
0 commit comments