Esempio n. 1
0
        static async Task Main(string[] args)
        {
            //var input = new HelloRequest { Name = "Kabbo"};

            //var channel = GrpcChannel.ForAddress("http://localhost:5000");
            //var client = new Greeter.GreeterClient(channel);

            //var reply = await client.SayHelloAsync(input);
            //Console.WriteLine(reply.Message);

            var input = new CustomerLookupModel {
                UserId = 1
            };

            var channel = GrpcChannel.ForAddress("http://localhost:5000");
            var client  = new Customer.CustomerClient(channel);

            var reply = await client.GetCustomerInfoAsync(input);

            Console.WriteLine($"Hello {reply.FirstName} {reply.LastName} ...");
            Console.WriteLine();

            Console.WriteLine($"Customer List:");
            using (var call = client.GetCustomersInfo(new CustomersLookupModel()))
            {
                while (await call.ResponseStream.MoveNext())
                {
                    var customer = call.ResponseStream.Current;
                    Console.WriteLine($"{customer.FirstName} {customer.LastName} ...");
                }
            }
            Console.ReadLine();
        }
Esempio n. 2
0
        static async Task Main(string[] args)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:5001");

            //var input = new HelloRequest { Name = "Aruna" };
            //var client = new Greeter.GreeterClient(channel);
            //var reply = await client.SayHelloAsync(input);
            //Console.WriteLine(reply.Message);

            var customerClient      = new Customer.CustomerClient(channel);
            var customerLookupModel = new CustomerLookupModel {
                UserId = 1
            };
            var customerResponse = await customerClient.GetCustomerInfoAsync(customerLookupModel);

            Console.WriteLine(customerResponse.FirstName);
            Console.WriteLine(customerResponse.LastName);
            Console.WriteLine(customerResponse.EmailAddress);
            Console.WriteLine(customerResponse.IsAtive);

            Console.WriteLine();
            Console.WriteLine("New Customers:");
            Console.WriteLine();

            using (var call = customerClient.GetNewCustomers(new NewCustomerRequest()))
            {
                while (await call.ResponseStream.MoveNext())
                {
                    var currentCust = call.ResponseStream.Current;
                    Console.WriteLine($"{currentCust.FirstName} {currentCust.LastName} {currentCust.EmailAddress} {currentCust.IsAtive}");
                }
            }

            Console.ReadLine();
        }
Esempio n. 3
0
        static async Task Main(string[] args)
        {
            //var input = new HelloRequest { Name="Kadir"};
            //var channel = GrpcChannel.ForAddress("https://localhost:5001");
            //var client = new Greeter.GreeterClient(channel);

            //var reply = await client.SayHelloAsync(input);

            //Console.WriteLine(reply.Message);

            //Console.ReadLine();

            Console.ReadLine();

            var channel        = GrpcChannel.ForAddress("https://localhost:5001");
            var customerClient = new Customer.CustomerClient(channel);

            var clientRequested = new CustomerLookupModel {
                UserId = 2
            };
            var customer = await customerClient.GetCustomerInfoAsync(clientRequested);

            Console.WriteLine($"{clientRequested.UserId}'idli arama sonucu dönen müşteri: {customer.FirstName} {customer.LastName}");

            Console.ReadLine();
        }
