예제 #1
0
        private void Connect()
        {
            try
            {
                lock (ConnectLock)
                {
                    if (!Connected)
                    {
                        if (Properties.Settings.Default.Simulation)
                        {
                            var gpsInfo = new GPSLocation();
                            gpsInfo.deviceName = "test";
                            gpsInfo.Latitude = 52.4897266086191;
                            gpsInfo.Longitude = 6.13765982910991;
                            gpsInfo.Rssi = (float)-59.5864372253418;

                            PostGpsLocation(gpsInfo);

                            PostDeviceLifeSign("test-online", 1, true);
                            PostDeviceLifeSign("test-offline", 2, false);

                        }
                        else
                        {
                            ConnectToTurboNet();
                        }

                        watchdogTimer.Start();

                        ConnectButton.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { ConnectButton.IsEnabled = false; }));
                        urlTextBox.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { urlTextBox.IsEnabled = false; }));
                        SimulationCheckBox.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { SimulationCheckBox.IsEnabled = false; }));

                        Connected = true;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, ex);
            }
        }
예제 #2
0
        private async void PostGpsLocation(GPSLocation gps)
        {
            try
            {
                string json = JsonConvert.SerializeObject(gps, Formatting.None);
                logger.Info("PostGpsLocation " + json);

                var content = new StringContent(json, Encoding.UTF8, "application/json");
                var result = await httpClient.PostAsync(Properties.Settings.Default.CdbUrl, content);

                logger.Info("PostObject :" + result.StatusCode);

                if (result.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    logger.Info("Error with PostGpsLocation " + json);
                }
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, ex);
            }
        }
예제 #3
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);
            }
        }
예제 #4
0
 private bool sterf(GPSLocation gps)
 {
     return(sterf(gps.RadioID));
 }