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");
     }
 }
Example #2
0
 public SettingsViewModel()
 {
     SettingsViewModel.logger.Debug("VIEWMODEL LOADING: SettingsViewModel");
     AuthenticationService.Instance.SuspendService = false;
     this.SettingsMenu = new ObservableCollection <string>();
     this.SettingsMenu.Add(Resources.PageSettingsMenuDbConfig);
     this.SettingsMenu.Add(Resources.PageSettingsMenuApplicationConfig);
     this.SettingsMenu.Add(Resources.PageSettingsMenuIOConfig);
     this.SettingsMenu.Add(Resources.PageSettingsMenuMailConfig);
     this.SettingsMenu.Add(Resources.PageSettingsMenuMembercardConfig);
     this.SelectedMenuItem = Resources.PageSettingsMenuDbConfig;
     this.SerialPorts      = new ObservableCollection <string>(CashDrawerService.SerialPorts);
     this.CardReaders      = new ObservableCollection <string>(EidService.ReaderList);
     this.Printers         = new ObservableCollection <string>(Util.Util.SystemPrinters);
     this.TimeSpan         = Settings.Default.MemberCardValidityPeriod.Days;
     SplashScreenHelper.Close();
 }
Example #3
0
        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();
            }
        }
Example #4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            AppHelper.Init(ClientTypeCode.DCL.ToString());

#if !DEBUG
            CheckForUpdate();
