public async Task GetData(Notifier.NotifierClient client)
        {
            DataRequest request = new DataRequest {
            };

            using (var call = client.Data(request))
            {
                var responseStream = call.ResponseStream;

                while (await responseStream.MoveNext())
                {
                    DataReply dataReply = responseStream.Current;
                    timerTick(dataReply.ProductName, dataReply.ProductPrice);
                }
            }
        }
            public async Task Data()
            {
                DataRequest request = new DataRequest {
                };

                using (var call = client.Data(request))
                {
                    var responseStream = call.ResponseStream;
                    while (await responseStream.MoveNext())
                    {
                        StringBuilder responseLog = new StringBuilder();

                        DataReply dataReply = responseStream.Current;
                        responseLog.Append(dataReply);

                        // Original Position: outside current loop
                        Console.WriteLine(responseLog.ToString());
                    }
                }
            }
예제 #3
0
        private static DataReply GetRowReplyFromReader(ulong row, DbDataReader reader)
        {
            var values = new object[reader.FieldCount];
            var len    = reader.GetProviderSpecificValues(values);

            var rowReply = new DataReply {
                RowNumber = (uint)row
            };

            for (ulong index = 0; index < (uint)len; index++)
            {
                var value = values[index];
                rowReply.Data.Add(value.ToString());
                if (value == DBNull.Value)
                {
                    rowReply.NullIndexes.Add((uint)index);
                }
            }
            return(rowReply);
        }
예제 #4
0
        private static void OnTimerElapsed(object sender, ElapsedEventArgs e, WeatherDataSender.WeatherDataSenderClient client)
        {
            //Create new random data.
            WeatherData weatherData = new WeatherData();
            DataRequest request     = new DataRequest()
            {
                Time          = weatherData.Timestamp,
                Temperature   = weatherData.Temperature,
                Humidity      = weatherData.Humidity,
                WindDirection = weatherData.WindDirection,
                Windspeed     = weatherData.WindSpeed,
                AtmPressure   = weatherData.AtmosphericPressure
            };

            //Start the stopwatch and send the data.
            stopwatch.Start();
            DataReply response = client.SendData(request);

            //Stop the stopwatch when a response is received. Log the response and reset the timer.
            stopwatch.Stop();
            Console.WriteLine("Response: " + response.Message);
            Console.WriteLine($"Response time: {stopwatch.ElapsedMilliseconds} ms");
            stopwatch.Reset();
        }
        public Task <WeatherForecast[]> GetForecastAsync(DateTime startDate)
        {
            var       channel  = GrpcChannel.ForAddress("https://localhost:5001");
            var       client   = new Greeter.GreeterClient(channel);
            DataReply response = client.GetData(new DataRequest()
            {
                Name = "Berlin"
            });
            RootObject             res = Newtonsoft.Json.JsonConvert.DeserializeObject <RootObject>(response.Message);
            List <WeatherForecast> lstWeatherForecast = new List <WeatherForecast>();

            foreach (Location local in res.observations.location)
            {
                foreach (Observation obs in local.observation)
                {
                    WeatherForecast oWeather = new WeatherForecast();
                    oWeather.Date         = res.feedCreation;
                    oWeather.TemperatureC = obs.temperature;
                    oWeather.Summary      = string.Format("latitude  {0}, longitude {1}", local.latitude, local.longitude);
                    lstWeatherForecast.Add(oWeather);
                }
            }
            return(Task.FromResult(lstWeatherForecast.ToArray()));
        }