private void ExecuteSyncCommand()
        {
            Task.Run(() =>
            {
                try
                {
                    if (BridgeSyncProcessHelper.SyncProcessRunning())
                    {
                        Messenger.Default.Send <BusyMessage>(new BusyMessage {
                            IsBusy = true, Message = "Performing data sync."
                        });
                        CottonDBMS.DataModels.Helpers.NetworkHelper.WaitForSyncToStop();
                        Messenger.Default.Send <BusyMessage>(new BusyMessage {
                            IsBusy = false, Message = ""
                        });
                    }
                    else
                    {
                        if (!CottonDBMS.DataModels.Helpers.NetworkHelper.HasNetwork())
                        {
                            Messenger.Default.Send <BusyMessage>(new BusyMessage {
                                IsBusy = true, Message = "No network.  Unable to sync."
                            });
                            System.Threading.Thread.Sleep(4000);
                            Messenger.Default.Send <BusyMessage>(new BusyMessage {
                                IsBusy = false, Message = ""
                            });
                            return;
                        }

                        Messenger.Default.Send <BusyMessage>(new BusyMessage {
                            IsBusy = true, Message = "Performing data sync."
                        });
                        BridgeSyncProcessHelper.RunSync(System.Reflection.Assembly.GetExecutingAssembly().Location, false);
                        Messenger.Default.Send <BusyMessage>(new BusyMessage {
                            IsBusy = false, Message = ""
                        });
                    }
                    Messenger.Default.Send <DataRefreshedMessage>(new DataRefreshedMessage());
                }
                catch (Exception exc)
                {
                    Logging.Logger.Log(exc);
                    Messenger.Default.Send <BusyMessage>(new BusyMessage {
                        IsBusy = false, Message = ""
                    });
                }
            });
        }
        private void ExecuteClearCommand()
        {
            Task.Run(() =>
            {
                System.Windows.MessageBoxResult msgResult = System.Windows.MessageBoxResult.No;
                System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
                {
                    msgResult = System.Windows.MessageBox.Show("Are you sure you want to clear all data stored on the bridge?", "Confirm", System.Windows.MessageBoxButton.YesNo);
                }));

                if (msgResult == System.Windows.MessageBoxResult.Yes)
                {
                    if (CottonDBMS.DataModels.Helpers.NetworkHelper.HasNetwork())
                    {
                        if (BridgeSyncProcessHelper.SyncProcessRunning())
                        {
                            Messenger.Default.Send <BusyMessage>(new BusyMessage {
                                IsBusy = true, Message = "Waiting for background sync to complete."
                            });
                            BridgeSyncProcessHelper.WaitForSyncToStop();
                        }
                        else
                        {
                            //run the sync to send data collected this also ensure after it completes
                            //it will not start again during the reset operation
                            Messenger.Default.Send <BusyMessage>(new BusyMessage {
                                IsBusy = true, Message = "Sending collected data."
                            });
                            BridgeSyncProcessHelper.RunSync(System.Reflection.Assembly.GetExecutingAssembly().Location, false);
                            BridgeSyncProcessHelper.WaitForSyncToStop();
                        }

                        Messenger.Default.Send <BusyMessage>(new BusyMessage {
                            IsBusy = true, Message = "Clearing data..."
                        });
                        using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                        {
                            dp.TruckRepository.ClearTruckData();
                            dp.LoadScanRepository.ClearBridgeScanData();
                            dp.TruckRepository.ClearClientFarmFieldData();
                            dp.FeederScanRepository.ClearBridgeScanData();
                            dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.LAST_SYNC_TIME, DateTime.Now.AddYears(-1).ToString());
                            dp.SaveChanges();
                            TagDataProvider.ClearBuffer();
                        }

                        Messenger.Default.Send <BusyMessage>(new BusyMessage {
                            IsBusy = false, Message = ""
                        });
                        Messenger.Default.Send <DataRefreshedMessage>(new DataRefreshedMessage());
                    }
                    else
                    {
                        System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            msgResult = System.Windows.MessageBox.Show("Cannot clear data no network connection");
                        }));
                    }
                }
            });
        }