11using System ;
22using System . Linq ;
3+ using System . Security . Cryptography ;
4+ using System . Text ;
35using System . Threading . Tasks ;
46using NServiceBus ;
57using Shared ;
@@ -15,21 +17,19 @@ static async Task Main(string[] args)
1517 LoggingUtils . ConfigureLogging ( "Sales" ) ;
1618
1719 var instanceName = args . FirstOrDefault ( ) ;
18- var instanceId = Guid . NewGuid ( ) ;
1920
2021 if ( string . IsNullOrEmpty ( instanceName ) )
2122 {
2223 Console . Title = "Sales" ;
2324
2425 instanceName = "original-instance" ;
25- instanceId = new Guid ( "14A46D23-4874-497B-ABCD-8D6E2488DB25" ) ;
2626 }
2727 else
2828 {
2929 Console . Title = $ "Sales - { instanceName } ";
3030 }
3131
32- Console . WriteLine ( "Using instance-id {0} ", instanceName ) ;
32+ var instanceId = DeterministicGuid . Create ( "Sales ", instanceName ) ;
3333
3434 var endpointConfiguration = new EndpointConfiguration ( "Sales" ) ;
3535 endpointConfiguration . LimitMessageProcessingConcurrencyTo ( 4 ) ;
@@ -94,4 +94,19 @@ static void RunUserInterfaceLoop(SimulationEffects state, string instanceName)
9494 }
9595 }
9696 }
97+
98+ static class DeterministicGuid
99+ {
100+ public static Guid Create ( params object [ ] data )
101+ {
102+ // use MD5 hash to get a 16-byte hash of the string
103+ using ( var provider = new MD5CryptoServiceProvider ( ) )
104+ {
105+ var inputBytes = Encoding . Default . GetBytes ( string . Concat ( data ) ) ;
106+ var hashBytes = provider . ComputeHash ( inputBytes ) ;
107+ // generate a guid from the hash:
108+ return new Guid ( hashBytes ) ;
109+ }
110+ }
111+ }
97112}
0 commit comments