You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
6.4 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using CommonFunc;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using ThriftCommon;
using XGL.Models;
using XGL.Data;
using System.Threading.Tasks;
namespace XGL
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
private System.Threading.Mutex mutex;
public App()
{
string name = Process.GetCurrentProcess().MainModule.ModuleName.Replace(".exe", "");
//禁止多开
mutex = new System.Threading.Mutex(true, name, out bool ret);
if (!ret)
{
MessageBox.Show("已有一个程序实例运行", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
Environment.Exit(0);
}
//UI线程未捕获异常处理事件UI主线程
this.DispatcherUnhandledException += App_DispatcherUnhandledException;
//非UI线程未捕获异常处理事件(例如自己创建的一个子线程)
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
//Task线程内未捕获异常处理事件
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;//Task异常
Common.ApplicationDicStr = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
Common.ThriftConfigIp = ConfigurationManager.AppSettings["thriftIp"];
Common.ThriftConfigPort = ConfigurationManager.AppSettings["thriftPort"];
Common.thriftBoxPort = ConfigurationManager.AppSettings["thriftBoxPort"];
Common.FormBoardThriftPort = ConfigurationManager.AppSettings["FormBoardThriftPort"];
//Common.LocatHostMac = Common.GetLocationHostMac();
//Common.HostIp = Common.GetLocationHostAddress();
//Common.PortName = ConfigurationManager.AppSettings["PortName"];
//Common.HostIp = "192.168.38.46";
//Common.LocatHostMac = "00:30:18:00:3A:E1";
//Common.stoplineset = Convert.ToInt32(ConfigurationManager.AppSettings["stopline"]);
//Common.PortNamestop = ConfigurationManager.AppSettings["PortNamestop"];
//Common.DefaultPosition = ConfigurationManager.AppSettings["DefaultPosition"];
//Common.CSPosition = ConfigurationManager.AppSettings["CSPosition"];
Common.LocalIPAddress = Common.IPAddress();
Common.PostType = ConfigurationManager.AppSettings["PostType"];
Common.LineCode = ConfigurationManager.AppSettings["LineCode"];
Common.LineId = ConfigurationManager.AppSettings["LineId"];
Common.BoardRefresh = Convert.ToInt32(ConfigurationManager.AppSettings["BoardRefresh"]);
Common.TakeOffRefresh = Convert.ToInt32(ConfigurationManager.AppSettings["TakeOffRefresh"]);
Common.EmptyRefresh = Convert.ToInt32(ConfigurationManager.AppSettings["EmptyRefresh"]);
//try
//{
// using (basedata_lineinfoDB lineinfoDB = new basedata_lineinfoDB())
// {
// Common.Lineinfo = lineinfoDB.GetModel(Common.LineId,Common.PostType);
// }
//}
//catch (Exception ex)
//{
//}
#region 自动更新
//try
//{
// string name = Process.GetCurrentProcess().ProcessName;
// XGL.AutoUpdate.WebService WS = new XGL.AutoUpdate.WebService();
// string RVersion = WS.getFileVersion();
// //string LVersion = FileVersionInfo.GetVersionInfo(name + ".exe").FileVersion;
// string LVersion = FileVersionInfo.GetVersionInfo("XGL.exe").FileVersion;
// int result = string.Compare(LVersion, RVersion);
// if (result < 0)
// {
// Process.Start("AutoUpdate.exe");
// System.Environment.Exit(System.Environment.ExitCode);
// }
//}
//catch
//{
//}
Window w;
switch (Common.PostType)
{
////上线
//case "1":
// w = new FormItem.FormBoard();
// w.Show();
// break;
//case "2"://排空
// w = new FormItem.FormEmpty();
// w.Show();
// break;
//case "0"://下线
// w = new FormItem.FormTakeOff();
// w.Show();
// break;
}
#endregion
}
void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
try
{
HandleException(e.Exception);
}
catch (Exception ex)
{
HandleException(ex);
}
finally
{
e.Handled = true;
}
}
private static void HandleException(Exception ex)
{
Logger log = new Logger();
log.Log(ex.ToString());
}
//非UI线程未捕获异常处理事件(例如自己创建的一个子线程)
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
var exception = e.ExceptionObject as Exception;
if (exception != null)
{
HandleException(exception);
}
}
catch (Exception ex)
{
HandleException(ex);
}
finally
{
//ignore
}
}
private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
try
{
var exception = e.Exception as Exception;
if (exception != null)
{
HandleException(exception);
}
}
catch (Exception ex)
{
HandleException(ex);
}
finally
{
e.SetObserved();
}
}
}
}