async static Task HandleUnaryCallWithMultiResponse(Ticker.TickerClient client, int?count = null) { MultipleTicksRequest request = null; if (count == null) { request = new MultipleTicksRequest { EmptyRequest = new EmptyRequest() }; } else { request = new MultipleTicksRequest { TicksRequested = new TicksForRequest { Count = (int)count } }; } var reply = await client.GetTicksAsync(request); if (reply.Code == GrpcProtoLibrary.Protos.Ticker.StatusCode.Error) { Console.WriteLine("Error occured while retriving data!!!"); return; } foreach (var tick in reply.Ticks) { WriteSingleTick(tick); } }
async static Task ServerStreamingHandling(Ticker.TickerClient client) { using (var call = client.GetStreamOfTicks(new EmptyRequest())) { await foreach (var tick in call.ResponseStream.ReadAllAsync()) { WriteSingleTick(tick); } } }
static async Task DeleteTickHandling(Ticker.TickerClient client, int id) { var request = new TickSearchRequest { TickId = id }; var reply = await client.DeleteTickAsync(request); Console.WriteLine(reply.Message); }
async static Task HandleCreateTick(Ticker.TickerClient client, TickToAdd tick) { var reply = await client.CreateTickAsync(tick); if (reply.Code == GrpcProtoLibrary.Protos.Ticker.StatusCode.Error) { Console.WriteLine("error occured while creating new tick"); return; } Console.WriteLine(reply.Message); }
private static async Task Main(string[] args) { GrpcChannel channel = GrpcChannel.ForAddress("https://localhost:45679"); var httpsClientTicker = new Ticker.TickerClient(channel); GrpcChannel authChannel = GrpcChannel.ForAddress("https://localhost:56790"); var httpsClient = new Auth.AuthClient(authChannel); var interceptorHttps = channel.Intercept(new HeaderLoggerInterceptor()); var healthChecker = new Health.HealthClient(interceptorHttps); string serviceName = "Ticker"; var result = await healthChecker.CheckAsync(new HealthCheckRequest { Service = serviceName }); Console.WriteLine(result?.Status); /* var reply = await httpsClient.LogInAsync(new LogInRequest { Username = "******", Password = "******" }); * var replyUser = await httpsClient.LogInAsync(new LogInRequest { Username = "******", Password = "******" }); * * var tokenAdmin = * await Authenticate(reply.Role); * * var tokenUser = await Authenticate(replyUser.Role); * * * Console.WriteLine(tokenAdmin); * Console.WriteLine(tokenUser); * * await ClientStreaming(httpsClientTicker, 1, tokenUser); * * * * /*await UpdateTickHandling(httpsClient, * new TickToAdd * { * InstrumentId = 1, * Close = (DecimalValue)5.6234m, * Open = (DecimalValue)5.6225m, * High = (DecimalValue)5.6238m, * Low = (DecimalValue)5.6224m, * Symbol = 2 * }); * await GetTicksForQuota(httpsClient, 1);*/ //await ClientStreaming(httpsClient, 1); Console.WriteLine("Press any key to close app..."); Console.ReadLine(); }
static async Task GetTicksForQuota(Ticker.TickerClient client, int symbolId) { var reply = await client.GetTickForSymbolAsync(new SymbolSearchRequest { SymbolId = symbolId }); if (reply.Code == GrpcProtoLibrary.Protos.Ticker.StatusCode.Error) { Console.WriteLine("error occured while retriving data"); return; } foreach (var tick in reply.Ticks) { WriteSingleTick(tick); } }
async static Task HandleSingleCall(Ticker.TickerClient client, int id) { var request = new TickSearchRequest { TickId = id }; var reply = await client.GetTickAsync(request); if (reply.Code == GrpcProtoLibrary.Protos.Ticker.StatusCode.Success) { WriteSingleTick(reply); } else { Console.WriteLine("Error while retriving data from server!!!"); } }
static async Task ClientStreaming(Ticker.TickerClient client, int symbolId, string token) { var header = new Metadata(); header.Add("Authorization", $"Bearer {token}"); var options = new CallOptions(header); using (var call = client.ClientStreaming(options)) { for (int i = 0; i < 5; i++) { var request = GenerateRequest(symbolId); await call.RequestStream.WriteAsync(request); await Task.Delay(3000); } await call.RequestStream.CompleteAsync(); var response = await call; Console.WriteLine(response.Message); } }
static async Task UpdateTickHandling(Ticker.TickerClient client, TickToAdd tickToAdd) { var reply = await client.UpdateTickAsync(tickToAdd); Console.WriteLine(reply.Message); }