Exemplo n.º 1
0
 private void DeviceLocationChanged(object sender, DeviceLocationChangedEventArgs e)
 {
     logger.Debug($"DeviceLocationChanged {e.GPSData.First().Latitude}");
 }
Exemplo n.º 2
0
        private void DeviceLocationChanged(object sender, DeviceLocationChangedEventArgs e)
        {
            try
            {
                logger.Info("DeviceLocationChanged");

                foreach (var i in e.GPSData)
                {
                    Device device;
                    lock (devices)
                    {
                        device = devices.FirstOrDefault(r => r.ID == i.DeviceID);

                        if (device == null)
                        {
                            devices.Clear();
                            devices = m_client.LoadRegisteredDevicesFromServer();

                            foreach (var dev in m_client.LoadUnregisteredDevicesFromServer())
                            {
                                dev.Name = "Radio " + dev.RadioID;
                                devices.Add(dev);
                            }

                            device = devices.FirstOrDefault(r => r.ID == i.DeviceID);
                        }
                    }

                    if (device != null)
                    {
                        StringBuilder build = new StringBuilder();
                        build.Append("DeviceLocationChanged");
                        build.Append("device: " + device.Name + " ");
                        build.Append("Altitude: " + i.Altitude + " ");
                        build.Append("Description: " + i.Description + " ");
                        build.Append("DeviceID: " + i.DeviceID + " ");
                        build.Append("Direction: " + i.Direction + " ");
                        build.Append("GpsSource: " + i.GpsSource + " ");
                        build.Append("InfoDate: " + i.InfoDate.ToString() + " ");
                        build.Append("InfoDateUtc: " + i.InfoDateUtc.ToString() + " ");
                        build.Append("Latitude: " + i.Latitude.ToString() + " ");
                        build.Append("Name: " + i.Name + " ");
                        build.Append("Radius: " + i.Radius.ToString() + " ");
                        build.Append("ReportId: " + i.ReportId.ToString() + " ");
                        build.Append("Rssi: " + i.Rssi.ToString() + " ");
                        build.Append("Speed: " + i.Speed.ToString() + " ");
                        build.Append("StopTime: " + i.StopTime.ToString() + " ");

                        logger.Info(build.ToString());

                        if (i.Longitude != 0 && i.Longitude != 0)
                        {
                            var gpsInfo = new GPSLocation();
                            gpsInfo.deviceName = device.Name;
                            gpsInfo.RadioID = device.RadioID;
                            gpsInfo.Latitude = i.Latitude;
                            gpsInfo.Longitude = i.Longitude;
                            gpsInfo.Rssi = i.Rssi;

                            PostGpsLocation(gpsInfo);
                        }

                        PostDeviceLifeSign(device.Name, device.RadioID, true);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, ex);
            }
        }
Exemplo n.º 3
0
        private void DeviceLocationChanged(object sender, DeviceLocationChangedEventArgs e)
        {
            try
            {
                logger.Info("DeviceLocationChanged");

                foreach (var gpsInfo in e.GPSData)
                {
                    try
                    {
                        int deviceID = gpsInfo.DeviceID;

                        GpsMeasurement gpsMeasurement = new GpsMeasurement
                        {
                            Latitude  = gpsInfo.Latitude,
                            Longitude = gpsInfo.Longitude,
                            Timestamp = gpsInfo.InfoDate.ToString(), // right formatting?
                            Rssi      = gpsInfo.Rssi,
                            DeviceID  = deviceID,
                        };

                        DeviceInfo deviceInfo;
                        if (!GetDeviceInfoByDeviceID(deviceID, out deviceInfo))
                        {
                            logger.Warn($"Could not find deviceInfo to update GPSfor device with, created it for deviceID {deviceID} ");
                            devices.TryAdd(deviceID, new DeviceInfo(deviceID));
                        }

                        int radioID = deviceInfo.RadioID;
                        gpsMeasurement.RadioID = radioID;
                        deviceInfo.GpsLocations.Push(gpsMeasurement);

                        // Previous existing logging magic
                        StringBuilder build = new StringBuilder();
                        build.Append("DeviceLocationChanged");
                        build.Append("Altitude: " + gpsInfo.Altitude + " ");
                        build.Append("Description: " + gpsInfo.Description + " ");
                        build.Append("DeviceID: " + gpsInfo.DeviceID + " ");
                        build.Append("Direction: " + gpsInfo.Direction + " ");
                        build.Append("GpsSource: " + gpsInfo.GpsSource + " ");
                        build.Append("InfoDate: " + gpsInfo.InfoDate.ToString() + " ");
                        build.Append("InfoDateUtc: " + gpsInfo.InfoDateUtc.ToString() + " ");
                        build.Append("Latitude: " + gpsInfo.Latitude.ToString() + " ");
                        build.Append("Name: " + gpsInfo.Name + " ");
                        build.Append("Radius: " + gpsInfo.Radius.ToString() + " ");
                        build.Append("ReportId: " + gpsInfo.ReportId.ToString() + " ");
                        build.Append("Rssi: " + gpsInfo.Rssi.ToString() + " ");
                        build.Append("Speed: " + gpsInfo.Speed.ToString() + " ");
                        build.Append("StopTime: " + gpsInfo.StopTime.ToString() + " ");

                        logger.Info(build.ToString());

                        PostGpsLocation(gpsMeasurement);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, $"Adding location failed for deviceID {gpsInfo?.DeviceID}");
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, ex);
            }
        }