示例#1
0
        private void ExecuteSyncCommand()
        {
            Task.Run(() =>
            {
                if (!SyncHelper.HasConnection())
                {
                    Messenger.Default.Send <BusyMessage>(new BusyMessage {
                        IsBusy = true, Message = "No network.  Unable to sync."
                    });
                    System.Threading.Thread.Sleep(3000);
                    Messenger.Default.Send <BusyMessage>(new BusyMessage {
                        IsBusy = false, Message = ""
                    });
                    return;
                }

                Messenger.Default.Send <BusyMessage>(new BusyMessage {
                    IsBusy = true, Message = "Syncing..."
                });

                if (PBISyncHelper.IsRunning)
                {
                    PBISyncHelper.WaitForCompletion();
                }
                PBISyncHelper.RunSync();
                PBISyncHelper.WaitForCompletion();
                Messenger.Default.Send <BusyMessage>(new BusyMessage {
                    IsBusy = false, Message = ""
                });
            });
        }
示例#2
0
        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 PBI Logger data?", "Confirm", System.Windows.MessageBoxButton.YesNo);
                }));

                if (msgResult == System.Windows.MessageBoxResult.Yes)
                {
                    if (CottonDBMS.DataModels.Helpers.NetworkHelper.HasNetwork())
                    {
                        if (PBISyncHelper.IsRunning)
                        {
                            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."
                            });
                            PBISyncHelper.RunSync();
                            PBISyncHelper.WaitForCompletion();
                        }

                        Messenger.Default.Send <BusyMessage>(new BusyMessage {
                            IsBusy = true, Message = "Clearing data..."
                        });
                        using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                        {
                            dp.BaleScanRepository.ClearScanData();
                            dp.SettingsRepository.UpsertSetting(BridgeSettingKeys.LAST_SYNC_TIME, DateTime.Now.AddYears(-1).ToString());
                            dp.SaveChanges();
                        }

                        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 handleWeightAcquired(WeightAcquiredMessage msg)
        {
            if (waitingForWeight)
            {
                try
                {
                    using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                    {
                        var scanNumber = dp.BaleScanRepository.LastScanNumber();
                        var scan       = dp.BaleScanRepository.FindSingle(s => s.ScanNumber == scanNumber);
                        if (scan != null && scan.Created >= DateTime.Now.AddMinutes(-5))
                        {
                            scan.ScaleWeight   = msg.Weight;
                            scan.SyncedToCloud = false;
                            scan.Source        = InputSource.TRUCK;
                            dp.BaleScanRepository.Save(scan);
                            dp.SaveChanges();

                            var displayedScan = PBIScans.FirstOrDefault(s => s.Barcode == scan.PbiNumber);

                            //update weight on displayed scan
                            if (displayedScan != null)
                            {
                                displayedScan.Weight = scan.NetLintBaleWeight;
                            }

                            Task.Run(() =>
                            {
                                if (PBISyncHelper.IsRunning)
                                {
                                    PBISyncHelper.WaitForCompletion();
                                }
                                PBISyncHelper.RunSync();
                            });
                        }
                    }
                }
                catch (Exception exc)
                {
                    Logging.Logger.Log(exc);
                }
                waitingForWeight = false;
            }
        }
        private void handleBarCodeScanned(BarcodeScannedMessage msg)
        {
            if (msg.Data.Length != 12)
            {
                return;
            }

            using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                BaleScanEntity scan = new BaleScanEntity();

                long newPBINumber = 0;

                if (!long.TryParse(msg.Data, out newPBINumber))
                {
                    newPBINumber = 0;
                }

                if (lastPBINumber == newPBINumber)
                {
                    return;
                }

                scan.OutOfSequence = (lastPBINumber != 0) && newPBINumber != (lastPBINumber + 1);

                lastPBINumber      = newPBINumber;
                scan.ScanNumber    = dp.BaleScanRepository.LastScanNumber() + 1;
                scan.PbiNumber     = msg.Data;
                scan.Name          = msg.Data;
                scan.Processed     = false;
                scan.SyncedToCloud = false;
                scan.ScaleWeight   = _weight;
                scan.TareWeight    = decimal.Parse(dp.SettingsRepository.GetSettingWithDefault(BridgeSettingKeys.TARE_WEIGHT, "0"));
                dp.BaleScanRepository.Save(scan);
                dp.SaveChanges();
                waitingForWeight = true;
                Logging.Logger.Log("SCAN", scan.ToString());

                System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
                {
                    if (PBIScans.Count() >= 200)
                    {
                        PBIScans.RemoveAt(PBIScans.Count() - 1);
                    }

                    PBIScans.Insert(0, new ScanItemViewModel {
                        Barcode = scan.Name, OutOfSequence = scan.OutOfSequence, TimeStamp = scan.LastCreatedOrUpdated, Weight = scan.NetLintBaleWeight
                    });
                }));


                Task.Run(() =>
                {
                    if (PBISyncHelper.IsRunning)
                    {
                        PBISyncHelper.WaitForCompletion();
                    }
                    PBISyncHelper.RunSync();
                });
            }
        }