Пример #1
0
 public void Start()
 {
     try
     {
         LogUtils.InitConfig();
         LogUtils.Info($"客户端版本:{AppCenter.Instance.SoftVerSion} 作者:wireboy", false);
         LogUtils.Info($"github地址:https://github.com/bobowire/Wireboy.Socket.P2PSocket", false);
         //读取配置文件
         if (ConfigUtils.IsExistConfig())
         {
             //初始化全局变量
             InitGlobal();
             //加载配置文件
             ConfigCenter config = ConfigUtils.LoadFromFile();
             ConfigCenter.LoadConfig(config);
             FileSystemWatcher fw = new FileSystemWatcher(Path.Combine(AppCenter.Instance.RuntimePath, "P2PSocket"), "Server.ini")
             {
                 NotifyFilter = NotifyFilters.LastWrite
             };
             fw.Changed            += Fw_Changed;
             fw.EnableRaisingEvents = true;
             //启动服务
             P2PServer.StartServer();
         }
         else
         {
             LogUtils.Error($"找不到配置文件.{AppCenter.Instance.ConfigFile}");
         }
     }
     catch (Exception ex)
     {
         LogUtils.Error($"启动失败:{ex}");
     }
     System.Threading.Thread.Sleep(1000);
 }
Пример #2
0
 public void Restart(ConfigCenter config)
 {
     Stop();
     System.Threading.Thread.Sleep(2000);
     if (config == null)
     {
         //读取配置文件
         if (ConfigUtils.IsExistConfig())
         {
             //加载配置文件
             try
             {
                 config = ConfigUtils.LoadFromFile();
             }
             catch (Exception ex)
             {
                 LogUtils.Error($"加载配置文件Server.ini失败:{Environment.NewLine}{ex}");
                 return;
             }
         }
         else
         {
             LogUtils.Error($"找不到配置文件.{AppCenter.Instance.ConfigFile}");
             return;
         }
     }
     //启动服务
     AppCenter.Instance.CurrentGuid = Guid.NewGuid();
     ConfigCenter.LoadConfig(config);
     //启动服务
     P2PServer.StartServer();
 }
 internal static void LoadConfig(ConfigCenter config)
 {
     m_instance = config;
 }