コード例 #1
0
ファイル: Win32Helper.cs プロジェクト: dr1rrb/smarthome.net
        public async Task <IWin32Window> GetOrCreateWindow(CancellationToken ct)
        {
            lock (_currentGate)
            {
                if (_current == null)
                {
                    _current = new WPFApplication();
                }

                _currentHandles++;
            }

            try
            {
                var handle = await _current.GetWindow();

                return(new WPFWindow(this, handle));
            }
            catch
            {
                Release();

                throw;
            }
        }
コード例 #2
0
ファイル: StartUp.xaml.cs プロジェクト: UmaxSoftWorks/UDS2
        protected void ShowMainWindow()
        {
            // Loading data
            this.stateLabel.Content = "Loading data...";
            WPFApplication.DoEvents();

            mainBackgroundWorker.RunWorkerAsync();
        }
コード例 #3
0
ファイル: Win32Helper.cs プロジェクト: dr1rrb/smarthome.net
 private void Release()
 {
     lock (_currentGate)
     {
         if (--_currentHandles == 0)
         {
             _current = null;
         }
     }
 }
コード例 #4
0
ファイル: StartUp.xaml.cs プロジェクト: UmaxSoftWorks/UDS2
        protected void mainBackgroundWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // Hide StartUp Window
            this.Hide();
            this.UpdateLayout();

            WPFApplication.DoEvents();

            // Show main window
            RunTime.Instance.MainWindow = (GuiOptions.Instanse.Manager ? (IExitableWindow) new Manager() : (IExitableWindow) new Main());

            RunTime.Instance.MainWindow.Dismissed += this.mainWindowFormClosed;
            RunTime.Instance.MainWindow.Execute();
        }
コード例 #5
0
        private void WindowClosing(object sender, CancelEventArgs e)
        {
            if (this.Exit)
            {
                if (WinHelper.MessageBox("Do you really want close program?", "Exit...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
                {
                    e.Cancel = true;
                    return;
                }

                if (!this.Visible)
                {
                    this.Visible = true;
                }

                // Log
                if (RunTime.Instance.LogWindow != null)
                {
                    RunTime.Instance.LogWindow.Close();
                    WPFApplication.DoEvents();
                }

                this.updateTimer.Stop();

                // Events
                GuiOptions.Instanse.ManagerPinChanged      -= this.ManagerPinChanged;
                GuiOptions.Instanse.ManagerLocationChanged -= this.ManagerLocationChanged;

                this.trayIcon.DoubleClick -= this.IconDoubleClick;

                this.mainMenu.DeInitializeEvents();
                this.trayIcon.DeInitializeEvents();


                // Notify Icon
                this.trayIcon.Visible = false;
                this.trayIcon.Dispose();

                // Exit
                WindowsHelper.Exit();
            }
            else
            {
                e.Cancel     = true;
                this.Visible = false;
            }
        }
コード例 #6
0
        protected virtual void Run(Window window)
        {
            WPFApplication application = Domain.Current.Application as WPFApplication ?? throw new InitializeException("Application is not wpf");

            if (window is null)
            {
                application.Run();
                return;
            }

            Context ??= window;
            if (window != Context)
            {
                throw new ArgumentException($"{nameof(window)} not reference equals with {nameof(Context)}");
            }

            Context.Closed += OnFormClosed;
            application.Run(Context);
        }
コード例 #7
0
 /// <summary>
 /// 程序启动
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
 {
     try
     {
         if (WPFApplication != null)
         {
             WPFApplication.Run();
         }
         else if (MainWindow != null)
         {
             System.Windows.Forms.Application.Run(MainWindow);
         }
     }
     catch (Exception ex)
     {
         ex.ToString().WriteToLog("", log4net.Core.Level.Error);
         System.Windows.MessageBox.Show("系统异常,请联系管理员!", "提示信息", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error, System.Windows.MessageBoxResult.OK);
         System.Environment.Exit(System.Environment.ExitCode);
     }
     return(false);
 }
コード例 #8
0
        private static void BuildLogin <TShellViewModel, TLogin>(IContainer container, WPFApplication wpfApplication, TShellViewModel shellViewModel, TLogin loginViewModel)
            where TShellViewModel : IShellViewModel
            where TLogin : ILoginViewModel
        {
            container.RegisterInstance <ILoginViewModel>(loginViewModel);
            loginViewModel.Initialize()
            .ContinueWith(lt =>
            {
                var loggedIn  = false;
                var loginView = loginViewModel.GetView() as Window;

                if (loginView == null)
                {
                    throw new ApplicationBuildException("The login view muse be of type Window");
                }

                loginView.Closed += delegate
                {
                    if (!loggedIn)
                    {
                        wpfApplication.GetSystemApplication().Shutdown();
                    }
                };
                loginViewModel.LoggedIn += (s, args) =>
                {
                    loggedIn = true;
                    wpfApplication.ShowWindow();
                    shellViewModel.Initialize().ContinueWith((t) =>
                    {
                        container.Resolve <IEventDispatcher>().GetEvent <ApplicationStartedEvent>().Raise(wpfApplication);
                    });
                    loginView.Close();
                };
                wpfApplication.GetSystemApplication()
                .Dispatcher.Invoke(() =>
                {
                    loginView.Show();
                });
            });
        }