예제 #1
0
        private void AdonisWindow_Loaded(object sender, RoutedEventArgs e)
        {
            SplashWindow.Stop();

            Application.Current.MainWindow = this;

            var handle = new WindowInteropHelper(Application.Current.MainWindow).Handle;
            var source = HwndSource.FromHwnd(handle);

            source?.AddHook(WndProc);
        }
예제 #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Window_Loaded 错误处理
            try
            {
                SplashWindow.Start();
                Thread.Sleep(1000);

                MainViewModel.Initial();
                _runLedtimer.Interval = TimeSpan.FromSeconds(1);
                _runLedtimer.Start();
                SplashWindow.Stop();
                Activate();
            }
            catch (Exception ex)
            {
                SplashWindow.ShowInfo("连接PLC失败");
                Thread.Sleep(2000);
                SplashWindow.Stop();
                Application.Current.Shutdown(0);
            }
        }
예제 #3
0
        private static void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
        {
            if (args.Error == null)
            {
                if (args.IsUpdateAvailable)
                {
                    var messageBox = new AdonisUI.Controls.MessageBoxModel
                    {
                        Text = $"There is new version {args.CurrentVersion} available.{Environment.NewLine}" +
                               $"You are using version {args.InstalledVersion}.{Environment.NewLine}" +
                               $"{ChangelogText}{Environment.NewLine}" +
                               $"Do you want to update the application now?",
                        Caption = @"Update Available",
                        Buttons = AdonisUI.Controls.MessageBoxButtons.YesNo()
                    };

                    AdonisUI.Controls.MessageBox.Show(messageBox);

                    if (!manual)
                    {
                        SplashWindow.splash.Hide();
                    }

                    if (messageBox.Result.Equals(AdonisUI.Controls.MessageBoxResult.Yes))
                    {
                        try
                        {
                            if (AutoUpdater.DownloadUpdate(args))
                            {
                                if (!manual)
                                {
                                    SplashWindow.Stop();
                                }
                                Application.Current.Shutdown();
                                Environment.Exit(0);
                            }
                        }
                        catch (Exception exception)
                        {
                            AdonisUI.Controls.MessageBox.Show(
                                exception.Message,
                                exception.GetType().ToString(),
                                AdonisUI.Controls.MessageBoxButton.OK,
                                AdonisUI.Controls.MessageBoxImage.Error);
                        }
                    }
                    if (!manual)
                    {
                        SplashWindow.splash.Show();
                    }
                }
            }
            else
            {
                if (args.Error is WebException)
                {
                    AdonisUI.Controls.MessageBox.Show(
                        @"There is a problem reaching update server. Please check your internet connection and try again later.",
                        @"Update Check Failed",
                        AdonisUI.Controls.MessageBoxButton.OK,
                        AdonisUI.Controls.MessageBoxImage.Error);
                }
                else
                {
                    AdonisUI.Controls.MessageBox.Show(
                        args.Error.Message,
                        args.Error.GetType().ToString(),
                        AdonisUI.Controls.MessageBoxButton.OK,
                        AdonisUI.Controls.MessageBoxImage.Error);
                }
            }
        }
예제 #4
0
        private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
        {
            if (args.Error == null)
            {
                if (args.IsUpdateAvailable)
                {
                    MessageBoxResult result = MessageBox.Show(
                        $"There is new version {args.CurrentVersion} available.{Environment.NewLine}" +
                        $"You are using version {args.InstalledVersion}.{Environment.NewLine}" +
                        $"{ChangelogText}{Environment.NewLine}" +
                        "Do you want to update the application now?",
                        @"Update Available",
                        MessageBoxButton.YesNo
                        );

                    if (!manual)
                    {
                        SplashWindow.splash.Hide();
                    }

                    if (result.Equals(MessageBoxResult.Yes))
                    {
                        try
                        {
                            if (AutoUpdater.DownloadUpdate(args))
                            {
                                if (!manual)
                                {
                                    SplashWindow.Stop();
                                }
                                Application.Current.Shutdown();
                                Environment.Exit(0);
                            }
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(
                                exception.Message,
                                exception.GetType().ToString(),
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                        }
                    }

                    if (!manual)
                    {
                        SplashWindow.splash.Show();
                    }
                }
                else if (manual)
                {
                    OnUpdateCheckCompleteEvent(new EventArgs());
                }
            }
            else
            {
                if (args.Error is WebException)
                {
                    MessageBox.Show(
                        @"There is a problem reaching update server. Please check your internet connection and try again later.",
                        @"Update Check Failed",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
                else
                {
                    MessageBox.Show(
                        args.Error.Message,
                        args.Error.GetType().ToString(),
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
            AutoUpdater.ParseUpdateInfoEvent -= AutoUpdaterOnParseUpdateInfoEvent;
            AutoUpdater.CheckForUpdateEvent  -= AutoUpdaterOnCheckForUpdateEvent;
        }