You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
4.5 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Globalization;
namespace CommService
{
/*
*类名称CommPlatform
*创建人:韩荣伟
*创建时间2010-10-30
*功能描述:通信平台管理类
*/
class CommPlatform
{
private System.Timers.Timer aTimer = null;
private System.Timers.Timer bTimer = null;
public TCPServer tcpServer;
//public void Init()
//{
//}
/*
*方法名称Start
*创建人:韩荣伟
*创建时间2010-10-30
*参数描述void
*返回描述void
*功能描述:通信平台启动
*/
public void Start()
{
//started = true;
//Common.logFile.write("启动侦听 成功");
//Common.tcpServer.frmMain = this;
//Common.messageHandler = new MessageHandler();
//////////////////////////////////////////////////////////////////////////////////////////
Common.logFile.write("commServer starting...", LogFile.LOGLVL_NORMAL);
////
tcpServer = new TCPServer(Common.configReader.sListenIP, Common.configReader.nListenPort);
Common.platForm.tcpServer.Start();
StartTimer();
}
/*
*方法名称Stop
*创建人:韩荣伟
*创建时间2010-10-30
*参数描述void
*返回描述void
*功能描述:通信平台停止
*/
public void Stop()
{
//
StopTimer();
//Common.tcpServer.Stop();
//started = false;
//Common.logFile.write("停止侦听 成功");
//lsvDeviceList.Items.Clear();
Common.platForm.tcpServer.Stop();
Common.logFile.write("commServer stopped.", LogFile.LOGLVL_NORMAL);
}
/*
*方法名称OnTimedEvent
*创建人:韩荣伟
*创建时间2010-10-30
*参数描述object source 发起者, ElapsedEventArgs e 定时器事件参数
*返回描述void
*功能描述:定时器执行函数,用于业务功能的处理
*/
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
//Common.logFile.write("commServer OnTimedEvent");
//暂时停止心跳检测sun
Common.platForm.tcpServer.TimeOut();
}
/*
*方法名称OnTimedEvent2
*创建人:韩荣伟
*创建时间2010-10-30
*参数描述object source 发起者, ElapsedEventArgs e 定时器事件参数
*返回描述void
*功能描述:定时器执行函数,删除过期日志文件
*/
private static void OnTimedEvent2(object source, ElapsedEventArgs e)
{
DateTime dtBase = DateTime.Now.AddDays(-30);
string sFlag = dtBase.ToString("yyyyMMdd", CultureInfo.InvariantCulture);
Common.logFile.DeleteAtFolder(Common.logFile.sRootPath, sFlag);
}
/*
*方法名称StartTimer
*创建人:韩荣伟
*创建时间2010-10-30
*参数描述void
*返回描述void
*功能描述:启动两个定时器
*/
private void StartTimer()
{
aTimer = new System.Timers.Timer(1000);
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
if (aTimer.Enabled == false)
{
aTimer.Enabled = true;
}
bTimer = new System.Timers.Timer(1000 * 3600 * 24);
bTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent2);
if (bTimer.Enabled == false)
{
bTimer.Enabled = true;
}
}
/*
*方法名称StopTimer
*创建人:韩荣伟
*创建时间2010-10-30
*参数描述void
*返回描述void
*功能描述:停止两个定时器
*/
private void StopTimer()
{
if (bTimer != null && bTimer.Enabled == true)
{
bTimer.Enabled = false;
}
if (aTimer != null && aTimer.Enabled == true)
{
aTimer.Enabled = false;
}
}
}
}