public PuppetMasterCommunicationService(ConcurrentDictionary <string, List <string> > serversIdByPartition, ConcurrentDictionary <string, string> serverUrls, ConcurrentBag <string> crashedServers, BoolWrapper continueExecution) { ServersIdByPartition = serversIdByPartition; ServerUrls = serverUrls; CrashedServers = crashedServers; ContinueExecution = continueExecution; }
static void Main(string[] args) { if (args.Length != 4) { Console.WriteLine("Usage: Client.exe <host> <port> <script_file> <id>"); return; } if (!int.TryParse(args[1], out int Port)) { Console.WriteLine("Invalid port value"); return; } if (!int.TryParse(args[3], out int id)) { Console.WriteLine("Invalid id"); return; } AppContext.SetSwitch( "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); string host = args[0]; var serverIdsByPartition = new ConcurrentDictionary <string, List <string> >(); var serverUrls = new ConcurrentDictionary <string, string>(); var crashedServers = new ConcurrentBag <string>(); var client = new GSTOREClient(id, serverIdsByPartition, serverUrls, crashedServers); BoolWrapper continueExecution = new BoolWrapper(false); var server = new Grpc.Core.Server { Services = { PuppetMasterClientGrpcService.BindService(new PuppetMasterCommunicationService(serverIdsByPartition, serverUrls, crashedServers, continueExecution)) }, Ports = { new ServerPort(host, Port, ServerCredentials.Insecure) } }; server.Start(); // Lock until information is received lock (continueExecution.WaitForInformationLock) { while (!continueExecution.Value) { Monitor.Wait(continueExecution.WaitForInformationLock); } } try { string line; string filePath = Directory.GetCurrentDirectory() + "\\" + args[2] + ".txt"; Console.WriteLine("File Path: " + filePath); System.IO.StreamReader file = new System.IO.StreamReader(filePath); while ((line = file.ReadLine()) != null) { string[] cmd = line.Split((char[])null, StringSplitOptions.RemoveEmptyEntries); CommandDispatcher(cmd, file, client); } file.Close(); // We need to stay up, in order to respond to status commands by the Puppet Master // Start gRPC server of connection with PM // For now, just wait for user input Console.ReadKey(); } catch (System.IO.FileNotFoundException) { Console.WriteLine("File not found. Exiting..."); } finally { Console.ReadKey(); server.ShutdownAsync().Wait(); } }