Esempio n. 4
0
        static async Task Main(string[] args)
        {
            //If we want to use both clients, we do need to recreate the channel
            AppContext.SetSwitch(
                "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            //var input = new HelloRequest { Name = "Tim" };
            //var channel = GrpcChannel.ForAddress("https://localhost:5002");

            //var client = new Greeter.GreeterClient(channel);
            //var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });


            var newChannel     = GrpcChannel.ForAddress("https://localhost:5002");
            var customerClient = new Customer.CustomerClient(newChannel);

            var clientRequested = new CustomerLookupModel()
            {
                UserId = 2
            };

            var customer = await customerClient.GetCustomerInfoAsync(clientRequested);

            using (var call = customerClient.GetNewCustomers(new NewCustomerRequest()))
            {
                while (await call.ResponseStream.MoveNext())
                {
                    var currentCustomer = call.ResponseStream.Current;
                    Console.WriteLine($"{currentCustomer.FirstName} {currentCustomer.LastName}");
                }
            }

            Console.ReadLine();
        }
Esempio n. 5
0
        static async Task Main(string[] args)
        {
            var input = new HelloRequest {
                Name = "Daniel"
            };
            var channel = GrpcChannel.ForAddress("https://localhost:5001");

            var client         = new Greeter.GreeterClient(channel);
            var customerClient = new Customer.CustomerClient(channel);

            var reply = await client.SayHelloAsync(input);

            var reply2 = await customerClient.GetCustomerInfoAsync(new CustomerLookupModel { UserId = 2 });

            Console.WriteLine(reply.Message);
            Console.WriteLine($"{reply2.FirstName} {reply2.LastName}");

            using (var call = customerClient.GetNewCustomers(new NewCustomerRequest()))
            {
                while (await call.ResponseStream.MoveNext())
                {
                    var currentCustomer = call.ResponseStream.Current;

                    Console.WriteLine($"Customer: {currentCustomer.FirstName} {currentCustomer.LastName} Email: {currentCustomer.EmailAddress}");
                }
            }
        }
Esempio n. 6
0
        public async Task <CustomerResponse> Register([Required] CustomerRequest request)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("Invalid model");
            }

            var response = await GrpcCallerService.CallService(urlGrpc : GRPCUrl.IdentityService, logger : _logger, func : async channel =>
            {
                var client = new Customer.CustomerClient(channel);
                _logger.LogDebug("Grpc get customer request {@request}", request);
                var customer = await client.AddCustomerAsync(request);
                var response = await GrpcCallerService.CallService(urlGrpc: GRPCUrl.ProductService, logger: _logger, func: async channel =>
                {
                    var client = new ProductUser.ProductUserClient(channel);
                    _logger.LogDebug("Grpc add product customer request {@request}", customer);
                    return(await client.UpdateCustomerAsync(new ProductUserRequest {
                        Id = customer.Id, Name = customer.Name, IsDeleted = false
                    }));
                });
                return(customer);
            });

            return(response);
        }
Esempio n. 7
0
        static async Task Main(string[] args)
        {
            //var input = new HelloRequest { Name = "Kirill" };
            //var channel = GrpcChannel.ForAddress("https://localhost:5001");
            //var client = new Greeter.GreeterClient(channel);

            //var reply = await client.SayHelloAsync(input);

            //Console.WriteLine(reply.Message);

            var channel        = GrpcChannel.ForAddress("https://localhost:5001");
            var customerClient = new Customer.CustomerClient(channel);

            var clientRequester = new CustomerLookupModel {
                UserId = 2
            };

            var customer = await customerClient.GetCustomerInfoAsync(clientRequester);

            Console.WriteLine($"Customer: {customer.FirstName} - {customer.LastName}");
            Console.WriteLine("==========new customer==============");

            using (var call = customerClient.GetNewCustomers(new NewCustomerRequest()))
            {
                while (await call.ResponseStream.MoveNext())
                {
                    var currenCustomer = call.ResponseStream.Current;

                    Console.WriteLine($"Customer: {currenCustomer.FirstName} - {currenCustomer.LastName}\n" +
                                      $" Email: {currenCustomer.Email} Age: {currenCustomer.Age} Active:{currenCustomer.IsActive}");
                }
            }

            Console.ReadLine();
        }
Esempio n. 8
0
        static async Task Main(string[] args)
        {
            var input = new HelloRequest()
            {
                Name = "Shahab Noori Goodarzi"
            };
            var channel       = GrpcChannel.ForAddress("https://localhost:5001");
            var greeterClient = new Greeter.GreeterClient(channel);
            var greeterReply  = await greeterClient.SayHelloAsync(input);

            Console.WriteLine(greeterReply.Message);


            var customerClient = new Customer.CustomerClient(channel);
            var customerReply  = await customerClient.GetCustomerInfoAsync(new CustomerLookupModel()
            {
                UserId = 1
            });

            Console.WriteLine($"{customerReply.FirstName} {customerReply.LastName}");

            using (var call = customerClient.GetNewCustomers(new NewCustomerRequest()))
            {
                while (await call.ResponseStream.MoveNext(CancellationToken.None))
                {
                    var currentCustomer = call.ResponseStream.Current;
                    Console.WriteLine($"{currentCustomer.FirstName} {currentCustomer.LastName} {currentCustomer.EmailAddress}");
                }
            }
            Console.ReadKey();
        }
