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;
        }
        private void connectToReader()
        {
            try
            {
                if (!TagDataProvider.IsConnected)
                {
                    Logging.Logger.Log("INFO", "READER NOT CONNECTED");

                    if (ReaderStatus == "CONNECTED")
                    {
                        Logging.Logger.Log("INFO", "READER CHANGE FROM CONNECTED TO DISCONNECTED");
                    }

                    using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                    {
                        var setting = dp.SettingsRepository.GetSettingWithDefault(BridgeSettingKeys.READER_HOST_NAME, "169.254.1.1");
                        TagDataProvider.SetHostName(setting);
                        TagDataProvider.Connect();
                        //System.Threading.Thread.Sleep(1000);
                    }
                }

                if (!TagDataProvider.IsConnected)
                {
                    ReaderStatus = "DISCONNECTED";
                }
                else
                {
                    if (ReaderStatus == "DISCONNECTED")
                    {
                        Logging.Logger.Log("INFO", "READER RE-CONNECTED");
                    }


                    ReaderStatus = "CONNECTED";
                    if (!readerTimeSet)
                    {
                        readerTimeSet = true;
                        TagDataProvider.Stop();
                        TagDataProvider.SyncReaderTime();
                        //TagDataProvider.Disconnect();
                    }
                }

                if (TagDataProvider.IsConnected && !TagDataProvider.IsSingulating())
                {
                    System.Threading.Thread.Sleep(500);

                    TagDataProvider.Start(0);

                    if (!TagDataProvider.IsSingulating())
                    {
                        TagDataProvider.Stop();
                        TagDataProvider.Disconnect();
                    }
                }
            }
            catch (Exception readerExc)
            {
                ReaderStatus = "ERROR";
                Logging.Logger.Log(readerExc);
            }
        }