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 (BridgeSyncTask.SyncProcessRunning()) { Messenger.Default.Send <BusyMessage>(new BusyMessage { IsBusy = true, Message = "Waiting for background sync to complete." }); BridgeSyncTask.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." }); BridgeSyncTask.RunSync(System.Reflection.Assembly.GetExecutingAssembly().Location, false); BridgeSyncTask.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.SaveChanges(); TagDataProvider.ClearBuffer(); dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.LAST_SYNC_TIME, DateTime.Now.AddYears(-1).ToString()); } 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"); })); } } }); }
/* private void Timer_Elapsed(object sender, ElapsedEventArgs e) * { * if (!executingTimer) //prevent long execution of handler from overlapping later callbacks * { * executingTimer = true; * using (var dp = SimpleIoc.Default.GetInstance<IUnitOfWorkFactory>().CreateUnitOfWork()) * { * lock (_trucks) * { * _trucks = dp.TruckRepository.GetAll().ToList(); * } * } * executingTimer = false; * } * }*/ public void Initialize() { using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork()) { GinName = dp.SettingsRepository.GetSettingWithDefault(BridgeSettingKeys.GIN_NAME, ""); WelcomeMessage = "WELCOME, TO " + GinName; TagDataProvider.ClearBuffer(); } }
private void handleTagsReported(List <TagItem> tagsReported) { try { TagItem truckTag = null; TruckEntity selectedTruck = null; lock (_trucks) { /*foreach (var tag in tagsReported) * { * Logging.Logger.Log("INFO", "EPC: " + tag.Epc + " SN: " + tag.SerialNumber + " ANTENNA PORT: " + tag.AntennaePort.ToString() + " FIRST SEEN LOCAL TIME: " + tag.Firstseen.ToLocalTime().ToString() + " PEAK RSSI: " + tag.PeakRSSI.ToString() + " PHASE ANGLE: " + tag.PhaseAngle.ToString()); * }*/ var truckTagIds = _trucks.Select(t => t.RFIDTagId).ToArray(); truckTag = tagsReported.FirstOrDefault(t => truckTagIds.Contains(t.SerialNumber) || truckTagIds.Contains(t.Epc)); if (truckTag != null) { using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork()) { selectedTruck = dp.TruckRepository.FindSingle(t => t.RFIDTagId == truckTag.SerialNumber || t.RFIDTagId == truckTag.Epc); var lastLoad = dp.LoadScanRepository.LastLoad(); if (lastLoad != null && lastLoad.TruckID == selectedTruck.Name && lastLoad.Created.AddMinutes(15) > DateTime.UtcNow) { selectedTruck = null; Logging.Logger.Log("INFO", "Truck Tag ignored: " + truckTag.SerialNumber); TagDataProvider.ClearBuffer(); } } } if (selectedTruck != null) { Logging.Logger.Log("INFO", "Truck Tag for truck: " + selectedTruck.Name + " scanned. Starting weigh in."); //check to see if this truck var vm = new WeighInPageViewModel(NavService); //TagDataProvider.ClearBuffer(); NavService.ShowPage(PageType.WEIGHT_IN_PAGE, false, (BasePageViewModel)vm); vm.Initialize(selectedTruck); } else { //TagDataProvider.ClearBuffer(); } } } catch (Exception exc) { Logging.Logger.Log(exc); Logging.Logger.WriteBuffer(); } }
private void handleTagsReported(List <TagItem> tagsReported) { using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork()) { foreach (var t in tagsReported) { var existingScan = dp.FeederScanRepository.FindSingle(s => s.Name == t.SerialNumber); if (existingScan == null) { Initialize(t.SerialNumber, t.Epc, false); } } TagDataProvider.ClearBuffer(); } }
private void handleTagsReported(List <TagItem> tagsReported) { using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork()) { foreach (var t in tagsReported) { var existingScan = dp.FeederScanRepository.FindSingle(s => s.Name == t.SerialNumber); if (existingScan == null) { var vm = new ModuleScanViewModel(NavService); NavService.ShowPage(PageType.FEEDER_MODULE_PAGE, false, vm); System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => { vm.Initialize(t.SerialNumber, t.Epc, true); })); } } TagDataProvider.ClearBuffer(); } }
public void Initialize() { using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork()) { TagDataProvider.SetGPOState(1, false); TagDataProvider.SetGPOState(2, false); TagDataProvider.SetGPOState(3, false); GinName = dp.SettingsRepository.GetSettingWithDefault(BridgeSettingKeys.GIN_NAME, ""); WelcomeMessage = "WELCOME, TO " + GinName; TagDataProvider.ClearBuffer(); Logging.Logger.WriteBuffer(); /*Task.Run(() => * { * TagDataProvider.DisconnectIfUptimeLimitReached(1); * });*/ lock (_trucks) { _trucks = dp.TruckRepository.GetAll().ToList(); } } }
private void ExecuteClearRFIDCommand() { RFIDEvents.Clear(); TagDataProvider.ClearBuffer(); }
private void ExecuteClearAllCommand() { Task.Run(async() => { 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 truck including module history, pickup lists, clients, farms, and fields? Data already sent to gin will not be deleted from the gin database.", "Confirm", System.Windows.MessageBoxButton.YesNo); })); if (msgResult == System.Windows.MessageBoxResult.Yes) { if (CottonDBMS.DataModels.Helpers.NetworkHelper.HasNetwork()) { if (CottonDBMS.DataModels.Helpers.NetworkHelper.SyncProcessRunning()) { Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Waiting for background sync to complete." }); CottonDBMS.DataModels.Helpers.NetworkHelper.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 Messages.BusyMessage { IsBusy = true, Message = "Sending collected data." }); CottonDBMS.DataModels.Helpers.NetworkHelper.RunSync(System.Reflection.Assembly.GetExecutingAssembly().Location, false); CottonDBMS.DataModels.Helpers.NetworkHelper.WaitForSyncToStop(); } Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage { IsBusy = true, Message = "Clearing data..." }); using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork()) { dp.TruckRepository.ClearTruckData(); dp.TruckRepository.ClearClientFarmFieldData(); AggregateDataProvider.Reset(); TagDataProvider.ClearBuffer(); var truck = dp.SettingsRepository.GetCurrentTruck(); if (truck != null) { await DocumentDBContext.DeleteItemAsync <TruckListsDownloaded>("TRUCKDOWNLOADS_" + truck.Id); } } Messenger.Default.Send <BusyMessage>(new Messages.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"); })); } } }); }