Esempio n. 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);

                var userAddress = new AddAddressRequest
                {
                    StudentId   = Guid.NewGuid().ToString(), /* To Be replaced with Students's Id*/
                    Name        = NameGenerator.GenerateName(12),
                    FullAddress = AddressGenerator.GenerateAddress(),
                    Enrollment  = Constants.AddressConstants.EnrollmentTypes[RandomNumberGenerator.GetRandomValue(1, 4)]
                };

                try
                {
                    var newAddress = await _client.AddAddressAsync(userAddress);

                    Console.WriteLine($"Address Data with Id: {newAddress.Id}");
                }
                catch (RpcException rpcError)
                {
                    _logger.LogError($"Error received from Server. {rpcError.Message} {rpcError.Trailers}");
                }

                await Task.Delay(_config.GetValue <int>("RPCService:DelayInterval"), stoppingToken);
            }
        }
Esempio n. 2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);

                // 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");
                }

                // await Task.Delay(1000, stoppingToken);
                await Task.Delay(_config.GetValue <int>("RPCService:DelayInterval"), stoppingToken);
            }
        }
Esempio n. 3
0
        public void ShouldGenerateAddressesFromPrivateKey(string privateKey, string address)
        {
            var privKeyStr = Encoders.Hex.DecodeData(privateKey);
            Key key        = new Key(privKeyStr);

            IAddressGenerator addressGenerator = new AddressGenerator();
            var actulaAddress = addressGenerator.GenerateAddress(key.PubKey.ToBytes());

            Assert.AreEqual(address, actulaAddress);
        }
Esempio n. 4
0
        public void ShouldGenerateAddressesFromPrivateKey(string privateKey, string address)
        {
            var privKeyStr = Encoders.Hex.DecodeData(privateKey);
            Key key        = new Key(privKeyStr);

            // Works for Mainnet by default when no wallet instance is created
            IAddressGenerator addressGenerator = new AddressGenerator();
            var actualAddress = addressGenerator.GenerateAddress(key.PubKey.ToBytes());

            Assert.AreEqual(address, actualAddress);
        }
Esempio n. 5
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 ****************//
            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 ****************//

            /*
             * DisplayHeader("Creating New Professor ...");
             * NewProfessorRequest professorNew = GenerateNewProfessor();
             * var newlyAddedProfessor = await _collegeClient.AddProfessorAsync(professorNew);
             * WriteLine($"\n\nNew Professor Added with Professor Id: {newlyAddedProfessor.ProfessorId}");
             * DisplayFooter();
             */

            //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);

            //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();
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
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"]);

            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();

            //**************** 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();
             */

            //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);

            //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();
        }
Esempio n. 8
0
        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();
        }