static async Task Main(string[] args) { string response = "Y"; _config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json").Build(); /* * WriteLine("\n\nCreating New Professor ..."); * while (response == "Y") * { * // Add New Professor * AddProfessorRequest professorNew = GenerateNewProfessor(); * * var newlyAddedProfessor = await Client.AddProfessorAsync(professorNew); * WriteLine($"\n\nNew Professor Added with Professor Id: {newlyAddedProfessor.ProfessorId}"); * * WriteLine("\n\nDo you want to create New Professor: {Y/N}"); * response = ReadKey().KeyChar.ToString().ToUpper(); * } */ response = "Y"; while (response == "Y") { WriteLine("\n\nPlease enter a Professor Id: "); var professorId = ReadLine(); // Retrieve Single Row var professorRequest = new GetProfessorRequest { ProfessorId = professorId }; var professor = await Client.GetProfessorByIdAsync(professorRequest); DisplayProfessorDetails(professor); WriteLine("\n\nDo you want to Lookup a Professor: {Y/N}"); response = ReadKey().KeyChar.ToString().ToUpper(); } response = "Y"; while (response == "Y") { // Retrieve Multiple Rows var professors = await Client.GetAllProfessorsAsync(new Empty()); foreach (var prof in professors.Professors) { DisplayProfessorDetails(prof); } WriteLine("\n\nDo you want to retrieve all professors: {Y/N}"); response = ReadKey().KeyChar.ToString().ToUpper(); } WriteLine("\n\nThank You for using the application. \n\nPress any key ..."); ReadKey(); }
public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context) { Stopwatch stopwatch = new Stopwatch(); GetProfessorResponse getProfessorResponse = new GetProfessorResponse(); Professor professor; string professorId = $"{Constants.RedisCacheStore.SingleProfessorsKey}{request.ProfessorId}"; stopwatch.Start(); var professorFromCache = _cache.GetString(professorId); if (!string.IsNullOrEmpty(professorFromCache)) { //if they are there, deserialize them professor = JsonConvert.DeserializeObject <Professor>(professorFromCache); } else { // Going to Data Store SQL Server professor = _professorsBll.GetProfessorById(Guid.Parse(request.ProfessorId)); //and then, put them in cache _cache.SetString(professorId, JsonConvert.SerializeObject(professor), GetDistributedCacheEntryOptions()); } stopwatch.Stop(); _logger.Log(LogLevel.Warning, $"Time Taken to Retireve a Record: {stopwatch.ElapsedMilliseconds} ms"); getProfessorResponse = GetProfessorObject(professor); return(await Task.FromResult(getProfessorResponse)); }
static async Task Main(string[] args) { using var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new CollegeService.CollegeServiceClient(channel); // Add New Professor NewProfessorRequest professorNew = new NewProfessorRequest() { Name = "Shiva", Doj = Timestamp.FromDateTime(DateTime.Now.AddYears(-5).ToUniversalTime()), Teaches = "CSharp, Java", Salary = 1234.56, IsPhd = true }; var professorGenerated = await client.AddProfessorAsync(professorNew); // Retrieve Single Row var professorRequest = new GetProfessorRequest { ProfessorId = "5ec797ec-da0a-43df-b3a3-3f9a04163656" }; var professor = await client.GetProfessorByIdAsync(professorRequest); DisplayProfessorDetails(professor); // Retrieve Multiple Rows var professors = await client.GetAllProfessorsAsync(new Empty()); foreach (var prof in professors.Professors) { DisplayProfessorDetails(prof); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
static async Task Main(string[] args) { _config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json").Build(); var _client = CollegeServiceClientHelper.GetCollegeServiceClient(_config["RPCService:ServiceUrl"]); DisplayHeader("Retrieve Single Row ..."); WriteLine("\n\nPlease enter a Professor Id: "); var professorId = ReadLine(); var professorRequest = new GetProfessorRequest { ProfessorId = professorId }; var professor = await _client.GetProfessorByIdAsync(professorRequest); DisplayProfessorDetails(professor); DisplayFooter(); DisplayHeader("Retrieve All Rows ..."); var professors = await _client.GetAllProfessorsAsync(new Empty()); foreach (var prof in professors.Professors) { DisplayProfessorDetails(prof); } WriteLine("\n\nThank You for using the application. \n\nPress any key ..."); ReadKey(); }
public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context) { _logger.Log(LogLevel.Debug, "Request Received for CollegeGrpcService::GetProfessorById"); Professor professor = await _professorsBll.GetProfessorById(Guid.Parse(request.ProfessorId)); GetProfessorResponse getProfessorResponse = _mapper.Map <GetProfessorResponse>(professor); _logger.Log(LogLevel.Debug, "Returning the results from CollegeGrpcService::GetProfessorById"); return(getProfessorResponse); }
private async void buttonFind_Click(object sender, EventArgs e) { var professorRequest = new GetProfessorRequest { ProfessorId = textBoxProfessorId.Text }; var professor = await _client.GetProfessorByIdAsync(professorRequest); textBoxName.Text = professor.Name; textBoxTeaches.Text = professor.Teaches; textBoxSalary.Text = professor.Salary.ToString(); checkBoxIsPhd.Checked = professor.IsPhd; }
public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context) { _logger.Log(LogLevel.Debug, "Request Received for CollegeGrpcService::GetProfessorById"); GetProfessorResponse getProfessorResponse = new GetProfessorResponse(); Professor professor; // Going to Data Store SQL Server professor = _professorsBll.GetProfessorById(Guid.Parse(request.ProfessorId)); getProfessorResponse = GetProfessorObject(professor); _logger.Log(LogLevel.Debug, "Returing the response from CollegeGrpcService::GetProfessorById"); return(await Task.FromResult(getProfessorResponse)); }
public async Task <Professor> GetProfessorById(string professorId) { _logger.Log(LogLevel.Debug, "Request Received for ProfessorsController::GetProfessorById"); // Retrieve Single Professor var professorRequest = new GetProfessorRequest { ProfessorId = professorId }; var singleProfessor = await _collegeServiceClient.GetProfessorByIdAsync(professorRequest); Professor professor = GetProfessorObject(singleProfessor); _logger.Log(LogLevel.Debug, "Sending Response from ProfessorsController::GetProfessorById"); return(professor); }
public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context) { _logger.Log(LogLevel.Debug, "Request Received for CollegeGrpcService::GetProfessorById"); //Professor professor = await _professorsSqlBll.GetProfessorById(Guid.Parse(request.ProfessorId)) // .ConfigureAwait(false); Professor professor = await _professorsCosmosBll.GetProfessorById(Guid.Parse(request.ProfessorId)) .ConfigureAwait(false); GetProfessorResponse getProfessorResponse = GetProfessorObject(professor); _logger.Log(LogLevel.Debug, "Returning the results from CollegeGrpcService::GetProfessorById"); return(getProfessorResponse); }
public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context) { GetProfessorResponse getProfessorResponse = new GetProfessorResponse(); if (!_collegeDbContext.Professors.Any(record => record.ProfessorId == Guid.Parse(request.ProfessorId))) { getProfessorResponse = null; } var professor = await _collegeDbContext.Professors .Where(record => record.ProfessorId == Guid.Parse(request.ProfessorId)) .Include(student => student.Students) .FirstOrDefaultAsync(); getProfessorResponse = GetProfessorObject(professor); return(getProfessorResponse); }
public override async Task <GetProfessorResponse> GetProfessorById(GetProfessorRequest request, ServerCallContext context) { Stopwatch stopwatch = new Stopwatch(); Professor professor; stopwatch.Start(); // Going to Data Store SQL Server professor = _professorsBll.GetProfessorById(Guid.Parse(request.ProfessorId)); stopwatch.Stop(); _logger.Log(LogLevel.Warning, $"Time Taken to Retireve a Record: {stopwatch.ElapsedMilliseconds} ms"); GetProfessorResponse getProfessorResponse = new GetProfessorResponse(); getProfessorResponse = GetProfessorObject(professor); return(await Task.FromResult(getProfessorResponse)); }
public async Task <ActionResult <Professor> > GetProfessorById(Guid professorId) { _logger.Log(LogLevel.Debug, "Request Received for ProfessorsController::Get"); var professorRequest = new GetProfessorRequest { ProfessorId = professorId.ToString() }; var _professor = await _collegeServiceClient.GetProfessorByIdAsync(professorRequest); if (_professor == null) { return(NotFound()); } _logger.Log(LogLevel.Debug, "Returning the results from ProfessorsController::Get"); return(Ok(GetProfessor(_professor))); }
static async Task Main(string[] args) { using var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new CollegeService.CollegeServiceClient(channel); // Retrieve Single Row var professorRequest = new GetProfessorRequest { ProfessorId = "5ec797ec-da0a-43df-b3a3-3f9a04163656" }; var professor = await client.GetProfessorByIdAsync(professorRequest); DisplayProfessorDetails(professor); // Retrieve Multiple Rows var professors = await client.GetAllProfessorsAsync(new Empty()); foreach (var prof in professors.Professors) { DisplayProfessorDetails(prof); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
static async Task Main(string[] args) { _config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json").Build(); var _collegeClient = CollegeServiceClientHelper.GetCollegeServiceClient(_config["RPCService:ServiceUrl"]); //var _addressClient = AddressServiceClientHelper.GetAddressBookServerClient(_config["RPCService:ServiceUrl"]); ////**************** ADDRESS BOOK CLIENT SIDE STREAMING ****************// //var userAddress = new AddAddressRequest //{ // StudentId = Guid.NewGuid().ToString(), /* To Be replaced with Students's Id*/ // Name = NameGenerator.GenerateName(12), // FullAddress = AddressGenerator.GenerateAddress(), // Enrollment = AddressConstants.EnrollmentTypes[RandomNumberGenerator.GetRandomValue(1, 4)] //}; //using (var stream = _addressClient.AddAddressEnrollments()) //{ // foreach (string enrollmentType in AddressConstants.EnrollmentTypes) // { // userAddress.Enrollment = enrollmentType; // await stream.RequestStream.WriteAsync(userAddress).ConfigureAwait(false); // } // await stream.RequestStream.CompleteAsync().ConfigureAwait(false); // await stream; // WriteLine($"Sent All"); //} ////**************** ADDRESS BOOK CLIENT SIDE STREAMING ****************// ////**************** ADDRESS BOOK SERVER SIDE STREAMING ****************// //var studentEnrollmentsRequest = new AddressEnrollmentRequest //{ // StudentId = "62b76fc7-46d9-4d1c-a246-7f4083a87634" //}; //using var studentEnrollments = _addressClient // .RetrieveAddressEnrollments(studentEnrollmentsRequest); //try //{ // await foreach (var studentEnrollment in studentEnrollments.ResponseStream.ReadAllAsync()) // { // WriteLine($"{studentEnrollment.StudentId} | {studentEnrollment.Name} | {studentEnrollment.Enrollment} | {studentEnrollment.EnrollmentStatus}"); // } //} //catch (RpcException ex) when (ex.StatusCode == StatusCode.Cancelled) //{ // Console.WriteLine("Stream cancelled."); //} ////**************** ADDRESS BOOK SERVER SIDE STREAMING ****************// /* * DisplayHeader("Creating New Professor ..."); * NewProfessorRequest professorNew = GenerateNewProfessor(); * var newlyAddedProfessor = await _collegeClient.AddProfessorAsync(professorNew); * WriteLine($"\n\nNew Professor Added with Professor Id: {newlyAddedProfessor.ProfessorId}"); * DisplayFooter(); */ var jwtToken = new JwtAccessToken(); if (jwtToken.Expiration < DateTime.Now) { jwtToken = GetTokenFromAuth0(); } var headers = new Metadata { { "Authorization", $"Bearer {jwtToken.Access_Token}" } }; //DisplayHeader("Retrieve Single Row ..."); WriteLine("\n\nPlease enter a Professor Id: "); var professorId = ReadLine(); var professorRequest = new GetProfessorRequest { ProfessorId = professorId }; var professor = await _collegeClient.GetProfessorByIdAsync(professorRequest, headers : headers); DisplayProfessorDetails(professor); DisplayFooter(); DisplayHeader("Retrieve All Rows ..."); var professors = await _collegeClient.GetAllProfessorsAsync(new Empty()); foreach (var prof in professors.Professors) { DisplayProfessorDetails(prof); } WriteLine("\n\nThank You for using the application. \n\nPress any key ..."); ReadKey(); }
static async Task Main(string[] args) { string response = "Y"; _config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json").Build(); // gRPC Clients CollegeServiceClient CollegeClient = CollegeServiceClientHelper.GetCollegeServiceClient(_config["RPCService:ServiceUrl"]); AddressBookServerClient AddressClient = AddressServiceClientHelper.GetAddressBookServerClient(_config["RPCService:ServiceUrl"]); /* * var cts = new CancellationTokenSource(TimeSpan.FromSeconds(50)); * * using var replies = AddressClient.GetWeatherStream(new Empty(), cancellationToken: cts.Token); * * try * { * await foreach (var weatherData in replies.ResponseStream.ReadAllAsync(cancellationToken: cts.Token)) * { * Console.WriteLine($"{weatherData.DateTimeStamp.ToDateTime():s} | {weatherData.Summary} | {weatherData.TemperatureC} C"); * } * } * catch (RpcException ex) when (ex.StatusCode == StatusCode.Cancelled) * { * Console.WriteLine("Stream cancelled."); * } */ // Address Enrollments Client Request for Server Streaming. var studentEnrollmentsRequest = new AddressEnrollmentRequest { StudentId = "3698FAED-83A1-4700-89EE-CAFE7716833E" }; using var studentEnrollments = AddressClient.RetrieveAddressEnrollments(studentEnrollmentsRequest); try { await foreach (var studentEnrollment in studentEnrollments.ResponseStream.ReadAllAsync()) { Console.WriteLine($"{studentEnrollment.StudentId} {studentEnrollment.Name} {studentEnrollment.Enrollment} {studentEnrollment.EnrollmentStatus}"); } } catch (RpcException ex) when(ex.StatusCode == StatusCode.Cancelled) { Console.WriteLine("Stream cancelled."); } // Address Enrollments Client Side Stream var userAddress = new AddAddressRequest { StudentId = Guid.NewGuid().ToString(), /* To Be replaced with Students's Id*/ Name = NameGenerator.GenerateName(12), FullAddress = AddressGenerator.GenerateAddress(), Enrollment = Konstants.AddressConstants.EnrollmentTypes[RandomNumberGenerator.GetRandomValue(1, 4)] }; using (var stream = AddressClient.AddAddressEnrollments()) { foreach (string enrollmentType in Konstants.AddressConstants.EnrollmentTypes) { userAddress.Enrollment = enrollmentType; await stream.RequestStream.WriteAsync(userAddress); } await stream.RequestStream.CompleteAsync(); await stream; WriteLine($"Sent All"); } /* * WriteLine("\n\nCreating New Professor ..."); * while (response == "Y") * { * // Add New Professor * AddProfessorRequest professorNew = GenerateNewProfessor(); * * var newlyAddedProfessor = await Client.AddProfessorAsync(professorNew); * WriteLine($"\n\nNew Professor Added with Professor Id: {newlyAddedProfessor.ProfessorId}"); * * WriteLine("\n\nDo you want to create New Professor: {Y/N}"); * response = ReadKey().KeyChar.ToString().ToUpper(); * } */ response = "Y"; while (response == "Y") { WriteLine("\n\nPlease enter a Professor Id: "); var professorId = ReadLine(); // Retrieve Single Row var professorRequest = new GetProfessorRequest { ProfessorId = professorId }; var professor = await CollegeClient.GetProfessorByIdAsync(professorRequest); DisplayProfessorDetails(professor); WriteLine("\n\nDo you want to Lookup a Professor: {Y/N}"); response = ReadKey().KeyChar.ToString().ToUpper(); } // Address Service gRPC var userAddress1 = new AddAddressRequest { StudentId = Guid.NewGuid().ToString(), /* To Be replaced with Students's Id*/ Name = NameGenerator.GenerateName(12), FullAddress = AddressGenerator.GenerateAddress(), Enrollment = Konstants.AddressConstants.EnrollmentTypes[RandomNumberGenerator.GetRandomValue(1, 4)] }; var newAddress = await AddressClient.AddAddressAsync(userAddress1); WriteLine($"Address Data with Id: {newAddress.Id}"); /* * response = "Y"; * while (response == "Y") * { * // Retrieve Multiple Rows * var professors = await Client.GetAllProfessorsAsync(new Empty()); * * foreach (var prof in professors.Professors) * { * DisplayProfessorDetails(prof); * } * * WriteLine("\n\nDo you want to retrieve all professors: {Y/N}"); * response = ReadKey().KeyChar.ToString().ToUpper(); * } */ WriteLine("\n\nThank You for using the application. \n\nPress any key ..."); ReadKey(); }
static async Task Main(string[] args) { string response = "Y"; _config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json").Build(); // gRPC Clients CollegeServiceClient CollegeClient = CollegeServiceClientHelper.GetCollegeServiceClient(_config["RPCService:ServiceUrl"]); AddressBookServerClient AddressClient = AddressServiceClientHelper.GetAddressBookServerClient(_config["RPCService:ServiceUrl"]); // Address Enrollments Client Side Stream var userAddress = new AddAddressRequest { StudentId = Guid.NewGuid().ToString(), /* To Be replaced with Students's Id*/ Name = NameGenerator.GenerateName(12), FullAddress = AddressGenerator.GenerateAddress(), Enrollment = Konstants.AddressConstants.EnrollmentTypes[RandomNumberGenerator.GetRandomValue(1, 4)] }; using (var stream = AddressClient.AddAddressEnrollments()) { foreach (string enrollmentType in Konstants.AddressConstants.EnrollmentTypes) { userAddress.Enrollment = enrollmentType; await stream.RequestStream.WriteAsync(userAddress); } await stream.RequestStream.CompleteAsync(); await stream; WriteLine($"Sent All"); } /* * WriteLine("\n\nCreating New Professor ..."); * while (response == "Y") * { * // Add New Professor * AddProfessorRequest professorNew = GenerateNewProfessor(); * * var newlyAddedProfessor = await Client.AddProfessorAsync(professorNew); * WriteLine($"\n\nNew Professor Added with Professor Id: {newlyAddedProfessor.ProfessorId}"); * * WriteLine("\n\nDo you want to create New Professor: {Y/N}"); * response = ReadKey().KeyChar.ToString().ToUpper(); * } */ response = "Y"; while (response == "Y") { WriteLine("\n\nPlease enter a Professor Id: "); var professorId = ReadLine(); // Retrieve Single Row var professorRequest = new GetProfessorRequest { ProfessorId = professorId }; var professor = await CollegeClient.GetProfessorByIdAsync(professorRequest); DisplayProfessorDetails(professor); WriteLine("\n\nDo you want to Lookup a Professor: {Y/N}"); response = ReadKey().KeyChar.ToString().ToUpper(); } // Address Service gRPC var userAddress1 = new AddAddressRequest { StudentId = Guid.NewGuid().ToString(), /* To Be replaced with Students's Id*/ Name = NameGenerator.GenerateName(12), FullAddress = AddressGenerator.GenerateAddress(), Enrollment = Konstants.AddressConstants.EnrollmentTypes[RandomNumberGenerator.GetRandomValue(1, 4)] }; var newAddress = await AddressClient.AddAddressAsync(userAddress1); WriteLine($"Address Data with Id: {newAddress.Id}"); /* * response = "Y"; * while (response == "Y") * { * // Retrieve Multiple Rows * var professors = await Client.GetAllProfessorsAsync(new Empty()); * * foreach (var prof in professors.Professors) * { * DisplayProfessorDetails(prof); * } * * WriteLine("\n\nDo you want to retrieve all professors: {Y/N}"); * response = ReadKey().KeyChar.ToString().ToUpper(); * } */ WriteLine("\n\nThank You for using the application. \n\nPress any key ..."); ReadKey(); }