Sic.Framework/MECF.Framework.UI.Client/ClientBase/BaseApp.cs

126 lines
3.0 KiB
C#
Raw Normal View History

using System;
using System.IO;
2023-04-13 11:51:03 +08:00
using System.Reflection;
using Aitex.Core.Account;
using Aitex.Core.RT.Log;
2023-04-13 11:51:03 +08:00
using Caliburn.Micro;
using MECF.Framework.Common.Account.Extends;
using MECF.Framework.Common.Utilities;
using MECF.Framework.UI.Client.CenterViews.Configs.Accounts;
using MECF.Framework.UI.Client.CenterViews.Configs.Roles;
using MECF.Framework.UI.Core.Accounts;
2023-04-13 11:51:03 +08:00
namespace MECF.Framework.UI.Client.ClientBase
{
public class BaseApp
{
#region Variables
2023-04-13 11:51:03 +08:00
public ModuleDataMonitor _dataMonitor;
#endregion
2023-04-13 11:51:03 +08:00
#region Constructors
2023-04-13 11:51:03 +08:00
public BaseApp()
{
UserMode = UserMode.None;
Initialized = false;
Configure();
2023-04-13 11:51:03 +08:00
}
#endregion
#region Properites
public LoginClientInfo ClientInfo { get; private set; }
public UserContext UserContext { get; private set; }
public MenuManager MenuManager { get; private set; }
public UserMode UserMode { get; set; }
public bool Initialized { get; private set; }
public static BaseApp Instance { get; set; }
#endregion
#region Methods
public void LoadSystemInfo()
{
var myInfo = new LoginClientInfo();
myInfo.HostName = Environment.MachineName;
myInfo.UserName = Environment.UserName;
myInfo.OSVersion = Environment.OSVersion.ToString();
try
{
myInfo.ComputerSystem = SystemInfoHelper.GetComputerSystem();
myInfo.CpuInfo = SystemInfoHelper.GetCpuInfo();
myInfo.LogicalDisk = SystemInfoHelper.GetLogicalDiskInfo();
}
catch (Exception ex)
{
LOG.Error("Unable to get system information.", ex);
}
finally
{
ClientInfo = myInfo;
}
}
2023-04-13 11:51:03 +08:00
public void Initialize(bool force = false)
{
if (Initialized && !force)
2023-04-13 11:51:03 +08:00
return;
MenuManager = new MenuManager();
UserContext = new UserContext();
2023-04-13 11:51:03 +08:00
2023-09-05 10:20:23 +08:00
var file = $"{System.AppDomain.CurrentDomain.BaseDirectory}MECF.Framework.UI.Client.dll";
2023-04-13 11:51:03 +08:00
if (File.Exists(file))
{
2023-09-05 10:20:23 +08:00
var assembly = Assembly.LoadFile(file);
2023-04-13 11:51:03 +08:00
AssemblySource.Instance.Add(assembly);
}
OnInitialize();
2023-04-13 11:51:03 +08:00
//must be called after specific project initialized
_dataMonitor = new ModuleDataMonitor();
Initialized = true;
2023-04-13 11:51:03 +08:00
}
public virtual void Dispose()
{
2023-04-13 11:51:03 +08:00
}
protected void Configure()
{
//config skin/language...
OnConfiguration();
}
protected virtual void OnInitialize()
{
2023-04-13 11:51:03 +08:00
}
protected virtual void OnConfiguration()
{
}
public virtual void SwitchPage(string mainMenu, string subMenu, object parameter)
{
}
2023-04-13 11:51:03 +08:00
#endregion
2023-04-13 11:51:03 +08:00
}
}