using SCADA.CommonCtrl.WpfControl; using SCADA.CommonLib; using SCADA.CommonLib.Helper; using SCADA.CommonLib.Service; using SCADA_DAQ.Plugin.Core.AutoUpdater; using SCADA_DAQ.Plugin.CoreUI; using System; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; using System.Xml.Linq; namespace SCADA_DAQ { /// /// App.xaml 的交互逻辑 /// public partial class App : Application, IApp { private static SystemControl systemControl; private string _sessionid; internal Task updateCheckTask; /// /// public IServiceHost ServiceHost { get; set; } /// /// /// public ThemeConfig ThemeConfig { get => AutoSaveParameterItem.Create("App.ThemeConfig", new ThemeConfig()); } /// /// public SystemConfig SystemConfig { get => AutoSaveParameterItem.Create("App.SystemConfig", new SystemConfig()); } /// /// /// public RuntimeInfo RuntimeInfo { get; set; } = new RuntimeInfo(); private App() { //RuntimeInfo.ProductId=ApplicationHelper.GetProductTitle(); RuntimeInfo.ProductId = System.Windows.Forms.Application.ProductName; RuntimeInfo.SessionId = _sessionid ?? (_sessionid = Guid.NewGuid().ToString()); RuntimeInfo.ExeName = Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase); RuntimeInfo.PuginPaths = "plugin"; RuntimeInfo.DllNameMatch = "SCADA_DAQ.Plugin.*.dll"; RuntimeInfo.MenuNameMatch = "UctFrm"; Console.WriteLine($"App Start {DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}"); if (string.IsNullOrEmpty(SystemConfig.WebServer)) { SystemConfig.WebServer = "www.skdscada.com"; } if (string.IsNullOrEmpty(SystemConfig.ProductTitle)) { SystemConfig.ProductTitle = ApplicationHelper.GetProductTitle(); } if (string.IsNullOrEmpty(SystemConfig.AuthorInfo)) { SystemConfig.AuthorInfo = System.Windows.Forms.Application.CompanyName; } if (string.IsNullOrEmpty(SystemConfig.DefaultUser)) { SystemConfig.DefaultUser = "Operator"; } try { var appServer = SystemConfig.WebServer; Trace.WriteLine($"Server:{appServer}"); var task = Task.Factory.StartNew(() => { Env.ParameterInit(this); }); var win = new MainWindow(); MainWindow = win; win.FrmClosingWait += Win_FrmClosingWait; systemControl = SystemControl.Create(this); var iconPath = "Content/Img/favicon.ico"; if (File.Exists(iconPath)) { MainWindow.Icon = new BitmapImage(new Uri(iconPath, UriKind.RelativeOrAbsolute)); } task.Wait(); systemControl.SystemInit(); } catch (Exception ex) { //updateCheckTask?.Wait(10 * 1000); Trace.TraceError(ex.ToString()); } } private void Win_FrmClosingWait(object sender, EventArgs e) { SystemControl.GetInstance().ApplicationDispose(0); } private void Application_Startup(object sender, StartupEventArgs e) { MainWindow.Show(); } private void Application_SessionEnding(object sender, SessionEndingCancelEventArgs e) { systemControl.ApplicationSessionEnding(this, e); } private void Application_Exit(object sender, ExitEventArgs e) { systemControl.ApplicationExit(e.ApplicationExitCode); } /// /// /// /// public bool RestartHost() { return systemControl.RestartHost(); } /// /// /// /// public void Restart(bool runAs = false) { MainWindow.Close(); Exit += (s, e) => { new Thread(() => { Thread.Sleep(1000); string strAppFileName = Process.GetCurrentProcess().MainModule.FileName; Process myNewProcess = new Process(); myNewProcess.StartInfo.FileName = strAppFileName; myNewProcess.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory; if (runAs == true) { myNewProcess.StartInfo.Verb = "runas"; } myNewProcess.Start(); }).Start(); }; } /// /// /// public void Restart() { Dispatcher.Invoke(new Action(() => { Restart(false); })); } /// /// /// public void ReLoadLicense() { systemControl.LoadLicense(); } /// /// 显示toast /// /// toast内容 /// /// toast 时间 短:2500 长:3500 public void ShowToast(object message, ControlStyle toastType = ControlStyle.Default, int showTime = 2000) { Dispatcher.BeginInvoke(new Action(() => { var toastItem = new ToastItem() { Message = message, ControlStyle = toastType }; var showPannel = SCADA.CommonCtrl.WpfHelper.VisualHelper.GetChildObject(MainWindow, "PART_ToastLayer"); toastItem.Show(showPannel, showTime); })); } /// /// 显示短toast /// /// toast内容 /// public void ShowShortToast(object message, ControlStyle toastType) { ShowToast(message, toastType, 2000); } /// /// 显示长toast /// /// toast内容 /// public void ShowLongToast(object message, ControlStyle toastType) { ShowToast(message, toastType, 3500); } } }