Exemple #1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // TODO: Don't display splash screen during startup if chosen by user
            _retryInterval = RETRY_INTERVAL;

            ManualResetEvent mre = new ManualResetEvent(false);
            // start splash screen thread
            Thread thread = new Thread(
                new ThreadStart(
                    delegate()
            {
                SplashScreenHelper.SplashScreen = new Splash();


                SplashScreenHelper.Show();

                mre.Set();

                System.Windows.Threading.Dispatcher.Run();
            }
                    ));


            thread.SetApartmentState(ApartmentState.STA);
            thread.IsBackground = true;
            thread.Start();

            // wait until thread initializes everything and then check
            mre.WaitOne();

            check();
        }
Exemple #2
0
        public static void Main()
        {
            Thread thread1 = new Thread((ThreadStart)(() =>
            {
                SplashScreenHelper.SplashScreen = new SplashScreenView();
                SplashScreenHelper.Show();
                Dispatcher.Run();
            }));

            thread1.SetApartmentState(ApartmentState.STA);
            thread1.IsBackground = true;
            thread1.Start();
            Thread thread2 = new Thread((ThreadStart)(() =>
            {
                LockScreenHelper.LockScreen = new LockScreenView();
                Dispatcher.Run();
            }));

            thread2.SetApartmentState(ApartmentState.STA);
            thread2.IsBackground = true;
            thread2.Start();
            if (!SingleInstance <App> .InitializeAsFirstInstance("POSInstance"))
            {
                return;
            }
            App app = new App();

            app.InitializeComponent();
            app.Run();
            SingleInstance <App> .Cleanup();
        }
Exemple #3
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");
            }
        }
Exemple #4
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");
            }
        }