static async Task Main(string[] args) { Console.WriteLine("Enter Server in format URL:Port"); string serverURL = Console.ReadLine(); var channel = GrpcChannel.ForAddress(serverURL); var client = new Workload.WorkloadClient(channel); while (true) { bool inputChecker = true; Console.WriteLine("Enter RFWID: "); int num = -1; string inputRFWID = Console.ReadLine(); while (!int.TryParse(inputRFWID, out num)) { Console.WriteLine("The value must be an integer. Please re-enter RFWID:"); inputRFWID = Console.ReadLine(); } Int32 rfwId = Convert.ToInt32(inputRFWID); string benchmark = ""; while (inputChecker) { Console.WriteLine("Enter BenchmarkType (DvdTesting = 0, DvdTraining = 1, NdBenchTesting = 2, NdBenchTraining = 3): "); benchmark = Console.ReadLine(); if ((benchmark.Equals("0") || benchmark.Equals("1") || benchmark.Equals("2") || benchmark.Equals("3"))) { inputChecker = false; } } inputChecker = true; string workloadMetric = ""; while (inputChecker) { Console.WriteLine("Enter WorkloadMetric (Cpu = 0, NetworkIn = 1, NetworkOut = 2, Memory = 3): "); workloadMetric = Console.ReadLine(); if ((workloadMetric.Equals("0") || workloadMetric.Equals("1") || workloadMetric.Equals("2") || workloadMetric.Equals("3"))) { inputChecker = false; } } inputChecker = true; Console.WriteLine("Enter BatchUnit: "); string inputBatchUnit = Console.ReadLine(); while (!int.TryParse(inputBatchUnit, out num)) { Console.WriteLine("The value must be an integer. Please re-enter BatchUnit:"); inputBatchUnit = Console.ReadLine(); } Int32 batchUnit = Convert.ToInt32(inputBatchUnit); Console.WriteLine("Enter BatchID: "); string inputBatchID = Console.ReadLine(); while (!int.TryParse(inputBatchID, out num)) { Console.WriteLine("The value must be an integer. Please re-enter BatchID:"); inputBatchID = Console.ReadLine(); } Int32 batchId = Convert.ToInt32(inputBatchID); Console.WriteLine("Enter BatchSize: "); string inputBatchSize = Console.ReadLine(); while (!int.TryParse(inputBatchSize, out num)) { Console.WriteLine("The size of the batch must be an integer. Please re-enter the size of the batch:"); inputBatchSize = Console.ReadLine(); } Int32 batchSize = Convert.ToInt32(inputBatchSize); WorkloadRequest workloadRequest = new WorkloadRequest(); workloadRequest.RFWID = rfwId; workloadRequest.BenchmarkType = (WorkloadRequest.Types.BenchmarkType)Enum.Parse(typeof(WorkloadRequest.Types.BenchmarkType), benchmark); workloadRequest.WorkloadMetric = (WorkloadRequest.Types.WorkloadMetric)Enum.Parse(typeof(WorkloadRequest.Types.WorkloadMetric), workloadMetric); workloadRequest.BatchUnit = batchUnit; workloadRequest.BatchID = batchId; workloadRequest.BatchSize = batchSize; WorkloadResponse workloadResponse = new WorkloadResponse(); workloadResponse = await client.GetWorkloadAsync(workloadRequest); Console.WriteLine("Server Response:\n" + "\"rfdid\": " + workloadResponse.RFDID.ToString() + ",\n" + "\"lastbatchID\": " + workloadResponse.LastBatchID.ToString() + ",\n" + "\"batches\": ["); for (int i = 0; i < workloadResponse.Batches.Count(); i++) { Console.WriteLine("\t{\t\"batchID\": " + workloadResponse.Batches[i].BatchID + ","); Console.WriteLine("\t\t\"requestedSamples\": [\n"); for (int j = 0; j < workloadResponse.Batches[i].RequestedSamples.Count(); j++) { if (j == workloadResponse.Batches[i].RequestedSamples.Count() - 1) { Console.WriteLine("\t\t\t" + workloadResponse.Batches[i].RequestedSamples[j] + "\n\t\t]\n\t},"); } else { Console.WriteLine("\t\t\t" + workloadResponse.Batches[i].RequestedSamples[j] + ","); } } if (i == workloadResponse.Batches.Count - 1) { Console.WriteLine("]"); } } Console.WriteLine("Press any key to continue OR press '9' to exit"); string continueORQuit = Console.ReadLine(); if (continueORQuit.Equals("9")) { break; } } }
static async Task Main(string[] args) { // The port number(5001) must match the port of the gRPC server. Console.WriteLine("Type Server URL:Port"); string url = Console.ReadLine(); var channel = GrpcChannel.ForAddress(url); var client = new Workload.WorkloadClient(channel); while (true) { //Verify all inputs string rfw = ""; while (true) { Console.Write("RFW ID: "); rfw = Console.ReadLine(); if (!String.IsNullOrEmpty(rfw)) { break; } Console.WriteLine("RFW ID is empty !"); } //validate benchmarktype string benchmark = ""; while (true) { Console.Write("Benchmark Type (DVDTrain = 0, DVDTest = 1, NDBenchTrain = 2, NDBench = 3): "); benchmark = Console.ReadLine(); if (benchmark == "0" || benchmark == "1" || benchmark == "2" || benchmark == "3") { break; } Console.WriteLine("Invalid Benchmark Type!"); } //validate metric type string metric = ""; while (true) { Console.Write("Workload Metric (CPU = 0, NetworkIn = 1, NetworkOut = 2, Memory = 3, FinalTarget = 4): "); metric = Console.ReadLine(); if (metric == "0" || metric == "1" || metric == "2" || metric == "3" || metric == "4") { break; } Console.WriteLine("Invalid Worload Metric!"); } //validate batch unit is a number int batchUnit = 0; while (true) { Console.Write("Batch Unit (integer): "); string str = Console.ReadLine(); if (int.TryParse(str, out batchUnit)) { break; } Console.WriteLine("Not a valid interger!"); } //validate batch id is a number int batchId = 0; while (true) { Console.Write("Batch ID (integer): "); string str = Console.ReadLine(); if (int.TryParse(str, out batchId)) { break; } Console.WriteLine("Not a valid interger!"); } //validate batch size is a number int batchSize = 0; while (true) { Console.Write("Batch Size (integer): "); string str = Console.ReadLine(); if (int.TryParse(str, out batchSize)) { break; } Console.WriteLine("Not a valid interger!"); } //send request then get resonse in "reply" variable var reply = await client.GetWorkloadAsync(new WorkloadRequest { Rfw = rfw, BenchMark = (WorkloadRequest.Types.BenchMarkType)Enum.Parse(typeof(WorkloadRequest.Types.BenchMarkType), benchmark), Metric = (WorkloadRequest.Types.MetricType)Enum.Parse(typeof(WorkloadRequest.Types.MetricType), metric), BatchUnit = batchUnit, BatchId = batchId, BatchSize = batchSize }); //output reply Console.WriteLine(" \n\n"); Console.WriteLine("Server Response: \nRFWID: " + reply.Rfw + "\nLastBatchID: " + reply.LastBatchId + "\nBatches: " + reply.Batches); Console.WriteLine("Press any key to continue or type 'quit' to exit..."); //exit loop string quit = Console.ReadLine(); if (quit == "quit") { break; } } }