public static DynamoMonthlyMeasurementModel Map(ProcessedMeasurementEvent newMeasurementEvent)
        {
            var measurementFields = MapFields(newMeasurementEvent.MeasurementFields);

            return(new DynamoMonthlyMeasurementModel(newMeasurementEvent.Id, newMeasurementEvent.MeasurementDate)
            {
                Chan = newMeasurementEvent.Channel,
                DeviceId = newMeasurementEvent.User.UserId,

                SId = newMeasurementEvent.SampleId,

                BattPc = newMeasurementEvent.BatteryLevelPercentage,
                RfPc = newMeasurementEvent.RfStrength,

                Fields = measurementFields,
                Tags = GetTags(newMeasurementEvent),
                Location = MapLocation(newMeasurementEvent.Location),

                DeleteAfter = newMeasurementEvent.DeleteAfter,
                Expires = newMeasurementEvent.Expires,
                Source = (int)newMeasurementEvent.Source
            });
        }
        public async Task <ProcessedMeasurementEvent> ProcessAsync(NewMeasurementEvent newMeasurementEvent)
        {
            if (newMeasurementEvent.UserId == Guid.Empty)
            {
                _logger.LogInformation("Not persisting measurement {0} as invalid user id. {1}",
                                       newMeasurementEvent.Id,
                                       newMeasurementEvent.UserId);
                return(null);
            }

            try
            {
                Measurement measurement = MapFromNewMeasurementEvent(newMeasurementEvent);

                User device = await _membershipService.LoadAsync(newMeasurementEvent.AccountId, newMeasurementEvent.UserId);

                if (device == null)
                {
                    return(null);
                }

                Measurement processedMeasurement = await ProcessMeasurementAsync(measurement, device, newMeasurementEvent.RemapOldFields);

                ProcessedMeasurementEvent processedMeasurementEvent = CreateProcessedMeasurementEvent(processedMeasurement, device);

                await _membershipService.UpdateFieldsAsync(device, processedMeasurementEvent);

                return(processedMeasurementEvent);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to process new measurement.");
                // re-throw so that messaging keeps the message.
                throw;
            }
        }
Beispiel #3
0
 private async Task PublishProcessedMeasurements(ProcessedMeasurementEvent processedMeasurementEvent)
 {
     await _processedMeasurementStreamWriter.PushStreamAsync(processedMeasurementEvent);
 }
Beispiel #4
0
 /// <summary>
 /// Notify the membership about any new fields that are on the device.
 ///
 /// Note that this will cause a UserUpdated event that updates the local cached user object.
 /// </summary>
 /// <param name="device"></param>
 /// <param name="processedMeasurementEvent"></param>
 /// <returns></returns>
 public async Task UpdateFieldsAsync(User device, ProcessedMeasurementEvent processedMeasurementEvent)
 {
     await CheckDeviceHasAllFieldsAsync(processedMeasurementEvent, device);
 }
 public async Task PushStreamAsync(ProcessedMeasurementEvent processedMeasurementEvent)
 {
     await Push(processedMeasurementEvent, processedMeasurementEvent.User.AccountId);
 }
 /// <summary>
 /// Publish the ProcessedMeasurementEvent from the Measurements service
 /// (i.e. the new event)
 /// </summary>
 private async Task PublishProcessedMeasurementEvent(ProcessedMeasurementEvent processedMeasurementEvent)
 {
     await _bus.PublishAsync(processedMeasurementEvent);
 }