123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using DBMaintenanceTool.Utilities;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Diagnostics;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Forms;
- using System.Windows.Threading;
- using Vinno.IUS.Common.Log;
- namespace DBMaintenanceTool
- {
- /// <summary>
- /// App.xaml 的交互逻辑
- /// </summary>
- public partial class App : System.Windows.Application
- {
- [DllImport("user32.dll")]
- public static extern bool CloseWindow(IntPtr hWnd);
- protected override void OnStartup(StartupEventArgs e)
- {
- Exit += (sender, ee)=> {
- foreach (var port in new string[] { "19100", "19200" })
- {
- using (Process ps = new Process())
- {
- try
- {
- ps.StartInfo.FileName = $"{EnvironmentManager.MongoToolsPath}\\mongo";
- ps.StartInfo.UseShellExecute = false;
- ps.StartInfo.RedirectStandardOutput = false;
- ps.StartInfo.RedirectStandardInput = true;
- ps.StartInfo.Arguments = $" --host 127.0.0.1:{port}";
- ps.StartInfo.CreateNoWindow = true;
- ps.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
- ps.StartInfo.Verb = "runas";
- ps.Start();
- ps.StandardInput.WriteLine($"use admin");
- ps.StandardInput.WriteLine(@"db.shutdownServer();");
- ps.StandardInput.WriteLine("exit");
- Logger.WriteLineInfo($"Stop DB port:{port} success");
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"Stop DB service error {ex}");
- throw;
- }
- }
- }
- };
- AppDomain.CurrentDomain.UnhandledException += OnDomainUnhandledException;
- Current.DispatcherUnhandledException += OnCurrentDispatcherUnhandledException;
- base.OnStartup(e);
- }
- private void OnCurrentDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
- {
- Logger.WriteLineError($"DispatcherUnhandledException happened, detail is :{e.Exception}");
- e.Handled = true;
- }
- private void OnDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- Logger.WriteLineError($"DomainUnhandledException happened, detail is :{e.ExceptionObject}");
- //e.ExceptionObject.Handled = true;
- }
- }
- }
|