using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.ServiceProcess; using System.Runtime.Remoting; using System.Windows.Forms; using System.Xml; using Tigerleq.Log; using Tigerleq.UserException; using Tigerleq.ServerConfig; namespace WindowsService ... { public partial class MainService : ServiceBase ...{ private string m_sServerConfigFile = Application.StartupPath + "/Config/ServerConfig.xml"; private ServerParas m_serverParas = null; public MainService() ...{ InitializeComponent(); try ...{ this.m_serverParas = new ServerParas(this.m_sServerConfigFile); } catch (System.Exception ex) ...{ LogOperate logOperate = new LogOperate(); logOperate.OperateExp(ex, "应用服务构造函数中读取配置信息时出错", ""); } } public void Start(string[] args) ...{ OnStart(args); } protected override void OnStart(string[] args) ...{ // TODO: 在此处添加代码以启动服务。 LogOperate logOperate = null; LogInfo logInfo = new LogInfo("开始启动MainService服务", ""); logOperate = new LogOperate(); logOperate.Write(logInfo); try ...{ RemotingConfiguration.Configure(Application.StartupPath + "/Config/" + this.m_serverParas.appServerParas.RemoteConfigFile,false); logInfo = new LogInfo("成功启动MainService服务", ""); logOperate = new LogOperate(); logOperate.Write(logInfo); } catch (AppErrException) ...{ return; } catch (Exception ex) ...{ LogErr logErr = new LogErr(ex, "在启动MainService服务时出错"); logOperate = new LogOperate(); logOperate.Write(logErr); return; } } protected override void OnStop() ...{ // TODO: 在此处添加代码以执行停止服务所需的关闭操作。 LogOperate logOperate = null; LogInfo logInfo = new LogInfo("停止MainService服务", ""); logOperate = new LogOperate(); logOperate.Write(logInfo); } private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) ...{ LogOperate logOperate = null; LogInfo logInfo = new LogInfo("登陆信息========================", ""); logOperate = new LogOperate(); logOperate.Write(logInfo); GC.Collect(); } protected override void OnPause() ...{ LogOperate logOperate = null; LogInfo logInfo = new LogInfo("暂停MainService服务", ""); logOperate = new LogOperate(); logOperate.Write(logInfo); } protected override void OnContinue() ...{ LogOperate logOperate = null; LogInfo logInfo = new LogInfo("继续MainService服务", ""); logOperate = new LogOperate(); logOperate.Write(logInfo); } /**//// <summary> /// /// </summary> /// <param name="powerStatus"></param> /// <returns></returns> protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus) ...{ LogOperate logOperate = null; LogInfo logInfo = new LogInfo("计算机的电源状态改变:" + powerStatus.ToString(), ""); logOperate = new LogOperate(); logOperate.Write(logInfo); return true; } protected override void OnShutdown() ...{ LogOperate logOperate = null; LogInfo logInfo = new LogInfo("操作系统关闭", ""); logOperate = new LogOperate(); logOperate.Write(logInfo); } }} using System.Collections.Generic; using System.ServiceProcess; using System.Text; using Tigerleq.Log; using System; namespace WindowsService ... { static class Program ...{ /**//// <summary> /// 应用程序的主入口点。 /// </summary> static void Main(string[] args) ...{ // ServiceBase[] ServicesToRun; // 同一进程中可以运行多个用户服务。若要将 // 另一个服务添加到此进程中,请更改下行以 // 创建另一个服务对象。例如, // // ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()}; // LogOperate logOperate = null; try ...{ LogInfo logInfo = new LogInfo("开始将服务加载到内存", ""); logOperate = new LogOperate(); logOperate.Write(logInfo); if (args.Length > 0) ...{ MainService ms = new MainService(); ms.Start(null); //PowerMsgService pms = new PowerMsgService(); //pms.cmd_Start(); //PowerUpdateService pus = new PowerUpdateService(); //pus.cmd_Start(); Console.WriteLine("输入q退出!输入g收集内存!"); char c; while ((c = (char)Console.Read()) != 'q') if (c == 'g') GC.Collect(); } else ...{ System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] ...{ new MainService()//, new PowerMsgService(), new PowerUpdateService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (System.Exception ex) ...{ logOperate = new LogOperate(); logOperate.OperateExp(ex, "在加载各服务时出错", ""); } // ServicesToRun = new ServiceBase[] { new MainService() }; // ServiceBase.Run(ServicesToRun); } }} 以上为服务程序: 一下为控制程序: using System; using System.IO; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.ServiceProcess; using System.Runtime.Serialization; using System.Diagnostics; using System.Xml; using Tigerleq.ServerConfig; using Tigerleq.Log; using Tigerleq.UserException; namespace Window_ContralService ... { public partial class Form_Service_Main : Form ...{ private string m_sServerConfigFile = Application.StartupPath + "/Config/ServerConfig.xml"; private ServerParas m_serverParas = null; public Form_Service_Main() ...{ InitializeComponent(); this.m_serverParas = new ServerParas(this.m_sServerConfigFile); double dInterval = this.m_serverParas.appServerParas.AppConfigRefreshInterval * 1000; this.tmrRefresh.Interval = int.Parse(dInterval.ToString()); this.tmrRefresh.Enabled = true; } private void Form_Service_Main_FormClosing(object sender, FormClosingEventArgs e) ...{ this.Visible = false; this.WindowState = FormWindowState.Minimized; e.Cancel = true; } private void notifyIcon1_DoubleClick(object sender, EventArgs e) ...{ Show_Form(); } private void Show_Form() ...{ if (this.WindowState == FormWindowState.Minimized || this.WindowState == FormWindowState.Maximized) ...{ this.WindowState = FormWindowState.Normal; } this.Activate(); this.Visible = true; } private void toolStripMenuItem_configset_Click(object sender, EventArgs e) ...{ Show_Form(); } private void toolStripMenuItem_exit_Click(object sender, EventArgs e) ...{ this.Dispose(); } private void button_start_Click(object sender, EventArgs e) ...{ LogErr logErr = null; LogOperate logOperate = null; try ...{ Start(); } catch (AppErrException) ...{ MessageBox.Show("在启动应用服务器服务时出错"); } catch (Exception ex) ...{ logErr = new LogErr(ex, "在启动应用服务器服务时出错"); logOperate = new LogOperate(); logOperate.Write(logErr); MessageBox.Show("在启动应用服务器服务时出错"); } } private void button_pause_Click(object sender, EventArgs e) ...{ LogErr logErr = null; LogOperate logOperate = null; try ...{ using (ServiceController sc = new ServiceController(this.m_serverParas.appServerParas.AppServiceName)) ...{ if (sc.Status == ServiceControllerStatus.Running) ...{ if (sc.CanPauseAndContinue) ...{ sc.Pause(); } else ...{ MessageBox.Show("当前服务不能暂停!", "提示"); return; } } } this.RefreshService(); } catch (AppErrException) ...{ MessageBox.Show("在暂停应用服务器服务时出错"); } catch (Exception ex) ...{ logErr = new LogErr(ex, "在暂停应用服务器服务时出错"); logOperate = new LogOperate(); logOperate.Write(logErr); MessageBox.Show("在暂停应用服务器服务时出错"); } } private void button_stop_Click(object sender, EventArgs e) ...{ LogErr logErr = null; LogOperate logOperate = null; try ...{ using (ServiceController sc = new ServiceController(this.m_serverParas.appServerParas.AppServiceName)) ...{ if (sc.Status != ServiceControllerStatus.Stopped) ...{ if (sc.CanShutdown) ...{ sc.Stop(); } else ...{ MessageBox.Show("当前服务不能停止!","提示"); return; } } } this.RefreshService(); } catch (AppErrException) ...{ MessageBox.Show("在停止应用服务器服务时出错"); } catch (Exception ex) ...{ logErr = new LogErr(ex, "在停止应用服务器服务时出错"); logOperate = new LogOperate(); logOperate.Write(logErr); MessageBox.Show("在停止应用服务器服务时出错"); } } private void button_refresh_Click(object sender, EventArgs e) ...{ LogErr logErr = null; LogOperate logOperate = null; try ...{ this.RefreshService(); } catch (AppErrException) ...{ MessageBox.Show("在刷新应用服务器状态时出错"); } catch (Exception ex) ...{ logErr = new LogErr(ex, "在刷新应用服务器状态时出错"); logOperate = new LogOperate(); logOperate.Write(logErr); MessageBox.Show("在刷新应用服务器状态时出错"); } } private void tmrRefresh_Tick(object sender, EventArgs e) ...{ LogErr logErr = null; LogOperate logOperate = null; try ...{ this.RefreshService(); } catch (AppErrException) ...{ } catch (Exception ex) ...{ logErr = new LogErr(ex, "在刷新应用服务器状态时出错"); logOperate = new LogOperate(); logOperate.Write(logErr); } } private void RefreshService() ...{ LogOperate logOperate = null; //bool bAllServiceStart = true; //bool bAllServiceStop = true; try ...{ GC.Collect(); GC.Collect(); using (ServiceController sc = new ServiceController(this.m_serverParas.appServerParas.AppServiceName)) ...{ ServiceControllerStatus aa = sc.Status; if (sc.Status == ServiceControllerStatus.Running) ...{ this.button_start.Enabled = false; this.button_pause.Enabled = true; this.button_stop.Enabled = true; this.label_start.Enabled = false; this.label_pause.Enabled = true; this.label_stop.Enabled = true; this.ToolStripMenuItem_start.Enabled = false; this.ToolStripMenuItem_pause.Enabled = true; this.ToolStripMenuItem_stop.Enabled = true; this.notifyIcon1.Icon = Icon.ExtractAssociatedIcon(@"ICO etwork.ico"); //bAllServiceStop = false; } else if (sc.Status == ServiceControllerStatus.Stopped) ...{ this.button_start.Enabled = true; this.button_pause.Enabled = false; this.button_stop.Enabled = false; this.label_start.Enabled = true; this.label_pause.Enabled = false; this.label_stop.Enabled = false; this.ToolStripMenuItem_start.Enabled = true; this.ToolStripMenuItem_pause.Enabled = false; this.ToolStripMenuItem_stop.Enabled = false; this.notifyIcon1.Icon = Icon.ExtractAssociatedIcon(@"ICOstop.ico"); this.tmrAutoStart.Enabled = true; // bAllServiceStart = false; } else if (sc.Status == ServiceControllerStatus.Paused) ...{ this.button_start.Enabled = true; this.button_pause.Enabled = false; this.button_stop.Enabled = true; this.label_start.Enabled = true; this.label_pause.Enabled = false; this.label_stop.Enabled = true; this.ToolStripMenuItem_start.Enabled = true; this.ToolStripMenuItem_pause.Enabled = false; this.ToolStripMenuItem_stop.Enabled = true; this.notifyIcon1.Icon = Icon.ExtractAssociatedIcon(@"ICOpause.ico"); this.tmrAutoStart.Enabled = true; } else ...{ this.button_start.Enabled = false; this.button_pause.Enabled = false; this.button_stop.Enabled = false; this.ToolStripMenuItem_start.Enabled = false; this.ToolStripMenuItem_pause.Enabled = false; this.ToolStripMenuItem_stop.Enabled = false; //bAllServiceStart = false; } } //using (ServiceController sc = new ServiceController( this.m_serverParas.appServerParas.MsgServiceName )) //{ // if(sc.Status==ServiceControllerStatus.Running) // { // this.mnuStartMsgServer.Enabled = false; // this.mnuStopMsgServer.Enabled = true; // bAllServiceStop = false; // } // else if( sc.Status == ServiceControllerStatus.Stopped ) // { // this.mnuStartMsgServer.Enabled = true; // this.mnuStopMsgServer.Enabled = false; // bAllServiceStart = false; // } // else // { // this.mnuStartMsgServer.Enabled = false; // this.mnuStopMsgServer.Enabled = false; // bAllServiceStart = false; // } //} //using (ServiceController sc = new ServiceController(this.m_serverParas.appServerParas.UpdateServiceName)) //{ // if (sc.Status == ServiceControllerStatus.Running) // { // this.ToolStripMenuItem_startUpdate.Enabled = false; // this.ToolStripMenuItem_stopUpdate.Enabled = true; // bAllServiceStop = false; // } // else if (sc.Status == ServiceControllerStatus.Stopped) // { // this.ToolStripMenuItem_startUpdate.Enabled = true; // this.ToolStripMenuItem_stopUpdate.Enabled = false; // bAllServiceStart = false; // } // else // { // this.ToolStripMenuItem_startUpdate.Enabled = false; // this.ToolStripMenuItem_stopUpdate.Enabled = false; // bAllServiceStart = false; // } //} //if (bAllServiceStart) //{ // this.mnuitmStartAllService.Enabled = false; // this.mnuitmStopAllService.Enabled = true; //} //if (bAllServiceStop) //{ // this.mnuitmStopAllService.Enabled = false; // this.mnuitmStartAllService.Enabled = true; //} //if (!bAllServiceStart && !bAllServiceStop) //{ // this.mnuitmStartAllService.Enabled = true; // this.mnuitmStopAllService.Enabled = true; //} } catch (Exception ex) ...{ logOperate = new LogOperate(); logOperate.OperateExp(ex, "在根据服务的当前状态更新控件状态时出错", ""); } } private void tmrAutoStart_Tick(object sender, EventArgs e) ...{ LogErr logErr = null; LogOperate logOperate = null; try ...{ Start(); this.tmrAutoStart.Enabled = false; } catch (AppErrException) ...{ } catch (Exception ex) ...{ logErr = new LogErr(ex, "在自动启动服务时出错"); logOperate = new LogOperate(); logOperate.Write(logErr); } } public void Start() ...{ LogOperate logOperate = null; try ...{ using (ServiceController sc = new ServiceController(this.m_serverParas.appServerParas.AppServiceName)) ...{ if (sc.Status == ServiceControllerStatus.Running) ...{ return; } if (sc.Status == ServiceControllerStatus.Paused) ...{ sc.Continue(); } else ...{ sc.Start(); } } this.RefreshService(); } catch (Exception ex) ...{ logOperate = new LogOperate(); logOperate.OperateExp(ex, "在启动应用服务器的服务时出错", ""); } } }} 一些用到的类: using System; using System.IO; using System.Xml; using System.Text; using System.Net; using System.Windows.Forms; using Tigerleq.Log; namespace Tigerleq.ServerConfig ... { public class AppServerParas ...{ 属性定义#region 属性定义 private string m_sIP = null; private string m_sPort = "8000"; private string m_sRemoteConfigFile = "ServerRemoteConfig.xml"; private string m_sClientMainFormTitle = "成都后墨科技数据中心"; private string m_sAppServiceName = "MainService"; private string m_sMsgServiceName = "PowerMsgService"; private string m_sUpdateServiceName = "PowerUpdateService"; private double m_dAppConfigRefreshInterval = 3; public string IP ...{ get ...{ return this.m_sIP; } set ...{ this.m_sIP = value.Trim(); } } public string Port ...{ get ...{ return this.m_sPort; } set ...{ this.m_sPort = value.Trim(); } } public string RemoteConfigFile ...{ get ...{ return this.m_sRemoteConfigFile; } set ...{ this.m_sRemoteConfigFile = value.Trim(); } } public string ClientMainFormTitle ...{ get ...{ return this.m_sClientMainFormTitle; } set ...{ this.m_sClientMainFormTitle = value.Trim(); } } public string AppServiceName ...{ get ...{ return this.m_sAppServiceName; } set ...{ this.m_sAppServiceName = value.Trim(); } } public string MsgServiceName ...{ get ...{ return this.m_sMsgServiceName; } set ...{ this.m_sMsgServiceName = value.Trim(); } } public string UpdateServiceName ...{ get ...{ return this.m_sUpdateServiceName; } set ...{ this.m_sUpdateServiceName = value.Trim(); } } public double AppConfigRefreshInterval ...{ get ...{ return this.m_dAppConfigRefreshInterval; } set ...{ this.m_dAppConfigRefreshInterval = value; } } #endregion public AppServerParas(XmlNode p_nd) ...{ try ...{ this.m_sIP = p_nd["IP"].InnerText.Trim(); this.m_sPort = p_nd["Port"].InnerText.Trim(); this.m_sRemoteConfigFile = p_nd["RemoteConfigFile"].InnerText.Trim(); int iLp = 0; this.m_sClientMainFormTitle = p_nd["ClientMainFormTitle"].InnerText.Trim(); this.m_sAppServiceName = p_nd["AppServiceName"].InnerText.Trim(); this.m_sMsgServiceName = p_nd["MsgServiceName"].InnerText.Trim(); this.m_sUpdateServiceName = p_nd["UpdateServiceName"].InnerText.Trim(); this.m_dAppConfigRefreshInterval = double.Parse(p_nd["AppConfigRefreshInterval"].InnerText); } catch (System.Exception ex) ...{ LogOperate logOperate = new LogOperate(); logOperate.OperateExp(ex, "在初始化应用服务配置参数类时出错", ""); } } public AppServerParas() ...{ IPAddress[] arripAddress = Dns.Resolve(System.Environment.MachineName).AddressList; this.m_sIP = arripAddress[0].ToString(); } public AppServerParas(AppServerParas p_appServerParas) ...{ this.m_dAppConfigRefreshInterval = p_appServerParas.AppConfigRefreshInterval; this.m_sAppServiceName = p_appServerParas.AppServiceName; this.m_sClientMainFormTitle = p_appServerParas.ClientMainFormTitle; this.m_sIP = p_appServerParas.IP; this.m_sMsgServiceName = p_appServerParas.MsgServiceName; this.m_sPort = p_appServerParas.Port; this.m_sRemoteConfigFile = p_appServerParas.RemoteConfigFile; this.m_sUpdateServiceName = p_appServerParas.UpdateServiceName; } public void InputXmlDoc(XmlDocument p_xDoc, XmlNode p_nd) ...{ try ...{ XmlNode ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "IP", ""); ndNew.InnerText = this.m_sIP; p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "Port", ""); ndNew.InnerText = this.m_sPort; p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "RemoteConfigFile", ""); ndNew.InnerText = this.m_sRemoteConfigFile; p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "ClientMainFormTitle", ""); ndNew.InnerText = this.m_sClientMainFormTitle; p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "AppServiceName", ""); ndNew.InnerText = this.m_sAppServiceName; p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "MsgServiceName", ""); ndNew.InnerText = this.m_sMsgServiceName; p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "UpdateServiceName", ""); ndNew.InnerText = this.m_sUpdateServiceName; p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "AppConfigRefreshInterval", ""); ndNew.InnerText = this.m_dAppConfigRefreshInterval.ToString(); p_nd.AppendChild(ndNew); } catch (System.Exception ex) ...{ LogOperate logOperate = new LogOperate(); logOperate.OperateExp(ex, "在将应用服务配置参数存入xml文档中时出错", ""); } } }} using System; using System.IO; using System.Xml; using System.Text; using System.Net; using System.Windows.Forms; using Tigerleq.Log; namespace Tigerleq.ServerConfig ... { public class ServerParas ...{ 属性定义#region 属性定义 private AppServerParas m_appServerParas = null; private MsgServerParas m_msgServerParas = null; private UpdateServerParas m_updateServerParas = null; private string m_sFile = Application.StartupPath + "/Config/ServerConfig.xml"; public AppServerParas appServerParas ...{ get ...{ return this.m_appServerParas; } } public MsgServerParas msgServerParas ...{ get ...{ return this.m_msgServerParas; } } public UpdateServerParas updateServerParas ...{ get ...{ return this.m_updateServerParas; } } #endregion public ServerParas(string p_sFile) ...{ try ...{ this.m_sFile = p_sFile.Trim(); XmlDocument xDoc = new XmlDocument(); xDoc.Load(this.m_sFile); XmlNode ndRoot = xDoc.DocumentElement; this.m_appServerParas = new AppServerParas(ndRoot["AppServerParas"]); //屏蔽了消息服务器,和更新服务器 //this.m_msgServerParas = new MsgServerParas(ndRoot["MsgServerParas"]); //this.m_updateServerParas = new UpdateServerParas(ndRoot["UpdateServerParas"]); ndRoot = null; xDoc = null; } catch (System.Exception ex) ...{ LogOperate logOperate = new LogOperate(); logOperate.OperateExp(ex, "在初始化应用服务器配置类时出错", ""); logOperate = null; } } public ServerParas(ServerParas p_serverParas) ...{ this.m_appServerParas = new AppServerParas(p_serverParas.appServerParas); } public ServerParas() ...{ this.m_appServerParas = new AppServerParas(); this.m_msgServerParas = new MsgServerParas(); this.m_updateServerParas = new UpdateServerParas(); } public void Save() ...{ try ...{ XmlDocument xDoc = new XmlDocument(); XmlDeclaration xmlDecla = xDoc.CreateXmlDeclaration("1.0", "GB2312", "yes"); xDoc.AppendChild(xmlDecla); XmlNode ndNew = xDoc.CreateNode(XmlNodeType.Element, "ServerParas", ""); xDoc.AppendChild(ndNew); ndNew = xDoc.CreateNode(XmlNodeType.Element, "AppServerParas", ""); xDoc["ServerParas"].AppendChild(ndNew); ndNew = xDoc.CreateNode(XmlNodeType.Element, "MsgServerParas", ""); xDoc["ServerParas"].AppendChild(ndNew); ndNew = xDoc.CreateNode(XmlNodeType.Element, "UpdateServerParas", ""); xDoc["ServerParas"].AppendChild(ndNew); this.m_appServerParas.InputXmlDoc(xDoc, xDoc["ServerParas"]["AppServerParas"]); this.m_msgServerParas.InputXmlDoc(xDoc, xDoc["ServerParas"]["MsgServerParas"]); this.m_updateServerParas.InputXmlDoc(xDoc, xDoc["ServerParas"]["UpdateServerParas"]); string sDirectory = this.m_sFile.Substring(0, this.m_sFile.LastIndexOf("/")); Directory.CreateDirectory(sDirectory); XmlTextWriter xmlTextWriter = new XmlTextWriter(this.m_sFile, Encoding.Default); xmlTextWriter.Formatting = Formatting.Indented; xDoc.WriteTo(xmlTextWriter); xmlTextWriter.Flush(); xmlTextWriter.Close(); xmlTextWriter = null; xDoc = null; } catch (System.Exception ex) ...{ LogOperate logOperate = new LogOperate(); logOperate.OperateExp(ex, "在将配置信息写入文件中时出错", ""); } } }} using System; using System.Collections.Generic; using System.Text; using System.Xml; using Tigerleq.Log; namespace Tigerleq.ServerConfig ... { public class MsgServerParas ...{ 属性定义#region 属性定义 private string m_sServerListenPort = "8001"; private string m_sClientListenPort = "8001"; private int m_iReceiveTimeOut = 20; private int m_iSendTiemOut = 20; private int m_iMessageLen = 200; private string m_sOnlineUsersFileName = "OnlineUsers.txt"; private int m_iFileMessageLen = 250; private double m_dClearInterval = 5; private double m_dClientContactInterval = 4; private string m_sClearFileTime = "2:00"; private double m_dMonitorRefreshInterval = 4; public string ServerListenPort ...{ get ...{ return this.m_sServerListenPort; } set ...{ this.m_sServerListenPort = value.Trim(); } } public string ClientListenPort ...{ get ...{ return this.m_sClientListenPort; } set ...{ this.m_sClientListenPort = value.Trim(); } } public int ReceiveTimeOut ...{ get ...{ return this.m_iReceiveTimeOut; } set ...{ this.m_iReceiveTimeOut = value; } } public int SendTimeOut ...{ get ...{ return this.m_iSendTiemOut; } set ...{ this.m_iSendTiemOut = value; } } public int MessageLen ...{ get ...{ return this.m_iMessageLen; } set ...{ this.m_iMessageLen = value; } } public string OnlineUsersFileName ...{ get ...{ return this.m_sOnlineUsersFileName; } set ...{ this.m_sOnlineUsersFileName = value.Trim(); } } public int FileMessageLen ...{ get ...{ return this.m_iFileMessageLen; } set ...{ this.m_iFileMessageLen = value; } } public double ClearInterval ...{ get ...{ return this.m_dClearInterval; } set ...{ this.m_dClearInterval = value; } } public double ClientContactInterval ...{ get ...{ return this.m_dClientContactInterval; } set ...{ this.m_dClientContactInterval = value; } } public string ClearFileTime ...{ get ...{ return this.m_sClearFileTime; } set ...{ this.m_sClearFileTime = value.Trim(); } } public double MonitorRefreshInterval ...{ get ...{ return this.m_dMonitorRefreshInterval; } set ...{ this.m_dMonitorRefreshInterval = value; } } #endregion public MsgServerParas(XmlNode p_nd) ...{ try ...{ this.m_sServerListenPort = p_nd["ServerListenPort"].InnerText; this.m_sClientListenPort = p_nd["ClientListenPort"].InnerText; this.m_iReceiveTimeOut = int.Parse(p_nd["ReceiveTimeOut"].InnerText); this.m_iSendTiemOut = int.Parse(p_nd["SendTimeOut"].InnerText); this.m_iMessageLen = int.Parse(p_nd["MessageLen"].InnerText); this.m_sOnlineUsersFileName = p_nd["OnlineUsersFileName"].InnerText; this.m_iFileMessageLen = int.Parse(p_nd["FileMessageLen"].InnerText); this.m_dClearInterval = double.Parse(p_nd["ClearInterval"].InnerText); this.m_dClientContactInterval = double.Parse(p_nd["ClientContactInterval"].InnerText); this.m_sClearFileTime = p_nd["ClearFileTime"].InnerText; this.m_dMonitorRefreshInterval = double.Parse(p_nd["MonitorRefreshInterval"].InnerText); } catch (System.Exception ex) ...{ LogOperate logOperate = new LogOperate(); logOperate.OperateExp(ex, "在初始化消息服务配置参数类时出错", ""); logOperate = null; } } public MsgServerParas() ...{ } public void InputXmlDoc(XmlDocument p_xDoc, XmlNode p_nd) ...{ try ...{ XmlNode ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "ServerListenPort", ""); ndNew.InnerText = this.m_sServerListenPort; p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "ClientListenPort", ""); ndNew.InnerText = this.m_sClientListenPort; p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "ReceiveTimeOut", ""); ndNew.InnerText = this.m_iReceiveTimeOut.ToString(); p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "SendTimeOut", ""); ndNew.InnerText = this.m_iSendTiemOut.ToString(); p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "MessageLen", ""); ndNew.InnerText = this.m_iMessageLen.ToString(); p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "OnlineUsersFileName", ""); ndNew.InnerText = this.m_sOnlineUsersFileName; p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "FileMessageLen", ""); ndNew.InnerText = this.m_iFileMessageLen.ToString(); p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "ClearInterval", ""); ndNew.InnerText = this.m_dClearInterval.ToString(); p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "ClientContactInterval", ""); ndNew.InnerText = this.m_dClientContactInterval.ToString(); p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "ClearFileTime", ""); ndNew.InnerText = this.m_sClearFileTime.ToString(); p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "MonitorRefreshInterval", ""); ndNew.InnerText = this.m_dMonitorRefreshInterval.ToString(); p_nd.AppendChild(ndNew); } catch (System.Exception ex) ...{ LogOperate logOperate = new LogOperate(); logOperate.OperateExp(ex, "在将消息服务配置参数存入xml文档中时出错", ""); } } }} using System; using System.Collections.Generic; using System.Text; using System.Xml; using Tigerleq.Log; namespace Tigerleq.ServerConfig ... { public class UpdateServerParas ...{ 属性定义#region 属性定义 private string m_sUpdateFilesPath = @".UpdateClient"; private string m_sListenPort = "8002"; private int m_iMultiThread = 1; private int m_iReceiveTimeOut = 60; private int m_iSendTimeOut = 60; private int m_iFileNameLen = 100; private int m_iUpdateType = -1; public string UpdateFilesPath ...{ get ...{ return this.m_sUpdateFilesPath; } set ...{ this.m_sUpdateFilesPath = value.Trim(); } } public string ListenPort ...{ get ...{ return this.m_sListenPort; } set ...{ this.m_sListenPort = value.Trim(); } } public int MultiThread ...{ get ...{ return this.m_iMultiThread; } set ...{ this.m_iMultiThread = value; } } public int ReceiveTimeOut ...{ get ...{ return this.m_iReceiveTimeOut; } set ...{ this.m_iReceiveTimeOut = value; } } public int SendTimeOut ...{ get ...{ return this.m_iSendTimeOut; } set ...{ this.m_iSendTimeOut = value; } } public int FileNameLen ...{ get ...{ return this.m_iFileNameLen; } set ...{ this.m_iFileNameLen = value; } } public int UpdateType ...{ get ...{ return this.m_iUpdateType; } set ...{ this.m_iUpdateType = value; } } #endregion public UpdateServerParas(XmlNode p_nd) ...{ try ...{ this.m_sUpdateFilesPath = p_nd["UpdateFilesPath"].InnerText; this.m_sListenPort = p_nd["ListenPort"].InnerText; this.m_iMultiThread = int.Parse(p_nd["MultiThread"].InnerText); this.m_iReceiveTimeOut = int.Parse(p_nd["ReceiveTimeOut"].InnerText); this.m_iSendTimeOut = int.Parse(p_nd["SendTimeOut"].InnerText); this.m_iFileNameLen = int.Parse(p_nd["FileNameLen"].InnerText); this.m_iUpdateType = int.Parse(p_nd["UpdateType"].InnerText); } catch (System.Exception ex) ...{ LogOperate logOperate = new LogOperate(); logOperate.OperateExp(ex, "在初始化自动更新服务的配置参数类时出错", ""); logOperate = null; } } public UpdateServerParas() ...{ } public void InputXmlDoc(XmlDocument p_xDoc, XmlNode p_nd) ...{ try ...{ XmlNode ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "UpdateFilesPath", ""); ndNew.InnerText = this.m_sUpdateFilesPath; p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "ListenPort", ""); ndNew.InnerText = this.m_sListenPort; p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "MultiThread", ""); ndNew.InnerText = this.m_iMultiThread.ToString(); p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "ReceiveTimeOut", ""); ndNew.InnerText = this.m_iReceiveTimeOut.ToString(); p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "SendTimeOut", ""); ndNew.InnerText = this.m_iSendTimeOut.ToString(); p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "FileNameLen", ""); ndNew.InnerText = this.m_iFileNameLen.ToString(); p_nd.AppendChild(ndNew); ndNew = p_xDoc.CreateNode(XmlNodeType.Element, "UpdateType", ""); ndNew.InnerText = this.m_iUpdateType.ToString(); p_nd.AppendChild(ndNew); } catch (System.Exception ex) ...{ LogOperate logOperate = new LogOperate(); logOperate.OperateExp(ex, "在将自动更新服务配置参数存入xml文档中时出错", ""); } } }} using System; using System.Collections.Generic; using System.Text; namespace Tigerleq.ClientConfig ... { public class ClientParas ...{ public static string IP = ""; public static string Port = "8000"; public static string UserNameFile = "UserName.txt"; private ClientParas() ...{ } }}