Esempio n. 9
0
        static async Task Main(string[] args)
        {
            var channel       = GrpcChannel.ForAddress("https://localhost:5001");
            var greeterClient = new Greeter.GreeterClient(channel);

            var request = new HelloRequest()
            {
                Name = "Marcin"
            };
            HelloReply reply = await greeterClient.SayHelloAsync(request);

            Console.WriteLine(reply);

            Console.WriteLine();
            var customerClient = new Customer.CustomerClient(channel);

            using AsyncServerStreamingCall <CustomerModel> custommers = customerClient.GetNewCustomers(new Unit());
            while (await custommers.ResponseStream.MoveNext())
            {
                CustomerModel currentCustomer = custommers.ResponseStream.Current;
                Console.WriteLine(currentCustomer);
            }

            _ = Console.ReadLine();
        }
Esempio n. 10
0
        static async Task Main(string[] args)
        {
            //var input = new HelloRequest { Name = "Ana" };
            //var channel = GrpcChannel.ForAddress("https://localhost:5001");
            //var client = new Greeter.GreeterClient(channel);
            //var reply = await client.SayHelloAsync(input);

            //Console.WriteLine(reply.Message);

            var channel         = GrpcChannel.ForAddress("https://localhost:5001");
            var customerClient  = new Customer.CustomerClient(channel);
            var clientRequested = new CustomerLookupModel {
                UserId = 2
            };
            var customer = await customerClient.GetCustomerInfoAsync(clientRequested);

            Console.WriteLine($"{ customer.FirstName} {customer.SecondName}");
            Console.WriteLine();
            Console.WriteLine("New Customer List");
            Console.WriteLine();
            using (var call = customerClient.GetNewCustomers(new NewCustomerRequest()))
            {
                while (await call.ResponseStream.MoveNext())
                {
                    var currentCustomer = call.ResponseStream.Current;

                    Console.WriteLine($"{ currentCustomer.FirstName} {currentCustomer.SecondName}: {currentCustomer.Age}");
                }
            }

            Console.ReadLine();
        }
Esempio n. 11
0
        static async Task Main()
        {
            var channel        = GrpcChannel.ForAddress("https://localhost:5001");
            var greeterClient  = new Greeter.GreeterClient(channel);
            var customerClient = new Customer.CustomerClient(channel);

            var greeterInput = new HelloRequest
            {
                Name = "John Doe"
            };

            var customerInput = new CustomerLookupModel
            {
                UserId = 2
            };

            var greeterReply = await greeterClient.SayHelloAsync(greeterInput);

            var customerReply = await customerClient.GetCustomerInfoAsync(customerInput);

            Console.WriteLine(greeterReply.Message);
            Console.WriteLine($"{ customerReply.FirstName } { customerReply.LastName }");
            Console.WriteLine();

            using (var call = customerClient.GetNewCustomers(new NewCustomerRequest()))
            {
                while (await call.ResponseStream.MoveNext())
                {
                    var currentCustomer = call.ResponseStream.Current;
                    Console.WriteLine($"{ currentCustomer.FirstName } { currentCustomer.LastName }: { currentCustomer.EmailAddress }");
                }
            }

            Console.ReadLine();
        }
