コード例 #1
0
        private IEnumerable <Measurement> GetSensorMeasurements(Sensor sensor)
        {
            if (!SavedState.NextMeasurementTimeBySensorSerial.TryGetValue(sensor.Serial, out var lastSeenTime))
            {
                lastSeenTime = DateTime.UtcNow.Date.AddDays(-Context.NewSensorSyncDays);
            }

            if (Context.SyncFromUtc.HasValue)
            {
                lastSeenTime = Context.SyncFromUtc.Value;
            }

            var request = new GetMeasurementsRequest
            {
                OrganisationId = sensor.OrganisationId,
                SensorSerial   = sensor.Serial,
                StartTime      = lastSeenTime,
                Order          = "asc"
            };

            do
            {
                var response = Client.Get(request);

                foreach (var measurement in response.Measurements)
                {
                    yield return(measurement);
                }

                request.Start = response.Next;
            } while (!string.IsNullOrEmpty(request.Start));
        }
コード例 #2
0
        public GetMeasurementsResponse GetMeasurements(GetMeasurementsRequest request)
        {
            int totalRecords;
            var data = SortData(request.Search, request.SortingDictionary, out totalRecords);

            if (request.Take != -1)
            {
                data = data.Skip(request.Skip).Take(request.Take);
            }

            return(new GetMeasurementsResponse
            {
                TotalRecords = totalRecords,
                Measurements = data.ToList().MapTo <GetMeasurementsResponse.Measurement>()
            });
            //var measurements = new List<Measurement>();
            //if (request.Take != 0)
            //{
            //    measurements = DataContext.Measurements.OrderBy(x => x.Id).Skip(request.Skip).Take(request.Take).ToList();
            //}
            //else
            //{
            //    measurements = DataContext.Measurements.OrderBy(x => x.Id).ToList();
            //}
            //var response = new GetMeasurementsResponse();
            //response.Measurements = measurements.MapTo<GetMeasurementsResponse.Measurement>();
            //return response;
        }
コード例 #3
0
        private GetMeasurementsResponse SendGetMeasurementRequest(Gateway gateway, KellerDevice device)
        {
            var uriBuilder = new UriBuilder("", gateway.GatewayIp, gateway.GatewayPort, ApiUrl);
            var channel    = new Channel(uriBuilder.ToString(), ChannelCredentials.Insecure);

            var client  = new Kiwi.Api.MeasurementService.MeasurementServiceClient(channel);
            var request = new GetMeasurementsRequest {
                DevEui = device.EUI
            };
            var reply = client.Get(request);

            channel.ShutdownAsync().Wait();
            return(reply);
        }
コード例 #4
0
ファイル: MeasurementService.cs プロジェクト: yhsantosa/Pear
        public GetMeasurementsResponse GetMeasurements(GetMeasurementsRequest request)
        {
            var measurements = new List <Measurement>();

            if (request.Take != 0)
            {
                measurements = DataContext.Measurements.OrderBy(x => x.Id).Skip(request.Skip).Take(request.Take).ToList();
            }
            else
            {
                measurements = DataContext.Measurements.OrderBy(x => x.Id).ToList();
            }
            var response = new GetMeasurementsResponse();

            response.Measurements = measurements.MapTo <GetMeasurementsResponse.Measurement>();
            return(response);
        }