/// <inheritdoc/> public override void Execute(UserSettings settings) { switch (settings.AppSide) { case AppSide.Client: IContract client = CreateClient <IContract>(settings); SysConsole.WriteQuestionLine("Single client instance created!"); SysConsole.WriteLine(); new Thread(() => { SysConsole.WriteInfoLine("[ON] Client request-reply method caller"); while (true) { client.Method("User1"); } }).Start(); new Thread(() => { SysConsole.WriteInfoLine("[ON] Client OneWay method caller"); while (true) { client.MethodOneWay("User2"); Thread.Sleep(1000); } }).Start(); Console.ReadKey(); break; case AppSide.Server: var concurrencyMode = QuestionManager.Choose( new[] { ConcurrencyMode.Single, ConcurrencyMode.Multiple }, s => s.ToString(), "Choose service ConcurrencyMode demonstration:"); var host = concurrencyMode == ConcurrencyMode.Multiple ? CreateServiceHost <IContract, ConcurrencyMultiple>(settings) : CreateServiceHost <IContract, ConcurrencySingle>(settings); host.Open(); SysConsole.WriteInfoLine($"Each one contract method executing at least {ThreadSleepTimeSeconds} SECONDS"); QuestionManager.AwaitingClientConnections(); break; default: throw new ArgumentOutOfRangeException(); } }
/// <inheritdoc/> public override void Execute(UserSettings settings) { switch (settings.AppSide) { case AppSide.Client: IContract client = CreateClient <IContract>(settings); int threads = 5; SysConsole.WriteQuestionLine("Single client instance created!"); SysConsole.WriteQuestionLine($"{threads} thread gonna calling this client."); SysConsole.WriteQuestionLine($"Expected {threads} concurrent executions.", 1); for (int i = 0; i < threads; i++) { var localId = i; new Thread( () => { SysConsole.WriteInfoLine("[ON] Client Request-Reply method caller"); while (true) { client.Method($"User{localId + 1}"); } }).Start(); } Console.ReadKey(); break; case AppSide.Server: var host = CreateServiceHost <IContract, ConcurrencyMultiple>(settings); host.Open(); SysConsole.WriteInfoLine($"Each one contract method process time at least {ThreadSleepTimeSeconds} SECONDS"); QuestionManager.AwaitingClientConnections(); break; default: throw new ArgumentOutOfRangeException(); } }
private void ProcessBroadcast(string clientId, BroadcastMessage broadcast) { SysConsole.WriteInfoLine($"CID [{clientId}] Data [{broadcast.Data}]"); }
private void ProcessPersonal(string clientId, PersonalMessage personal) { SysConsole.WriteInfoLine($"CID [{clientId}] Data [{personal.Data}]"); }