Esempio n. 12
0
        static void Main()
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new Customer.CustomerClient(channel);

            Console.WriteLine("All customer");
            GetCustomers(client).Wait();

            Console.WriteLine("Get customer id");
            GetCustomer(client, "a6c8c6b1-4349-45b0-ab31-244740aaf0f0");

            var customerModel = new CustomerModel()
            {
                Id           = "a6c8c6b1-4349-45b0-ab31-244740aaf0f0",
                FirstName    = "New",
                PreferenceId = "76324c47-68d2-472d-abb8-33cfa8cc0c84"
            };

            Console.WriteLine("New customer");
            CreateCustomer(client, customerModel);
            GetCustomers(client).Wait();

            Console.WriteLine("Edit customer");
            customerModel.FirstName = "Update";
            EditCustomers(client, customerModel);
            GetCustomers(client).Wait();

            Console.WriteLine("Delete customer");
            DeleteCustomer(client, "a6c8c6b1-4349-45b0-ab31-244740aaf0f0");
            GetCustomers(client).Wait();


            Console.ReadKey();
        }
Esempio n. 13
0
        static async Task Main(string[] args)
        {
            //var channel = GrpcChannel.ForAddress("https://localhost:5001");
            //var client = new Greeter.GreeterClient(channel);
            //var reply = await client.SayHelloAsync(new HelloRequest() { Name = "Vijay" });
            //Console.WriteLine(reply.Message);
            //Console.ReadLine();

            var channel    = GrpcChannel.ForAddress("https://localhost:5001");
            var custClient = new Customer.CustomerClient(channel);
            var reply      = await custClient.GetCustomerInfoAsync(new CustomerLookupModel()
            {
                UserId = 1
            });

            Console.WriteLine($" {reply.FirstName} {reply.LastName} is {reply.Age} years old");
            Console.WriteLine($" ---------------------------------------------------------");
            Console.WriteLine($" New customers:");
            using (var call = custClient.GetNewCustomers(new NewCustomerRequest()))
            {
                while (await call.ResponseStream.MoveNext(new System.Threading.CancellationToken()))
                {
                    _ = Task.Delay(1000);
                    var currentcust = call.ResponseStream.Current;
                    Console.WriteLine($" {currentcust.FirstName} {currentcust.LastName} is {currentcust.Age} years old");
                }
            }
            Console.ReadLine();
        }
Esempio n. 14
0
        static async Task Main(string[] args)
        {
            var channel        = GrpcChannel.ForAddress("https://localhost:5001");
            var customerClient = new Customer.CustomerClient(channel);

            Console.WriteLine("Date: ");
            DateTime input;//= Console.ReadLine();
            // DateTime dt;

            var auxx = Console.ReadLine();

            Console.WriteLine(auxx);
            bool isValid = DateTime.TryParseExact(
                auxx,
                "MM/dd/yyyy",
                CultureInfo.InvariantCulture,
                DateTimeStyles.None,
                out input);

            if (isValid)
            {
                var clientRequested = new CustomerLookupModel {
                    Date = auxx
                };
                var customer = await customerClient.GetCustomerInfoAsync(clientRequested);
            }
            else
            {
                Console.WriteLine("gresit");
            }
        }
        //static void Main(string[] args)
        static async Task Main(string[] args)
        {
            // GreeterService
            //var input = new HelloRequest { Name = "Owamamwen" };
            //var channel = GrpcChannel.ForAddress("http://localhost:5000");
            //var client = new Greeter.GreeterClient(channel);
            //var reply = await client.SayHelloAsync(input);
            //Console.WriteLine(reply.Message);
            //
            //
            // CustomersSerive
            var channel         = GrpcChannel.ForAddress("http://localhost:5000");
            var customerClient  = new Customer.CustomerClient(channel);
            var clientRequested = new CustomerLookModel {
                UserId = 2
            };
            var customer = await customerClient.GetCustomerInfoAsync(clientRequested);

            Console.WriteLine($"{customer.FirstName} {customer.LastName}");

            // NewCustomer
            Console.WriteLine("\n New Customer List \n");

            using (var call = customerClient.GetNewCustomers(new NewCustomerRequest()))
            {
                while (await call.ResponseStream.MoveNext())
                {
                    var currentCustomer = call.ResponseStream.Current;

                    Console.WriteLine($"{currentCustomer.FirstName} {currentCustomer.LastName} {currentCustomer.EmailAddress} {currentCustomer.Age} {currentCustomer.IsAlive}");
                }

                Console.ReadLine();
            }
        }
