123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- 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
- {
- /// <summary>
- /// App.xaml 的交互逻辑
- /// </summary>
- public partial class App : Application, IApp
- {
- private static SystemControl systemControl;
- private string _sessionid;
- internal Task updateCheckTask;
- /// <summary>
- /// </summary>
- public IServiceHost ServiceHost { get; set; }
- /// <summary>
- ///
- /// </summary>
- public ThemeConfig ThemeConfig { get => AutoSaveParameterItem.Create("App.ThemeConfig", new ThemeConfig()); }
- /// <summary>
- /// </summary>
- public SystemConfig SystemConfig { get => AutoSaveParameterItem.Create("App.SystemConfig", new SystemConfig()); }
- /// <summary>
- ///
- /// </summary>
- 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);
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public bool RestartHost()
- {
- return systemControl.RestartHost();
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="runAs"></param>
- 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();
- };
- }
- /// <summary>
- ///
- /// </summary>
- public void Restart()
- {
- Dispatcher.Invoke(new Action(() =>
- {
- Restart(false);
- }));
- }
- /// <summary>
- ///
- /// </summary>
- public void ReLoadLicense()
- {
- systemControl.LoadLicense();
- }
- /// <summary>
- /// 显示toast
- /// </summary>
- /// <param name="message">toast内容</param>
- /// <param name="toastType"></param>
- /// <param name="showTime">toast 时间 短:2500 长:3500</param>
- 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<Panel>(MainWindow, "PART_ToastLayer");
- toastItem.Show(showPannel, showTime);
- }));
- }
- /// <summary>
- /// 显示短toast
- /// </summary>
- /// <param name="message">toast内容</param>
- /// <param name="toastType"></param>
- public void ShowShortToast(object message, ControlStyle toastType)
- {
- ShowToast(message, toastType, 2000);
- }
- /// <summary>
- /// 显示长toast
- /// </summary>
- /// <param name="message">toast内容</param>
- /// <param name="toastType"></param>
- public void ShowLongToast(object message, ControlStyle toastType)
- {
- ShowToast(message, toastType, 3500);
- }
- }
- }
|