private async Task <bool> CallServiceForLargeNumberNotification(int value)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    var randomNumberMessage = new RandomNumberRequest()
                    {
                        number = value
                    };

                    var jsonString   = JsonConvert.SerializeObject(randomNumberMessage);
                    var httpResponse = await httpClient.PostAsync(NotificationEndpoint, new StringContent(jsonString, Encoding.UTF8, "application/json"));

                    if (httpResponse.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        return(true);
                    }
                }
            }
            catch
            {
                return(false);
            }

            return(false);
        }
Ejemplo n.º 2
0
 public override Task GenerateRandomNumbers(RandomNumberRequest request, IServerStreamWriter <RandomNumberResponse> responseStream, Grpc.Core.ServerCallContext context)
 {
     return(Task.Run(async() =>
     {
         for (var counter = 0; counter < request.Count; counter++)
         {
             await Task.Delay(request.DelayInMs);
             await responseStream.WriteAsync(new RandomNumberResponse()
             {
                 RequestId = request.RequestId,
                 RandomNumber = new Random().NextDouble()
             });
         }
     }));
 }