Esempio n. 1
0
        // 从数据目录装载全部实例定义,并连接服务器
        public static void Initial(string strDataDir)
        {
            DataDir = strDataDir;
            LogDir  = Path.Combine(strDataDir, "log");  // 日志目录
            PathUtil.CreateDirIfNeed(LogDir);

            var repository = log4net.LogManager.CreateRepository("main");

            log4net.GlobalContext.Properties["LogFileName"] = Path.Combine(LogDir, "log_");
            log4net.Config.XmlConfigurator.Configure(repository);

            ZManager.Log = LogManager.GetLogger("main", "zlib");
            _log         = LogManager.GetLogger("main", "capo");

            string strVersion = Assembly.GetAssembly(typeof(ServerInfo)).GetName().Version.ToString();

            // 验证一下日志文件是否允许写入。这样就可以设置一个标志,决定后面的日志信息写入文件还是 Windows 日志
            // DetectWriteErrorLog("*** dp2Capo 开始启动 (dp2Capo 版本: " + strVersion + ")");
            WriteLog("info", "*** dp2Capo 开始启动 (dp2Capo 版本: " + strVersion + ")");

            try
            {
                ServerInfo.LoadCfg(DataDir);
            }
            catch (Exception ex)
            {
                WriteLog("fatal", "dp2Capo 装载全局配置文件阶段出错: " + ex.Message);
                throw ex;
            }

            _exited = false;

            DirectoryInfo root = new DirectoryInfo(strDataDir);
            var           dis  = root.GetDirectories();

            foreach (DirectoryInfo di in dis)
            {
                if (di.Name.ToLower() == "log")
                {
                    continue;
                }
                string strXmlFileName = Path.Combine(di.FullName, "capo.xml");
                if (File.Exists(strXmlFileName) == false)
                {
                    continue;
                }
                Instance instance = new Instance();
                instance.Initial(strXmlFileName);
                _instances.Add(instance);
            }

#if NO
            // 连接服务器,如果暂时连接失败,后面会不断自动重试连接
            foreach (Instance instance in _instances)
            {
                instance.BeginConnnect();
            }
#endif

            _defaultThread.BeginThread();

            _lifeThread.BeginThread();
        }
Esempio n. 2
0
 // 停止一个 Instance
 public ServiceControlResult StopInstance(string strInstanceName)
 {
     return(ServerInfo.StopInstance(strInstanceName));
 }