// Check if there is already a response from this device, we are not doing duplicates
 private bool IsNewResponseForPing(PingDiagnostic tripData, PingDiagnosticResponse response)
 {
     if (tripData == null || response == null)
     {
         return(false);
     }
     return(!tripData.Responders.Any(r => r.Channel == response.Channel && r.ReceiverIdentifier == response.ReceiverIdentifier));
 }
        private string FormatReply(PingDiagnosticResponse r)
        {
            string resp = $"{{{r.ReceiveTime.ToString("HH:mm:ss.fff")}|{r.ReceiverIdentifier}";

            resp += $"|channel:{r.Channel.ToString()}";
            resp += $"|gsm:{r.DeviceDetail.CellularType}:{r.DeviceDetail.CellularProvider}:{r.DeviceDetail.CellularSignalStrength}";
            resp += $"|wifi:{r.DeviceDetail.WifiProvider}:{r.DeviceDetail.WifiSignalStrength}";
            resp += $"|batt:{r.DeviceDetail.BatteryPercentage}";
            resp += $"|vol:{r.DeviceDetail.VolumePercentage}}}";
            return(resp);
        }
        public PingLookupResult RegisterTripResponse(PingDiagnostic tripData, PingDiagnosticResponse response)
        {
            //If the tripdata was not ours we skip processing and signal that it's not our process for now
            if (tripData == null)
            {
                return(PingLookupResult.Invalid);
            }

            if (IsNewResponseForPing(tripData, response))
            {
                tripData.Responders.Add(response);
            }
            else
            {
                logger.LogDebug($"Response on ping {tripData.SessionIdentifier}|{tripData.PingIdentifier} by {response.ReceiveTime} over {response.Channel} is already processed, skipping duplicate");
            }
            return(PingLookupResult.Found); //whether or not we were allowed to process this
        }
Esempio n. 4
0
 private void RegisterPongResponse(PingDiagnostic diagnostic, PingDiagnosticResponse response)
 {
     logger.LogInformation($"Writing response: {response.ReceiverIdentifier} for ping {diagnostic.PingIdentifier}");
     RunQuery(SQLStoreResponse, new {
         SessionIdentifier      = diagnostic.SessionIdentifier,
         PingIdentifier         = diagnostic.PingIdentifier,
         ReceiverIdentifer      = response.ReceiverIdentifier,
         ReceiveTime            = response.ReceiveTime,
         Channel                = response.Channel.ToString(),
         CellularType           = response.DeviceDetail.CellularType,
         CellularProvider       = response.DeviceDetail.CellularProvider,
         CellularSignalStrength = response.DeviceDetail.CellularSignalStrength,
         WifiProvider           = response.DeviceDetail.WifiProvider,
         WifiSignalStrength     = response.DeviceDetail.WifiSignalStrength,
         BatteryPercentage      = response.DeviceDetail.BatteryPercentage,
         VolumePercentage       = response.DeviceDetail.VolumePercentage
     });
 }
 public PingLookupResult RegisterTripResponse(PingDiagnosticResponse response)
 {
     logger.LogDebug($"Got response for {response.PingIdentifier} from {response.ReceiverIdentifier}");
     try
     {
         if (MulticastPings.ContainsKey(response.PingIdentifier))
         {
             var rt = MulticastPings[response.PingIdentifier];
             return(RegisterTripResponse(rt, response));
         }
         else
         {
             //In theory the process can crash if the key is removed after the first if, locking here might be a too large impact so we allow it here and let the error handling take care of that case
             logger.LogWarning($"Cannot process {response.Channel} from {response.ReceiverIdentifier}, ping {response.SessionIdentifier}|{response.PingIdentifier} was already purged");
             return(PingLookupResult.NotInCollection);
         }
     }
     catch (Exception e)
     {
         logger.LogWarning($"Cannot process {response.Channel} from {response.ReceiverIdentifier}, for: {response.SessionIdentifier}|{response.PingIdentifier} -> {e.Message}");
         return(PingLookupResult.NotInCollection);
     }
 }