Esempio n. 16
0
        static async Task Main(string[] args)
        {
            var channel        = GrpcChannel.ForAddress("https://localhost:5001");
            var customerClient = new Customer.CustomerClient(channel);

            Console.WriteLine("Introduceti o data sub forma: luna/zi/an  \n");
            var      input = Console.ReadLine();
            DateTime dDate;

            if (DateTime.TryParse(input, out dDate))
            {
                String.Format("{0:d/MM/yyyy}", dDate);
                var clientRequested = new CustomerLookupModel {
                    UserId = input.ToString()
                };

                var customer = await customerClient.GetCustomerInfoAsync(clientRequested);

                Console.WriteLine($"{ customer.FirstName } { customer.LastName }");
            }
            else
            {
                Console.WriteLine("Eroare");
            }

            Console.ReadLine();
        }
Esempio n. 17
0
        public static void DeleteCustomer(Customer.CustomerClient client, string Id)
        {
            var customer = new CustomerRequest {
                Id = Id
            };

            client.DeleteCustomers(customer);
        }
Esempio n. 18
0
 public static async Task GetCustomers(Customer.CustomerClient client)
 {
     using var clientData = client.GetCustomers(new Empty());
     while (await clientData.ResponseStream.MoveNext(new System.Threading.CancellationToken()))
     {
         var thisProduct = clientData.ResponseStream.Current;
         Console.WriteLine($"id: {thisProduct.Id} FirstName: {thisProduct.FirstName}");
     }
 }
Esempio n. 19
0
        private static async Task <CustomerModel> GetCustomerAsync(Customer.CustomerClient client, int id)
        {
            var clientRequested = new CustomerLookupModel {
                UserId = id
            };
            var customer = await client.GetCustomerInfoAsync(clientRequested);

            return(customer);
        }
Esempio n. 20
0
 private static async Task GetAndDisplayAllCustomers(Customer.CustomerClient client)
 {
     using var call = client.GetAllCustomers(new AllCustomersRequest());
     while (await call.ResponseStream.MoveNext())
     {
         var customer = call.ResponseStream.Current;
         DisplayCustomer(customer);
     }
 }
Esempio n. 21
0
		//This method is used for Unary RPC
		private static async Task CustomerInfoMethod(int userId, Customer.CustomerClient customerClient)
		{
			var clientRequestId = new CustomerLookUpModel()
			{
				UserId = userId
			};

			var customer = await customerClient.GetCustomerInfoAsync(clientRequestId);

			Console.WriteLine($"{customer.FirstName} {customer.LastName}");
		}
Esempio n. 22
0
        static async Task Main(string[] args)
        {
            var channel        = GrpcChannel.ForAddress("https://localhost:5001");
            var customerClient = new Customer.CustomerClient(channel);

            Console.WriteLine("Name: ");
            var input           = Console.ReadLine();
            var clientRequested = new CustomerLookupModel {
                Name = input.ToString()
            };
            var customer = await customerClient.GetCustomerInfoAsync(clientRequested);
        }
Esempio n. 23
0
        static async void Request2()
        {
            var input = new CustomerLookupModel {
                UserId = 1
            };

            var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client  = new Customer.CustomerClient(channel);

            var reply = await client.GetCustomerInfoAsync(input);

            Console.WriteLine($"{reply.FirstNmae}{reply.LastNmae}");
        }
Esempio n. 24
0
        public async Task <CustomerResponse> Get([Required] Guid id)
        {
            var response = await GrpcCallerService.CallService(urlGrpc : GRPCUrl.IdentityService, logger : _logger, func : async channel =>
            {
                var client = new Customer.CustomerClient(channel);
                _logger.LogDebug("Grpc get customer request request {@request}", id);
                return(await client.GetCustomerAsync(new CustomerItemRequest {
                    Id = id.ToString()
                }));
            });

            return(response);
        }
