51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using SuperSocket.SocketBase;
|
||
using SuperSocket.SocketEngine;
|
||
using System;
|
||
using System.IO;
|
||
using WX.CRM.Common;
|
||
|
||
namespace WX.CRM.DataSynServer.Socket
|
||
{
|
||
public class SocketServiceManage
|
||
{
|
||
private static IBootstrap IBootstrap { get; set; }
|
||
private static readonly string LogServiceConfigFileName = Config.LogServiceConfigFileName;
|
||
|
||
public static bool Start()
|
||
{
|
||
try
|
||
{
|
||
var configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, LogServiceConfigFileName);
|
||
IBootstrap = BootstrapFactory.CreateBootstrapFromConfigFile(configFilePath);
|
||
if (!IBootstrap.Initialize())
|
||
{
|
||
Console.WriteLine("日志服务初始化失败");
|
||
LogHelper.Error("日志服务启动失败!");
|
||
return false;
|
||
}
|
||
var result = IBootstrap.Start();
|
||
if (result == StartResult.Failed)
|
||
{
|
||
Console.WriteLine("日志服务启动失败!");
|
||
LogHelper.Error("日志服务启动失败!");
|
||
return false;
|
||
}
|
||
LogHelper.Info("Socket服务启动成功!");
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error($"启动日志Socket服务失败:{ex}");
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public static void Stop()
|
||
{
|
||
if (IBootstrap != null)
|
||
IBootstrap.Stop();
|
||
IBootstrap = null;
|
||
}
|
||
}
|
||
}
|