private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { try { Messenger.Default.Unregister <FirstSetupWizardComplete>(this); CottonDBMS.TruckApp.Tasks.TruckPullFromCloudTask.Cancel(); AggregateDataProvider.Cleanup(); TagDataProvider.Disconnect(); GPSDataProvider.Disconnect(); QuadratureEncoderDataProvider.Dispose(); Logging.Logger.CleanUp(); base.OnClosed(e); } catch (Exception exc) { System.Diagnostics.Trace.Write(exc.Message); } //if (ConfigurationManager.AppSettings["AllowStartupAndShutdown"].ToLower() == "true") //System.Diagnostics.Process.Start("Shutdown", "-s -t 10"); }
private void initialize() { if (vm == null) { vm = SimpleIoc.Default.GetInstance <NavViewModel>(); DataContext = vm; unlockSettingsControl.DataContext = vm; passwordModalControl.DataContext = vm; busyModal.DataContext = vm; } this.Visibility = Visibility.Visible; //check for gps offsett setting using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork()) { var repo = dp.SettingsRepository; var offsetSetting = repo.FindSingle(s => s.Key == TruckClientSettingKeys.GPS_OFFSET_FEET); if (offsetSetting == null) { repo.UpsertSetting(TruckClientSettingKeys.GPS_OFFSET_FEET, "45"); GPSDataProvider.SetGpsOffsetFeet(45.0); } else { GPSDataProvider.SetGpsOffsetFeet(double.Parse(offsetSetting.Value)); } } if (!vm.HasCloudSettings) { MessageBox.Show("Data sync settings have not been configured. Please configure then restart the application."); navTabControl.SelectedIndex = 2; } else { Task.Run(() => { try { try { if (!TagDataProvider.IsConnected) { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Looking for RFID reader..." }); //System.Threading.Thread.Sleep(35000); int tryNumber = 1; do { //todo fix error hangs when no reader on rugged pc TagDataProvider.Connect(); tryNumber++; System.Threading.Thread.Sleep(3000); } while (tryNumber < 10 && !TagDataProvider.IsConnected); //Messenger.Default.Send<BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Connecting to RFID reader..." }); //TagDataProvider.Connect(); //System.Threading.Thread.Sleep(1400); } if (!TagDataProvider.IsConnected) { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Not connected to RFID Reader." }); System.Threading.Thread.Sleep(1200); } else { TagDataProvider.Stop(); Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "RFID Reader found." }); TagDataProvider.SyncReaderTime(); System.Threading.Thread.Sleep(1200); } } catch (Exception readerExc) { Logging.Logger.Log(readerExc); } Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Initializing shaft sensor..." }); QuadratureEncoderDataProvider.StartEvents(); System.Threading.Thread.Sleep(1000); if (!QuadratureEncoderDataProvider.IsStarted) { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Shaft Sensor not found." }); System.Threading.Thread.Sleep(1200); } if (!GPSDataProvider.IsConnected) { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Connecting to GPS receiver..." }); Task.Run(() => { GPSDataProvider.Connect(); }); int waitCount = 0; while (waitCount < 60 && !GPSDataProvider.IsConnected) { System.Threading.Thread.Sleep(500); waitCount++; } if (GPSDataProvider.IsConnected) { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "GPS connected." }); System.Threading.Thread.Sleep(1000); } else { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "GPS not connected." }); System.Threading.Thread.Sleep(2000); } } Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = false, Message = "" }); TagDataProvider.Initialize(); AggregateDataProvider.Initialize(); CottonDBMS.TruckApp.Tasks.TruckPullFromCloudTask.Init(); readerSettingsControl.Initialize(); } catch (Exception exc) { CottonDBMS.Logging.Logger.Log(exc); } }); } navTabControl.Height = canvasLayout.ActualHeight; navTabControl.Width = canvasLayout.ActualWidth; modalBG.Height = canvasLayout.ActualHeight; modalBG.Width = canvasLayout.ActualWidth; }