public override Task <QuizeMessage> GetQuizeByID( QuizeIdMessage request, ServerCallContext context) { var result = new QuizeMessage { Id = 19, Name = "Bla bla quize", Description = "some more bla bla ", QuestionList = { new QuestionMessage { Id = 21, Text = "question1" }, new QuestionMessage { Id = 23, Text = "question3", Answers = { { true, "this is good" }, { false, "this is not so good" } } }, } }; return(Task.FromResult(result)); }
public override Task <QuizeIdMessage> CreateQuize( QuizeMessage request, ServerCallContext context) { //Create quize var result = new QuizeIdMessage { Id = 100 }; return(Task.FromResult(result)); }
static async System.Threading.Tasks.Task Main(string[] args) { Console.WriteLine("Hello World!"); var conf = new MapperConfiguration(ce => {//https://dotnetfiddle.net/RPWSUd ce.CreateMap <Quize, QuizeMessage>().ReverseMap(); ce.CreateMap <Question, QuestionMessage>().ReverseMap(); ce.CreateMap(typeof(IEnumerable <>), typeof(RepeatedField <>)).ConvertUsing(typeof(EnumerableToRepeatedFieldTypeConverter <,>)); ce.CreateMap(typeof(RepeatedField <>), typeof(List <>)).ConvertUsing(typeof(RepeatedFieldToListTypeConverter <,>)); ce.ForAllPropertyMaps( map => map.DestinationType.IsGenericType && map.DestinationType.GetGenericTypeDefinition() == typeof(RepeatedField <>), (map, options) => options.UseDestinationValue()); //.ForAllOtherMembers( //options => options.Condition((src, dest, srcValue) => srcValue != null)); }); var mapper = new Mapper(conf); // The port number(5001) must match the port of the gRPC server. var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new QuizeDefinition.QuizeDefinitionClient(channel); var request = new QuizeIdMessage { Id = 1 }; QuizeMessage reply = client.GetQuizeByID(request); var mapped = mapper.Map <Quize>(reply); var questions = mapper.Map <List <Question> >(reply.QuestionList); mapped.Questions = questions; Console.WriteLine($"{reply.Id}, {reply.Name}, {reply.Description}, {reply.QuestionList?.Count}"); var quizeItems = new List <QuizeMessage>(); using (var call = client.GetQuizeList(request)) { while (await call.ResponseStream.MoveNext()) { var item = call.ResponseStream.Current; quizeItems.Add(item); Console.WriteLine($"{item.Id}, {item.Name}, {item.Description}, {item.QuestionList?.Count}"); } } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public override async Task GetQuizeList( QuizeIdMessage request, IServerStreamWriter <QuizeMessage> responseStream, ServerCallContext context) { var result = new List <QuizeMessage>() { new QuizeMessage { Id = 19, Name = "Bla bla quize", Description = "some more bla bla ", QuestionList = { new QuestionMessage { Id = 21, Text = "question1" }, new QuestionMessage { Id = 23, Text = "question3", Answers = { { true, "this is good" }, { false, "this is not so good" } } }, } }, new QuizeMessage { Id = 29, Name = "Bla bla quize", Description = "some more bla bla ", QuestionList = { new QuestionMessage { Id = 25, Text = "question2" }, new QuestionMessage { Id = 24, Text = "question4", Answers = { { true, "this is good" }, { false, "this is not so good" } } }, } }, new QuizeMessage { Id = 39, Name = "Bla bla quize", Description = "some more bla bla ", QuestionList = { new QuestionMessage { Id = 26, Text = "question1" }, new QuestionMessage { Id = 27, Text = "question3", Answers = { { true, "this is good" }, { false, "this is not so good" } } }, } } }; foreach (var item in result) { await responseStream.WriteAsync(item); } }
public override Task <Empty> DeleteQuize(QuizeIdMessage request, ServerCallContext context) { //…code to delete a customer… return(Task.FromResult(new Empty())); }