Esempio n. 25
0
        public async Task <CustomerResponse> UpdateCustomer([Required] CustomerUpdateRequest customerRequest)
        {
            var response = await GrpcCallerService.CallService(urlGrpc : GRPCUrl.IdentityService, logger : _logger, func : async channel =>
            {
                var client = new Customer.CustomerClient(channel);
                _logger.LogDebug("Grpc get customer request {@request}", customerRequest);
                var customer = await client.UpdateCustomerAsync(customerRequest);
                await UpdateProductCustomer(customer, false);
                return(customer);
            });

            return(response);
        }
Esempio n. 26
0
        public async static void GetCustomer(Customer.CustomerClient client, string Id)
        {
            var customer = new CustomerRequest {
                Id = Id
            };

            using var response = client.GetCustomer(customer);
            while (await response.ResponseStream.MoveNext(new System.Threading.CancellationToken()))
            {
                var thisProduct = response.ResponseStream.Current;
                Console.WriteLine($"id: {thisProduct.Id}");
            }
        }
Esempio n. 27
0
        public async Task <PaginatedCustomerResponse> Get([Required] CustomerItemsRequest request)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("Invalid model");
            }
            var response = await GrpcCallerService.CallService(urlGrpc : GRPCUrl.IdentityService, logger : _logger, func : async channel =>
            {
                var client = new Customer.CustomerClient(channel);
                _logger.LogDebug("Grpc get customer request request {@request}", request);
                return(await client.GetCustomersAsync(request));
            });

            return(response);
        }
Esempio n. 28
0
        public async Task <CustomerResponse> DeleteCustomer([Required] Guid id)
        {
            var response = await GrpcCallerService.CallService(urlGrpc : GRPCUrl.IdentityService, logger : _logger, func : async channel =>
            {
                var client = new Customer.CustomerClient(channel);
                _logger.LogDebug("Grpc delete customer request {@request}", id);
                var customer = await client.DeleteCustomerAsync(new CustomerItemRequest {
                    Id = id.ToString()
                });
                await UpdateProductCustomer(customer, true);
                return(customer);
            });

            return(response);
        }
Esempio n. 29
0
        private static async Task CustomersUsingExample(ChannelBase channel)
        {
            Console.WriteLine("Customers:");
            var id = 4;

            Console.WriteLine($"Get customer info for id {id}: ");

            var client   = new Customer.CustomerClient(channel);
            var customer = await GetCustomerAsync(client, id);

            DisplayCustomer(customer);

            Console.WriteLine();

            Console.WriteLine("Get all customers:");
            await GetAndDisplayAllCustomers(client);
        }
Esempio n. 30
0
        //changing the method from void Main to async Task Main allows for async calls
        static async Task Main(string[] args)
        {
            //hello request
            //var input = new HelloRequest
            //{
            //    Name = "Ionut"
            //};
            //var channel = GrpcChannel.ForAddress("https://localhost:5001");
            ////setting up a client
            ////instantiating gRPC server call
            //var client = new Greeter.GreeterClient(channel);
            ////getting the reply
            //var reply = await client.SayHelloAsync(input);

            //Console.WriteLine(reply.Message);

            var channel        = GrpcChannel.ForAddress("https://localhost:5001");
            var customerClient = new Customer.CustomerClient(channel);

            var clientRequested = new CustomerLookupModel
            {
                UserId = 1
            };

            var customer = await customerClient.GetCustomerInfoAsync(clientRequested);

            Console.WriteLine($"{customer.FirstName } {customer.LastName} ");
            Console.WriteLine();
            Console.WriteLine("New Customer List");
            Console.WriteLine();

            using (var call = customerClient.GetNewCustomers(new NewCustomerRequest()))
            {
                //loops through every customer in the list, until the stream ends
                //when it's done, we received every new customer
                while (await call.ResponseStream.MoveNext())
                {
                    var currentCustomer = call.ResponseStream.Current;

                    Console.WriteLine($"{currentCustomer.FirstName } {currentCustomer.LastName}: {currentCustomer.EmailAddress} ");
                }
            }

            Console.ReadLine();
        }