static async Task Main(string[] args)
        {
            var externalFilePath = @"C:\Users\secrets.json";

            _config = new ConfigurationBuilder()
                      .SetBasePath(Directory.GetCurrentDirectory())
                      .AddJsonFile("appsettings.json")
                      .AddJsonFile(externalFilePath)
                      .Build();

            var jwtToken = new JwtAccessToken();

            if (jwtToken.Expiration < DateTime.Now)
            {
                jwtToken = GetTokenFromAuth0();
            }

            var headers = new Metadata
            {
                { "Authorization", $"Bearer {jwtToken.Access_Token}" }
            };

            var reply = await Client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" }, headers : headers);

            WriteLine("Greeting: " + reply.Message);

            WriteLine("\n\nThank You for using the application. \n\nPress any key ...");
            ReadKey();
        }
Exemplo n.º 2
0
        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();
        }