using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;
using System.ServiceModel;
using Topshelf;
using QMFrameWork.Common.Util;
using QMFrameWork.Cache;
using QM.Exchange.Core.Services;
using QM.Exchange.Core;
namespace QM.ServiceHost
{
///
/// 服务管理器
///
public class ManagerServer : ServiceControl
{
//登录服务
System.ServiceModel.ServiceHost _loginServiceHost = new System.ServiceModel.ServiceHost(typeof(LoginService));
//双工通讯服务
System.ServiceModel.ServiceHost _DuplexMessageServiceHost = new System.ServiceModel.ServiceHost(typeof(DuplexMessageService));
//普通通讯服务
System.ServiceModel.ServiceHost _generalMessageServiceHost = new System.ServiceModel.ServiceHost(typeof(GeneralMessageService));
//服务管理
private ServiceManager _ServiceManager = new ServiceManager();
#region 启动
public bool StartService()
{
try
{
//装配数据工厂
QMFrameWork.Data.DataFactory.Configure(true);
//初始缓存
CacheManager.Config();
//启动登录服务
if (_loginServiceHost.State != CommunicationState.Opening)
_loginServiceHost.Open();
Console.WriteLine("登录服务:启动");
//启动双工服务
if (_DuplexMessageServiceHost.State != CommunicationState.Opening)
_DuplexMessageServiceHost.Open();
Console.WriteLine("双工通讯服务:启动");
//启动双工服务
if (_generalMessageServiceHost.State != CommunicationState.Opening)
_generalMessageServiceHost.Open();
Console.WriteLine("普通通讯服务:启动");
//服务管理启动
_ServiceManager.Start();
return true;
}
catch (Exception ex)
{
QMFrameWork.Log.LogManager.LogHelper.Error(
new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "启动服务", ErrorInfo = ex });
throw;
}
}
///
/// TopShelf's method delegated to .
///
public bool Start(HostControl hostControl)
{
DaulInstanceService.OnEnterMainService += new EventHandler((obj, e) =>
{
this.StartService();
});
DaulInstanceService.Start();
return true;
}
#endregion
#region 停止
public bool StopService()
{
try
{
//停止服务
QMFrameWork.Data.DataFactory.Stop();
_loginServiceHost.Close();
_DuplexMessageServiceHost.Close();
_ServiceManager.Stop();
return true;
}
catch (Exception ex)
{
QMFrameWork.Log.LogManager.LogHelper.Error(
new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "停止服务", ErrorInfo = ex });
throw;
}
}
///
/// TopShelf's method delegated to .
///
public bool Stop(HostControl hostControl)
{
DaulInstanceService.Stop();
this.StopService();
return true;
}
#endregion
}
}