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(); }
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(); }
public override Task <CustomerModel> GetCustomerInfo(CustomerLookupModel request, ServerCallContext context) { Console.WriteLine("Hello, " + request.Name); return(Task.FromResult(new CustomerModel { })); }
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(); }
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(); }
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(); }
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 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(); }
public override async Task GetCrowdInfoFromId(CustomerLookupModel request, IServerStreamWriter <CustomerModel> responseStream, ServerCallContext context) { foreach (var id in new int[] { 1, 2, 3, 4 }) { await responseStream.WriteAsync(GetFakePerson(id)); } }
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(); }
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(); }
public override Task <CustomerModel> GetCustomerInfo(CustomerLookupModel request, ServerCallContext context) { CustomerModel output = new CustomerModel(); switch (request.UserId) { case 1: output.FirstName = "Vijay"; output.LastName = "A"; output.Emailaddress = "*****@*****.**"; output.IsAlive = true; output.Age = 25; break; case 2: output.FirstName = "Joe"; output.LastName = "Smith"; output.Emailaddress = "*****@*****.**"; output.IsAlive = true; output.Age = 35; break; default: output.FirstName = "John"; output.LastName = "Doe"; output.Emailaddress = "*****@*****.**"; output.IsAlive = true; output.Age = 45; break; } return(Task.FromResult(output)); }
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); }
public override Task <CustomerModel> GetCustomerInfo(CustomerLookupModel request, ServerCallContext context) { CustomerModel output = new CustomerModel(); if (request.UserId == 1) { output.FirstName = "Gevorg"; output.Lastname = "Asryan"; } return(Task.FromResult(output)); }
public override Task <CustomerModel> GetCustomerInfo(CustomerLookupModel request, ServerCallContext context) { return(Task.FromResult(new CustomerModel() { Age = 22, EmailAddress = "*****@*****.**", FirstName = "Pera", LastName = "Pera", IsAlive = true })); }
public override Task <CustomerModel> GetCustomerInfo( CustomerLookupModel request, ServerCallContext context ) { CustomerModel output = new CustomerModel(); output.FirstName = "Tom"; output.LastName = "Fong"; return(Task.FromResult(output)); }
public override Task <CustomerModel> GetCustomerInfo(CustomerLookupModel request, ServerCallContext context) { CustomerModel output = new CustomerModel { EmailAddress = "*****@*****.**", FirstName = "roonz", LastName = "moneypenny", IsAtive = true }; return(Task.FromResult(output)); }
public override Task <CustomerModel> GetCustomerInfo( CustomerLookupModel request, ServerCallContext context) { var customer = _repository.GetCustomer(request.UserId); if (customer == null) { return(Task.FromResult(new CustomerModel())); } return(Task.FromResult(_mapper.Map <CustomerModel>(customer))); }
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); }
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}"); }
public override Task <CustomerModel> GetCustomerInfo(CustomerLookupModel request, ServerCallContext context) { var output = new CustomerModel(); switch (request.UserId) { default: output = DefaultCustomerModelResponse; break; } return(Task.FromResult(output)); }
public override Task <CustomerModel> GetCustomerInfo(CustomerLookupModel request, ServerCallContext context) { CustomerModel output = new CustomerModel(); if (request.UserId == 1) { output.FirstName = "Afifah"; output.LastName = "Tasneem"; } if (request.UserId == 2) { output.FirstName = "Omar"; output.LastName = "Abdullah"; } return(Task.FromResult(output)); }
public override Task <CustomerModel> GetCustomerInfo(CustomerLookupModel request, ServerCallContext context) { var data = request.UserId; CustomerModel output = new CustomerModel(); Console.WriteLine("data: " + data); DateTime dt; if (DateTime.TryParse(data, out dt)) { String.Format("{0:d/MM/yyyy}", dt); Console.WriteLine("zodie: " + GetHoroscop(dt)); } return(Task.FromResult(output)); }
//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(); }
public override Task <CustomerModel> GetCustomerInfo(CustomerLookupModel request, ServerCallContext context) { CustomerModel output = request.UserId switch { 1 => new CustomerModel { FirstName = "A", LastName = "A" }, 2 => new CustomerModel { FirstName = "B", LastName = "B" }, _ => new CustomerModel { FirstName = "C", LastName = "C" }, }; return(Task.FromResult(output)); }
//Beispielvideo YouTube -> https://www.youtube.com/watch?v=QyxCX2GYHxk static async Task Main(string[] args) { #region Hallo Welt Beispiel //var input = new HelloRequest { Name = "Tim" }; //var channel = GrpcChannel.ForAddress("https://localhost:5001"); //var client = new Greeter.GreeterClient(channel); //var reply = await client.SayHelloAsync(input); //Console.WriteLine(reply.Message); Console.WriteLine("Hello World!"); #endregion #region Übertragen und Anzeigen eines komplexen Objektes 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.LastName}"); #endregion #region Übertragen von Listen using (var call = customerClient.GetNewCustomers(new NewCustomerRequest())) { while (await call.ResponseStream.MoveNext()) { var currentCustomer = call.ResponseStream.Current; Console.WriteLine($"{currentCustomer.FirstName} {currentCustomer.LastName}:{currentCustomer.EmaiAdress}"); } } #endregion Console.ReadLine(); }
static async Task testing_customer(int userId) { var customerClient = new Customer.CustomerClient(channel); var clientRequested = new CustomerLookupModel { UserId = userId }; var customer = await customerClient.GetCustomerInfoAsync(clientRequested); Console.WriteLine($"{customer.FName} {customer.LName}"); Console.WriteLine(); Console.WriteLine("New customer List : "); using (var call = customerClient.GetNewCustomers(new NewCustomerRequest())) { while (await call.ResponseStream.MoveNext()) { var currentCustomer = call.ResponseStream.Current; Console.WriteLine($"{currentCustomer.FName} {currentCustomer.LName} : {currentCustomer.Email}"); } } }
static async Task Main(string[] args) { var personGenerator = new PersonGenerator(); var person = personGenerator.GetNewPerson(); var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channel); Console.WriteLine("Hello from client"); var input = new HelloRequest { Name = person.FullName }; var reply = await client.SayHelloAsync(input); Console.WriteLine(reply.Message); var customerService = new Customer.CustomerClient(channel); var customerId = new CustomerLookupModel { UserId = new Random().Next(1, 100) }; var userFound = customerService.GetCustomerInfo(customerId); Console.WriteLine($"Name: {userFound.Fullname}\nEmailAddress:{userFound.EmailAddress}\nGender:{userFound.Gender}\nId:{userFound.UserId}"); //var input2 = new CrowdLookupModel { UserIds = new Google.Protobuf.Collections.RepeatedField<CustomerLookupModel> { customerId, customerId } }; var cancel = new CancellationToken(); using (var call = customerService.GetCrowdInfoFromId(customerId)) { while (await call.ResponseStream.MoveNext(cancel)) { var current = call.ResponseStream.Current; Console.WriteLine($"Name: {current.Fullname}"); } } Console.ReadLine(); }
static async Task Main(string[] args) { //// configuracion del canal, escuchando al servidor de grpc //var channel = GrpcChannel.ForAddress("https://localhost:5001"); //var client = new Greeter.GreeterClient(channel); //var input = new HelloRequest { Name="Leo" }; //var reply = await client.SayHelloAsync(input); //Console.WriteLine(reply.Message); //----------------------------------------------------- var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Customer.CustomerClient(channel); var input = new CustomerLookupModel { UserId = 2 }; var reply = await client.GetCustomerInfoAsync(input); Console.WriteLine($"{reply.FirstName}, {reply.LastName}"); Console.WriteLine("---------------"); //----------------------------------------------------- using (var call = client.GetNewCustomers(new NewCustomerRequest())) { while (await call.ResponseStream.MoveNext()) { var currentCustomer = call.ResponseStream.Current; Console.WriteLine($"{currentCustomer.FirstName} {currentCustomer.LastName}"); } } Console.ReadLine(); }
public override Task <CustomerModel> GetCustomerInfo(CustomerLookupModel request, ServerCallContext context) { CustomerModel output = new CustomerModel(); if (request.UserId == 1) { output.FirstName = "Bob"; output.SecondName = "Dylan"; } else if (request.UserId == 2) { output.FirstName = "Bon"; output.SecondName = "Jovi"; } else { output.FirstName = "Joe"; output.SecondName = "Nickleson"; } return(Task.FromResult(output)); }