public NewTicketViewModel() { NewTicketViewModel.logger.Debug("VIEWMODEL LOADING: NewTicketViewModel"); AuthenticationService.Instance.SuspendService = false; this.OpenTickets = new ObservableCollection <TicketViewModel>(); this.Categories = new ObservableCollection <Category>(); this.UnitOfWork = new UnitOfWork(); this.LoadCategories(); SplashScreenHelper.ShowText(Resources.SplashScreenLoadingProducts); SplashScreenHelper.Close(); if (AuthenticationService.Instance.AuthenticatedMember == null) { LockScreenHelper.Show(); } this.CurrentTicket = new TicketViewModel() { Ticket = new Ticket(), Visibility = Visibility.Collapsed, NewTicket = true, ItemSelectedCommand = (ICommand) new RelayCommand(new Action(this.SelectedItemChanged)) }; this.OpenTickets.Add(this.CurrentTicket); this.OpenCheckoutSheet = this.UnitOfWork.CheckoutSheetRepository.GetLastOpenSheet(); if (this.OpenCheckoutSheet == null) { if (NavigatorHelper.NavigationService == null) { return; } NavigatorHelper.NavigationService.Navigate(new Uri("Views/NewTicket/NewCheckoutSheetPageView.xaml", UriKind.Relative)); NavigatorHelper.NavigationService.RemoveBackEntry(); } else { try { foreach (Ticket ticket in this.UnitOfWork.TicketRepository.GetOpenTicketsNoTracking()) { this.OpenTickets.Add(new TicketViewModel() { Ticket = ticket, TicketControlClicked = (ICommand) new RelayCommand <TicketViewModel>(new Action <TicketViewModel>(this.TicketSelected)) }); } } catch (SqlException ex) { SplashScreenHelper.CloseInstant(); int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand); NewTicketViewModel.logger.Error("Database error: {0}", ex.Message); } catch (DataException ex) { SplashScreenHelper.CloseInstant(); int num = (int)WPFMessageBox.Show(Resources.ExceptionDbWarning + ex.Message, Resources.ExceptionDbWarningTitle, MessageBoxButton.OK, MessageBoxImage.Hand); NewTicketViewModel.logger.Error("Database error: {0}", ex.Message); } NewTicketViewModel.logger.Debug("VIEWMODEL LOADED: NewTicketViewModel"); } }
private void retry() { _retryCountDownTimer = new DispatcherTimer(); _retryCountDownTimer.Tick += (_, a) => { // countdown reached zero, let's try to log back in if (_retryInterval-- == 0) { _retryCountDownTimer.Stop(); _retryInterval = RETRY_INTERVAL; check(); } else { SplashScreenHelper.ShowText("There was a problem accessing your profile. Trying again in " + _retryInterval + " seconds"); } }; _retryCountDownTimer.Interval = new TimeSpan(0, 0, 0, 1); _retryCountDownTimer.IsEnabled = true; _retryCountDownTimer.Start(); }
private void check() { var clientid = (int)IPdevices.Properties.Settings.Default["clientid"]; var deviceid = (int)IPdevices.Properties.Settings.Default["deviceid"]; if (clientid > 0) { try { SplashScreenHelper.ShowText("Looking for profile..."); using (ipdevicesEntities ipde = new ipdevicesEntities()) { // does the client actually exist? if (ipde.clients.Any(o => o.uid == clientid)) { Console.WriteLine("Client id " + clientid + " was found"); SplashScreenHelper.ShowText("Profile found!"); var cl = new client(); cl = ipde.clients.Find(clientid); SplashScreenHelper.ShowText("Looking for registered device..."); // check for registered devices device dev = null; if (cl.devices.Where(d => d.did == deviceid).DefaultIfEmpty(null).FirstOrDefault() != null) { SplashScreenHelper.ShowText("Device found!"); dev = ipde.devices.Find(deviceid); } // give client information and device information main = new Main(cl, dev); // apply the proper datacontet to the notify icon notifyIcon = (TaskbarIcon)FindResource("MyNotifyIcon"); notifyIcon.DataContext = new NotifyIconViewModel((MainViewModel)main.DataContext); SplashScreenHelper.Close(); main.Show(); } else { // well clientid was found in settings, but it doesn't exist in the db. Then just make sure that we reset settings too! Console.WriteLine("Client id " + clientid + " not found in db, resetting settings to default 0"); IPdevices.Properties.Settings.Default.clientid = 0; IPdevices.Properties.Settings.Default.deviceId = 0; IPdevices.Properties.Settings.Default.Save(); SplashScreenHelper.Close(); openLoginWindow(); } } ; } catch (Exception ex) { retry(); Console.WriteLine("Error logging in: " + ex.Message); } } else { SplashScreenHelper.Close(); openLoginWindow(); } }