#endif

            try
            {
                LocalizeDictionary.Instance.Culture = Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = Client.Properties.Settings.Default.Culture;
                SplashScreenHelper.Show(Thread.CurrentThread.CurrentCulture);
                SplashScreenHelper.SetState(DCL.Resources.StringResources.StateInitModules);

#if DEBUG
                // HACK: надоело по сто раз перегружаться
                SplashScreenHelper.SetState(DCL.Resources.StringResources.WaitServiceInit);
                //Thread.Sleep(10000);
#endif

                AppHelper.InitExceptionEngine(this);

                base.OnStartup(e);

                // стартуем "движок"
                var bootstrapper = new Bootstraper();
                bootstrapper.Run();

                // авторизуемся
                SplashScreenHelper.SetState(DCL.Resources.StringResources.StateAuthentication);
                AuthenticationHelper.AskCredentials = true;

                while (true)
                {
                    try
                    {
                        if (!Authenticate())
                        {
                            AppHelper.Log.Info("Exit from application. User was not Authenticated");
                            Environment.Exit(0);
                        }
                        else
                        {
                            // идем дальше
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is EndpointNotFoundException || ex.InnerException is General.CommunicationException)
                        {
                            if (
                                MessageBox.Show("Отсутствует связь с сервисом.\r\nПовторить попытку подключения?",
                                                "Соединение", MessageBoxButton.YesNo,
                                                MessageBoxImage.Question,
                                                MessageBoxResult.Yes) == MessageBoxResult.No)
                            {
                                AppHelper.Log.Info("Не удалось соединиться с сервисом");
                                Environment.Exit(0);
                            }
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                // запускаем модули
                SplashScreenHelper.SetState(DCL.Resources.StringResources.StateRunModules);
                bootstrapper.RunModules();

                // дополнительная проверка после общего запуска
                SplashScreenHelper.SetState(DCL.Resources.StringResources.StateRun);
                if (AuthenticationHelper.IsAuthenticated)
                {
                    AppHelper.Log.Debug("Show main form");
                    Current.MainWindow.Closed += MainWindow_Closed;
                    Current.MainWindow.UpdateLayout();
                    Current.MainWindow.Show();
                    SignalRHelper.TryConnectToServer();
                }
                else
                {
                    AppHelper.Log.Info("Exit from application. User Authentication was canceled");
                    Current.Shutdown();
                }

                SplashScreenHelper.Close();
            }
            catch (Exception ex)
            {
                SplashScreenHelper.Close();

                // обрабатываем ошибку
                if (!ExceptionPolicy.Instance.HandleException(ex, typeof(App)))
                {
                    throw;
                }

                // и безусловно выходим из приложения (без инициализации работать не можем)
                AppHelper.Log.Info("Exit from application. Exception was not handled");
                Environment.Exit(0);
            }
            finally
            {
                AppHelper.Log.Debug("Startup complete");
            }
        }
Example #5
0
        private const int MaxCountConnectionAttempt = 7; //Достаточно случайное число

        protected override void OnStartup(StartupEventArgs e)
        {
            AppHelper.Init(ClientTypeCode.RCL.ToString());

#if !DEBUG
            AppHelper.Log.Info("Проверка обновлений");

            bool isCantCopyToLocal;
            var  updateInfo = UpdateHelper.ReadUpdateInfo(Environment.CurrentDirectory, Client.Properties.Settings.Default.UpdateInfoFile, out isCantCopyToLocal);

            if (updateInfo == null)
            {
                MessageBox.Show(
                    "В данный момент выполняется обновление системы.\r\nПовторите попытку позже.", "ВНИМАНИЕ!", MessageBoxButton.OK, MessageBoxImage.Information);
                Shutdown();
                return;
            }
#endif

            try
            {
                CultureInfo.DefaultThreadCurrentCulture           =
                    LocalizeDictionary.Instance.Culture           =
                        Thread.CurrentThread.CurrentCulture       =
                            Thread.CurrentThread.CurrentUICulture = Client.Properties.Settings.Default.Culture;

                SplashScreenHelper.Show(Thread.CurrentThread.CurrentCulture);
                SplashScreenHelper.SetState(RCL.Resources.StringResources.StateInitModules);
                AppHelper.InitExceptionEngine(this);

                base.OnStartup(e);

                // стартуем "движок"
                var bootstrapper = new Bootstraper();
                bootstrapper.Run();

#if DEBUG
                SplashScreenHelper.SetState(RCL.Resources.StringResources.WaitServiceInit);
                Thread.Sleep(5000);
#endif

                // запускаем модули
                SplashScreenHelper.SetState(RCL.Resources.StringResources.StateRunModules);
                bootstrapper.RunModules();

                // авторизуемся
                SplashScreenHelper.SetState(RCL.Resources.StringResources.StateAuthentication);
                AuthenticationHelper.AskCredentials = true;

                var count = 0;
                while (true)
                {
                    try
                    {
                        if (!Authenticate())
                        {
                            AppHelper.Log.Info("Exit from application. User was not Authenticated.");
                            Environment.Exit(0);
                        }
                        else
                        {
                            // идем дальше
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is EndpointNotFoundException || ex.InnerException is CommunicationException)
                        {
                            if (count++ < MaxCountConnectionAttempt)
                            {
                                AppHelper.Log.Info(string.Format("Попытка соединения с сервисом {0}", count));
                            }
                            else
                            {
                                AppHelper.Log.Info("Не удалось соединиться с сервисом");
                                throw new DeveloperException("Превышено количество попыток соединения с сервером. Приложение будет закрыто.", ex);
                                //Environment.Exit(0);
                            }
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                // дополнительная проверка после общего запуска
                SplashScreenHelper.SetState(RCL.Resources.StringResources.StateRun);
                if (AuthenticationHelper.IsAuthenticated)
                {
                    AppHelper.Log.Debug("Show main form");
                    Current.MainWindow.Closed += MainWindow_Closed;
                    Current.MainWindow.UpdateLayout();
                    Current.MainWindow.Show();
                }
                else
                {
                    AppHelper.Log.Info("Exit from application. User Authentication was canceled");
                    Current.Shutdown();
                }
            }
            catch (Exception ex)
            {
                // обрабатываем ошибку
                if (!ExceptionPolicy.Instance.HandleException(ex, typeof(App)))
                {
                    throw;
                }

                // и безусловно выходим из приложения (без инициализации работать не можем)
                AppHelper.Log.Info("Exit from application. Exception was not handled");
                Environment.Exit(0);
            }
            finally
            {
                SplashScreenHelper.Close();
                AppHelper.Log.Debug("Startup complete");
            }
        }