/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:ServiceHostCollection.cs
* 2.功能描述:服务集合
* 编辑履历:
* 作者 日期 版本 修改内容
* 陈晓野 2014/09/16 1.00 新建
*******************************************************************************/
using System;
using System.Collections.ObjectModel;
using System.ServiceModel;
using Dongke.IBOSS.PRD.WCF.ExHGS3QRS;
using Dongke.IBOSS.PRD.WCF.Services.ConfigSetting;
namespace Dongke.IBOSS.PRD.WCF.Services
{
///
/// 服务集合
///
public class ServiceHostCollection : Collection, IDisposable
{
#region 属性
///
/// 服务名
///
public string ServiceName
{
get
{
return "DKService";
}
}
///
/// IP
///
public string IP
{
get;
set;
}
///
/// 端口
///
public string Port
{
get;
set;
}
#endregion
#region 构造函数
///
/// 构造函数
///
public ServiceHostCollection()
{
}
#endregion
#region 公有方法
///
/// 初始化
///
public void Init()
{
//BatchingHostingSettings settings = BatchingHostingSettings.GetSection();
//foreach (ServiceTypeElement element in settings.ServiceTypes)
//{
// this.AddServiceHost(element.ServiceType);
//}
this.AddServiceHost(typeof(WCFTestService));
this.AddServiceHost(typeof(PDAModuleService));
this.AddServiceHost(typeof(DKIBOSSPRDService));
this.AddServiceHost(typeof(CommonModuleService));
this.AddServiceHost(typeof(CMNModuleService));
this.AddServiceHost(typeof(SystemModuleService));
this.AddServiceHost(typeof(HRModuleService));
this.AddServiceHost(typeof(PCModuleService));
this.AddServiceHost(typeof(PMModuleService));
this.AddServiceHost(typeof(PPModuleService));
this.AddServiceHost(typeof(TATModuleService));
this.AddServiceHost(typeof(ReportModuleService));
this.AddServiceHost(typeof(PMModuleServiceNew));
this.AddServiceHost(typeof(PCModuleServiceNew));
this.AddServiceHost(typeof(PAMModuleService));
this.AddServiceHost(typeof(PublicModuleService));
this.AddServiceHost(typeof(SmartDeviceService));
this.AddServiceHost(typeof(SAPDataService));
this.AddServiceHost(typeof(ExHGS3QR));
}
///
/// 追加服务类型
///
///
public void AddServiceHosts(params Type[] serviceTypes)
{
if (null != serviceTypes)
{
Array.ForEach(serviceTypes, serviceType => AddServiceHost(serviceType));
}
}
///
/// 追加服务类型
///
///
public void AddServiceHost(Type serviceType)
{
Uri baseAddress = new Uri(string.Format("http://{0}:{1}/{2}/{3}", this.IP, this.Port, this.ServiceName, serviceType.Name));
ServiceHost host = new ServiceHost(serviceType, baseAddress);
this.Add(host);
}
///
/// 启动服务
///
public void Open()
{
foreach (ServiceHost host in this)
{
host.Open();
}
}
///
/// 销毁
///
public void Dispose()
{
foreach (IDisposable host in this)
{
host.Dispose();
}
this.Clear();
}
#endregion
}
}