public void NewModuleDetected(string serialNumber)
        {
            var lat = GPSDataProvider.GetAverageLatitude(DateTime.Now.ToUniversalTime().AddSeconds(-3), DateTime.Now.ToUniversalTime());
            var lng = GPSDataProvider.GetAverageLongitude(DateTime.Now.ToUniversalTime().AddSeconds(-3), DateTime.Now.ToUniversalTime());

            foreach (var sn in AggregateDataProvider.SerialNumbersOnTruckIncludingBuffered)
            {
                if (sn != serialNumber && !ModulesOnTruck.Any(t => t.SerialNumber == sn))
                {
                    ModulesOnTruck.Add(new ModuleViewModel {
                        SerialNumber = sn, Latitude = lat, Longitude = lng, Loaded = true
                    });
                }
            }
            SerialNumber = serialNumber;
        }
Ejemplo n.º 2
0
        private void ProcessTagUnloadingMessage(TagUnloadingMessage msg)
        {
            Task.Run(() =>
            {
                if (!_windowService.IsWindowOpen(WindowType.WaitingForUnloadWindow))
                {
                    using (var uow = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                    {
                        Logging.Logger.Log("DEBUG", "Processing unload message from home view model.");
                        DateTime gpsStart = DateTime.Now.ToUniversalTime().AddSeconds(-3);
                        DateTime gpsEnd   = DateTime.Now.ToUniversalTime();

                        double latitude  = GPSDataProvider.GetAverageLatitude(gpsStart, gpsEnd);
                        double longitude = GPSDataProvider.GetAverageLongitude(gpsStart, gpsEnd);


                        /*if (_windowService.IsWindowOpen(WindowType.PickupWindow))
                         * {
                         *  _windowService.CloseModalWindow(WindowType.PickupWindow);
                         * }*/

                        System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            UnloadingAtGinViewModel vm = SimpleIoc.Default.GetInstance <UnloadingAtGinViewModel>();
                            vm.SerialNumber            = msg.SerialNumber;
                            vm.Refresh();
                            if (!_windowService.IsWindowOpen(WindowType.UnloadingAtGin))
                            {
                                vm.Initialize();
                                _windowService.ShowModalWindow(WindowType.UnloadingAtGin, vm);
                            }
                            else
                            {
                                vm.Refresh();
                            }
                        }));
                    }
                }
            });
        }
