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

132 lines
3.3 KiB
C#
Raw Normal View History

using System;
using System.IO;
2023-04-13 11:51:03 +08:00
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Aitex.Core.Account;
using Aitex.Core.RT.Log;
2023-04-13 11:51:03 +08:00
using Caliburn.Micro;
using Caliburn.Micro.Core;
2023-04-13 11:51:03 +08:00
using MECF.Framework.Common.Account.Extends;
using MECF.Framework.Common.Utilities;
2023-04-13 11:51:03 +08:00
namespace MECF.Framework.UI.Client.ClientBase
{
public class BaseApp
{
public LoginClientInfo ClientInfo { get; private set; }
2023-04-13 11:51:03 +08:00
public UserContext UserContext { get; private set; }
2023-04-13 11:51:03 +08:00
public MenuManager MenuManager { get; private set; }
public UserMode UserMode { get; set; }
2023-04-13 11:51:03 +08:00
public bool Initialized { get; private set; }
public ModuleDataMonitor _dataMonitor;
private static BaseApp _instance = null;
public static BaseApp Instance
{
2023-09-05 10:20:23 +08:00
get => _instance;
set => _instance = value;
2023-04-13 11:51:03 +08:00
}
public BaseApp()
{
UserMode = UserMode.None;
Initialized = false;
Configure();
2023-04-13 11:51:03 +08:00
}
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
public int GetPermission(string menuid)
{
2023-09-05 10:20:23 +08:00
var per = 1;
if (UserContext != null)
2023-04-13 11:51:03 +08:00
{
2023-09-05 10:20:23 +08:00
var list = UserContext.Role.PermissionContent.Split(';');
2023-04-13 11:51:03 +08:00
var result = from r in list
where r.Split(',')[0] == menuid
select r;
2023-04-13 11:51:03 +08:00
if (result.Count() > 0)
per = int.Parse(result.ToArray()[0].Split(',')[1]);
}
2023-04-13 11:51:03 +08:00
return per;
}
}
}