using DeviceRepair.Models;
using DeviceRepair.Models.SFC;
using System;
using System.Collections.Generic;
using System.Linq;
using TsSFCDevice.Client.Biz.Impl;
namespace TsSFCDevice.Client.Biz.Base.Utils
{
public class SysRuntimeInfo
{
public readonly string DEVICE_OEM = "BIZ_EQUIP_70";
public readonly string DEVICE_KH = "BIZ_EQUIP_69";
///
/// 当前机器名
///
public string ComputerName { get; set; }
#region 当前登陆用户信息
private TsSFCUserInfo m_CurrentUser;
public TsSFCUserInfo CurrentUser
{
get
{
return m_CurrentUser;
}
set
{
m_CurrentUser = value;
}
}
private IList m_CurrentAuths;
public IList CurrentAuths
{
get
{
return m_CurrentAuths;
}
set
{
m_CurrentAuths = value;
}
}
#endregion
#region 各种缓存
private IList m_CurrentDeviceCaches;
///
/// 设备信息缓存
///
public IList CurrentDeviceCaches
{
get
{
if (m_CurrentDeviceCaches == null)
{
List auths = new List();
if (AuthValidate(DEVICE_OEM))
auths.Add("OEM");
if (AuthValidate(DEVICE_KH))
auths.Add("KH");
DevRepository devDa = new DevRepository();
m_CurrentDeviceCaches = devDa.GetDatas(auths);
}
return m_CurrentDeviceCaches;
}
set
{
m_CurrentDeviceCaches = value;
}
}
public int[] CurrentDeviceAutoIDCaches
{
get
{
return CurrentDeviceCaches.Select(x => x.AutoID).ToArray();
}
}
private IList m_CurrentUsersCaches;
///
/// 当前用户信息缓存
///
public IList CurrentUsersCaches
{
get
{
if (m_CurrentUsersCaches == null)
{
UserRepository userDa = new UserRepository();
m_CurrentUsersCaches = userDa.GetDatas();
}
return m_CurrentUsersCaches;
}
set
{
m_CurrentUsersCaches = value;
}
}
private IList m_CurrentDevRootCaches;
public IList CurrentDevRootCaches
{
get
{
if (m_CurrentDevRootCaches == null)
{
List auths = new List();
if (AuthValidate(DEVICE_OEM))
auths.Add("OEM");
if (AuthValidate(DEVICE_KH))
auths.Add("KH");
m_CurrentDevRootCaches = DevRepository.Instance.Get_DEVICE_Route(auths);
}
return m_CurrentDevRootCaches;
}
set
{
m_CurrentDevRootCaches = value;
}
}
#endregion
#region Methods
///
/// 校验用户权限
///
///
///
public bool AuthValidate(string vAuthCode)
{
return CurrentAuths?.FirstOrDefault(A => { return A.AuthCode == vAuthCode; }) != null;
}
public bool AuthStartWithValidate(string vAuthCode)
{
return CurrentAuths?.FirstOrDefault(A => { return A.AuthCode.StartsWith(vAuthCode, StringComparison.OrdinalIgnoreCase); }) != null;
}
#endregion
}
}