天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

159 lines
5.1 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NSC;
using QMFrameWork.Data;
namespace NSC.Service
{
public class SystemServiceEngine : IDisposable
{
/// <summary>
/// 服务定义列表
/// </summary>
List<ServiceDefination> ServiceDefineList = null;
/// <summary>
/// 动态库跟路径
/// </summary>
public static string DllRootPath { get; set; }
/// <summary>
/// 装载服务定义
/// </summary>
public void Load()
{
try
{
string sql = "SELECT * FROM T_QM_SYSSERVICEDEFINE WHERE SERVICESTATE='0'";
using (IDataSession session = DataFactory.CreateSession())
{
ServiceDefineList = session.GetList<ServiceDefination>(sql, (new List<DataParameter>()).ToArray()).ToList();
}
}
catch (Exception ex)
{
//记录异常信息
Console.WriteLine(ex.Message);
}
//创建各个服务的实例
foreach (var s in ServiceDefineList)
{
try
{
string path = "";
if(s.DLLPATH.IndexOf(@":\")<0)
{
path = DllRootPath + s.DLLPATH;
}
else
{
path = s.DLLPATH;
}
s.ENTITYSTATE = Common.Data.ServiceEntityState.Loading;
s.SERVICEENTITY = Common.AssemblyUtil.AssemblyFactory.CreateInstanceAnywhere(path, s.CLASSPATH) as IService;
s.ENTITYSTATE = Common.Data.ServiceEntityState.Loaded;
}
catch (Exception ex)
{
//记录异常信息
Console.WriteLine(ex.Message);
}
}
}
/// <summary>
/// 重新装载服务定义
/// </summary>
public void Reload()
{
try
{
List<ServiceDefination> list = new List<ServiceDefination>();
string sql = "SELECT * FROM T_QM_SYSSERVICEDEFINE WHERE SERVICESTATE='0'";
using (IDataSession session = DataFactory.CreateSession())
{
list = session.GetList<ServiceDefination>(sql, (new List<DataParameter>()).ToArray()).ToList();
}
foreach (var s in ServiceDefineList)
{
var n = list.Find(p => p.SERVICECODE == s.SERVICECODE);
if (n == null)
{
s.SERVICEENTITY = null;
ServiceDefineList.Remove(s);
}
}
foreach (var n in list)
{
var m = ServiceDefineList.Find(p => p.SERVICECODE == n.SERVICECODE);
if (m == null)
{
ServiceDefineList.Add(n);
string path = "";
if (n.DLLPATH.IndexOf(@":\") < 0)
{
path = DllRootPath + n.DLLPATH;
}
else
{
path = n.DLLPATH;
}
n.ENTITYSTATE = Common.Data.ServiceEntityState.Loading;
n.SERVICEENTITY = Common.AssemblyUtil.AssemblyFactory.CreateInstanceAnywhere(path, n.CLASSPATH) as IService;
n.ENTITYSTATE = Common.Data.ServiceEntityState.Loaded;
}
}
}
catch (Exception ex)
{
//记录异常信息
throw ex;
}
}
/// <summary>
/// 关闭所有服务
/// </summary>
public void Dispose()
{
ServiceDefineList.Clear();
ServiceDefineList = null;
}
/// <summary>
/// 服务处理
/// </summary>
/// <param name="userAuth">客户端的访问级别</param>
/// <param name="input">传入的数据</param>
/// <returns></returns>
internal NetServiceStruct ServiceHandler(Common.Data.UserAuthority userAuth, NetServiceStruct input, bool ignoreCase)
{
var s = ServiceDefineList.Find(p => p.SERVICECODE == input.ServiceName && p.ENTITYSTATE == Common.Data.ServiceEntityState.Loaded);
if (s != null)
{
return s.SERVICEENTITY.ServiceFunction(userAuth, input);
}
else
{
if (!ignoreCase)
{
throw new Common.Exceptions.NoneServiceException();
}
else
{
return null;
}
}
}
}
}