Ejemplo n.º 3
0
        private void ProcessTagLoadingMessage(TagLoadingMessage msg)
        {
            Task.Run(() =>
            {
                using (var uow = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                {
                    DateTime gpsStart = DateTime.Now.ToUniversalTime().AddSeconds(-4);
                    DateTime gpsEnd   = DateTime.Now.ToUniversalTime();

                    double latitude  = GPSDataProvider.GetAverageLatitude(gpsStart, gpsEnd);
                    double longitude = GPSDataProvider.GetAverageLongitude(gpsStart, gpsEnd);

                    //PickupListEntity pickupList = uow.PickupListRepository.GetListIDWithSerialNumber(msg.SerialNumber);

                    //IF LOADING WINDOW NOT OPEN AND WE ARE ON THE GIN YARD

                    /*if (!_windowService.IsWindowOpen(WindowType.LoadingWindow) && (uow.SettingsRepository.CoordsAtFeeder(latitude, longitude) || uow.SettingsRepository.CoordsOnGinYard(latitude, longitude)))
                     * {
                     *  if (!_windowService.IsWindowOpen(WindowType.LoadingAtGin))
                     *  {
                     *      Logging.Logger.Log("DEBUG", "Processing load message from home view model for gin load.");
                     *      //we are at the gin yard or feeder so just show loading window with no list checks
                     *      System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                     *      {
                     *          LoadingAtGinViewModel vm = SimpleIoc.Default.GetInstance<LoadingAtGinViewModel>();
                     *          vm.SerialNumber = msg.SerialNumber;
                     *          vm.Initialize();
                     *          _windowService.ShowModalWindow(WindowType.LoadingAtGin, vm);
                     *      }));
                     *  }
                     *  else
                     *  {
                     *      System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                     *      {
                     *          LoadingAtGinViewModel vm = SimpleIoc.Default.GetInstance<LoadingAtGinViewModel>();
                     *          vm.AddModule(msg.SerialNumber);
                     *      }));
                     *  }
                     * }
                     * else
                     * {*/
                    Logging.Logger.Log("DEBUG", "Processing load message from home view model.");
                    //if we're in the field then
                    if (!_windowService.IsWindowOpen(WindowType.PickupWindow))
                    {
                        System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            PickUpListViewModel vm = SimpleIoc.Default.GetInstance <PickUpListViewModel>();

                            if (this.SelectedItem != null)
                            {
                                vm.ListID = this.SelectedItem.ListID;
                            }
                            else
                            {
                                vm.ListID = GUIDS.UNASSIGNED_LIST_ID;
                            }

                            vm.InitiatingEvent = msg;
                            _windowService.ShowModalWindow(WindowType.PickupWindow, vm);
                        }));
                    }
                    //}
                }
            });
        }
        private void ProcessTagLoadingMessage(TagLoadingMessage msg)
        {
            if (!_windowService.IsWindowOpen(WindowType.LoadingAtGin))
            {
                Task.Run(() =>
                {
                    Logging.Logger.Log("DEBUG", "Processing tag loading message from pickup list " + msg.SerialNumber);
                    using (var uow = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                    {
                        System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            DateTime gpsStart = DateTime.Now.ToUniversalTime().AddSeconds(-3);
                            DateTime gpsEnd   = DateTime.Now.ToUniversalTime();

                            double latitude  = GPSDataProvider.GetAverageLatitude(gpsStart, gpsEnd);
                            double longitude = GPSDataProvider.GetAverageLongitude(gpsStart, gpsEnd);

                            //if we're not at the gin yard or feeder - we must be loading in the field
                            //if (!uow.SettingsRepository.CoordsAtFeeder(latitude, longitude) && !uow.SettingsRepository.CoordsOnGinYard(latitude, longitude))
                            // {
                            bool moduleOnList = this.Modules.Any(m => m.SerialNumber.Trim().ToLower() == msg.SerialNumber.Trim().ToLower());

                            if (moduleOnList && !_windowService.IsWindowOpen(WindowType.LoadingIncorrectModuleWindow) && !_windowService.IsWindowOpen(WindowType.WaitingForUnloadWindow))
                            {
                                if (!_windowService.IsWindowOpen(WindowType.LoadingWindow))
                                {
                                    LoadingWindowViewModel vm = SimpleIoc.Default.GetInstance <LoadingWindowViewModel>();
                                    vm.SerialNumber           = msg.SerialNumber;
                                    vm.Initialize(this.ListID);
                                    _windowService.ShowModalWindow(WindowType.LoadingWindow, vm);
                                }
                                else //window is already open but another module passed under antenna view
                                {
                                    LoadingWindowViewModel vm = SimpleIoc.Default.GetInstance <LoadingWindowViewModel>();
                                    vm.NewModuleDetected(msg.SerialNumber);
                                }
                            }
                            else //we're in the incorrect module sequence or we detected an incorrect module previously
                            {
                                if (_windowService.IsWindowOpen(WindowType.LoadingWindow))
                                {
                                    _windowService.CloseModalWindow(WindowType.LoadingWindow);
                                }

                                if (!_windowService.IsWindowOpen(WindowType.LoadingIncorrectModuleWindow))
                                {
                                    if (_windowService.IsWindowOpen(WindowType.WaitingForUnloadWindow))
                                    {
                                        _windowService.CloseModalWindow(WindowType.WaitingForUnloadWindow);
                                    }

                                    if (_windowService.IsWindowOpen(WindowType.UnloadCorrectionWindow))
                                    {
                                        _windowService.CloseModalWindow(WindowType.UnloadCorrectionWindow);
                                    }

                                    incorrectModuleVM.ActiveListID = this.ListID;
                                    incorrectModuleVM.ListName     = this.ListName;
                                    incorrectModuleVM.Client       = this.Client;
                                    incorrectModuleVM.Farm         = this.Farm;
                                    incorrectModuleVM.Field        = this.Field;
                                    incorrectModuleVM.Initialize(false);
                                    incorrectModuleVM.NewModuleLoaded(msg.SerialNumber, moduleOnList);
                                    _windowService.ShowModalWindow(WindowType.LoadingIncorrectModuleWindow, incorrectModuleVM);
                                }
                                else //window is already open
                                {
                                    incorrectModuleVM.NewModuleLoaded(msg.SerialNumber, moduleOnList);
                                }
                            }


                            //}

                            Logging.Logger.Log("DEBUG", "Done Processing tag loading message from pickup list " + msg.SerialNumber);
                        }));
                    }
                });
            }
        }