private Telegram ParseTelegram(string sensorId, TextTelegram textTelegram) { Telegram telegram = null; try { this.m_logger.Info($"Origin sensor: {sensorId}."); telegram = this.m_parserClient.Parse(textTelegram.Telegram); telegram.SensorId = sensorId; telegram.Timestamp = textTelegram.Timestamp; if (textTelegram.Longitude > 0D && textTelegram.Latitude > 0D) { telegram.Latitude = textTelegram.Latitude; telegram.Longitude = textTelegram.Longitude; } } catch (ServerTooBusyException ex) { this.m_logger.Error("DSMR parser timeout. Is the remote up?", ex); this.m_logger.Error($"Telegram text: {textTelegram.Telegram}"); } catch (FaultException ex) { this.m_logger.Error("Error in the DSMR parser service.", ex); this.m_logger.Error($"Telegram text: {textTelegram.Telegram}"); } catch (CommunicationException ex) { this.m_logger.Error("Unknown DSMR parsing exception.", ex); this.m_logger.Error($"Telegram text: {textTelegram.Telegram}"); if (this.m_parserClient.State == CommunicationState.Faulted) { this.m_parserClient = new ParserServiceClient(EndpointConfigName); } } return(telegram); }
public static TextTelegram Convert(ControlMessage message) { var telegram = new TextTelegram(); var token = JToken.Parse(message.Data); if (token["latitude"] != null && token["longitude"] != null) { telegram.Latitude = token["latitude"].ToObject <double>(); telegram.Longitude = token["longitude"].ToObject <double>(); } else { telegram.Longitude = telegram.Latitude = 0D; } if (token["telegram"] == null) { throw new InvalidOperationException("Unable to parse telegram without a telegram."); } telegram.Timestamp = token["timestamp"].ToObject <DateTime>(); var base64 = token["telegram"].ToString(); var bytes = System.Convert.FromBase64String(base64); telegram.Telegram = Encoding.UTF8.GetString(bytes); return(telegram); }