public void Restart(ConfigCenter config)
 {
     CloseTcp();
     System.Threading.Thread.Sleep(2000);
     if (config == null)
     {
         //读取配置文件
         if (ConfigUtils.IsExistConfig())
         {
             //加载配置文件
             try
             {
                 config = ConfigUtils.LoadFromFile();
             }
             catch (Exception ex)
             {
                 LogUtils.Error($"加载配置文件Client.ini失败:{Environment.NewLine}{ex}");
                 return;
             }
         }
         else
         {
             LogUtils.Error($"找不到配置文件.{AppCenter.Instance.ConfigFile}");
             return;
         }
     }
     ConfigCenter.LoadConfig(config);
     //启动服务
     AppCenter.Instance.CurrentGuid = Guid.NewGuid();
     //连接服务器
     P2PClient.ConnectServer();
     AppCenter.Instance.StartNewTask(() => P2PClient.TestAndReconnectServer());
     //启动端口映射
     P2PClient.StartPortMap();
 }
 public void Start()
 {
     LogUtils.InitConfig();
     LogUtils.Info($"客户端版本:{AppCenter.SoftVerSion} 作者:wireboy", false);
     LogUtils.Info($"github地址:https://github.com/bobowire/Wireboy.Socket.P2PSocket", false);
     //读取配置文件
     if (ConfigUtils.IsExistConfig())
     {
         //加载配置文件
         try
         {
             ConfigCenter config = ConfigUtils.LoadFromFile();
             ConfigCenter.LoadConfig(config);
             FileSystemWatcher fw = new FileSystemWatcher(Path.Combine(AppCenter.Instance.RuntimePath, "P2PSocket"), "Client.ini")
             {
                 NotifyFilter = NotifyFilters.LastWrite
             };
             fw.Changed            += Fw_Changed;
             fw.EnableRaisingEvents = true;
         }
         catch (Exception ex)
         {
             LogUtils.Error($"加载配置文件Client.ini失败:{Environment.NewLine}{ex}");
             return;
         }
     }
     else
     {
         LogUtils.Error($"找不到配置文件.{AppCenter.Instance.ConfigFile}");
         return;
     }
     //启动服务
     AppCenter.Instance.CurrentGuid = Guid.NewGuid();
     //连接服务器
     P2PClient.ConnectServer();
     AppCenter.Instance.StartNewTask(() => P2PClient.TestAndReconnectServer());
     //启动端口映射
     P2PClient.StartPortMap();
     System.Threading.Thread.Sleep(1000);
 }
示例#3
0
 internal static void LoadConfig(ConfigCenter config)
 {
     m_instance = config;
 }