//private bool IsBindingLib = false; /// <summary> /// 构造函数 /// </summary> /// <param name="strDp2Url"></param> /// <param name="strDp2UserName"></param> /// <param name="strDp2Password"></param> /// <param name="strDp2WeiXinUrl"></param> /// <param name="strDp2WeiXinLogDir"></param> public void Init(string strDp2Url, string strDp2UserName, string strDp2Password, string strDp2WeiXinUrl, string strDp2WeiXinLogDir, bool isUseMongoDb, string mongoDbConnStr, string instancePrefix //bool isBindingLib ) { this.dp2Url = strDp2Url; this.dp2UserName = strDp2UserName; this.dp2Password = strDp2Password; this.dp2WeiXinUrl = strDp2WeiXinUrl; this.dp2WeiXinLogDir = strDp2WeiXinLogDir; // 通道池对象 ChannelPool = new LibraryChannelPool(); ChannelPool.BeforeLogin -= new BeforeLoginEventHandle(Channel_BeforeLogin); ChannelPool.BeforeLogin += new BeforeLoginEventHandle(Channel_BeforeLogin); // 使用mongodb存储微信用户与读者绑定关系 this.IsUseMongoDb = isUseMongoDb; if (this.IsUseMongoDb == true) { WxUserDatabase.Current.Open(mongoDbConnStr, instancePrefix); } //this.IsBindingLib = isBindingLib; }
/// <summary> /// 构造函数 /// </summary> /// <param name="strDp2Url"></param> /// <param name="strDp2UserName"></param> /// <param name="strDp2Password"></param> /// <param name="strDp2WeiXinUrl"></param> /// <param name="strDp2WeiXinLogDir"></param> public void Init(string strDp2Url, string strDp2UserName, string strDp2Password, string strDp2WeiXinUrl, string strDp2WeiXinLogDir) { this.dp2Url = strDp2Url; this.dp2UserName = strDp2UserName; this.dp2Password = strDp2Password; this.dp2WeiXinUrl = strDp2WeiXinUrl; this.dp2WeiXinLogDir = strDp2WeiXinLogDir; // 通道池对象 ChannelPool = new LibraryChannelPool(); ChannelPool.BeforeLogin -= new BeforeLoginEventHandle(Channel_BeforeLogin); ChannelPool.BeforeLogin += new BeforeLoginEventHandle(Channel_BeforeLogin); }
public int Load( bool bReload, string strDataDir, string strHostDir, out string strError) { strError = ""; int nRet = 0; this.m_lock.AcquireWriterLock(m_nLockTimeout); try { OpacApplication app = this; // new CirculationApplication(); this.DataDir = strDataDir; this.HostDir = strHostDir; string strFileName = PathUtil.MergePath(strDataDir, "opac.xml"); string strBinDir = PathUtil.MergePath(strHostDir, "bin"); string strCfgDir = PathUtil.MergePath(strDataDir, "cfgs"); string strCfgMapDir = PathUtil.MergePath(strDataDir, "cfgsmap"); string strLogDir = PathUtil.MergePath(strDataDir, "log"); string strSessionDir = PathUtil.MergePath(strDataDir, "session"); string strColumnDir = PathUtil.MergePath(strDataDir, "column"); // string strStyleDir = PathUtil.MergePath(strDataDir, "style"); // PathUtil.CreateDirIfNeed(strStyleDir); // 确保目录创建 app.m_strFileName = strFileName; app.CfgDir = strCfgDir; app.CfgMapDir = strCfgMapDir; PathUtil.CreateDirIfNeed(app.CfgMapDir); // 确保目录创建 // log app.LogDir = strLogDir; // 日志存储目录 PathUtil.CreateDirIfNeed(app.LogDir); // 确保目录创建 // session临时文件 app.SessionDir = strSessionDir; PathUtil.CreateDirIfNeed(app.SessionDir); // 确保目录创建 // bin dir app.BinDir = strBinDir; nRet = 0; if (bReload == false) { if (app.HasAppBeenKilled() == true) { app.WriteErrorLog("*** 发现opac service先前曾被意外终止 ***"); } } if (bReload == true) app.WriteErrorLog("opac service 开始重新装载 " + this.m_strFileName); else app.WriteErrorLog("opac service 开始启动。"); // if (bReload == false) { app.m_strWebuiFileName = PathUtil.MergePath(strDataDir, "webui.xml"); // string strWebUiFileName = PathUtil.MergePath(strDataDir, "webui.xml"); nRet = LoadWebuiCfgDom(out strError); if (nRet == -1) { // strError = "装载配置文件-- '" + strWebUiFileName + "'时发生错误,原因:" + ex.Message; app.WriteErrorLog(strError); goto ERROR1; } } // XmlDocument dom = new XmlDocument(); try { dom.Load(strFileName); } catch (FileNotFoundException) { strError = "file '" + strFileName + "' not found ..."; goto ERROR1; } catch (Exception ex) { strError = "装载配置文件-- '" + strFileName + "' 时发生错误,错误类型:" + ex.GetType().ToString() + ",原因:" + ex.Message; app.WriteErrorLog(strError); // throw ex; goto ERROR1; } app.OpacCfgDom = dom; // *** 进入内存的参数开始 // 注意修改了这些参数的结构后,必须相应修改Save()函数的相关片断 // 2011/1/7 bool bValue = false; DomUtil.GetBooleanParam(app.OpacCfgDom.DocumentElement, "debugMode", false, out bValue, out strError); this.DebugMode = bValue; // 应用服务器参数 // 元素<libraryServer> // 属性url/username/password XmlElement node = dom.DocumentElement.SelectSingleNode("libraryServer") as XmlElement; if (node != null) { app.WsUrl = DomUtil.GetAttr(node, "url"); app.ReportDir = DomUtil.GetAttr(node, "reportDir"); app.ManagerUserName = DomUtil.GetAttr(node, "username"); try { app.ManagerPassword = Cryptography.Decrypt( DomUtil.GetAttr(node, "password"), EncryptKey); } catch { strError = "<libraryServer>元素password属性中的密码设置不正确"; // throw new Exception(); goto ERROR1; } CfgsMap = new CfgsMap(this.CfgMapDir, this.WsUrl); CfgsMap.Clear(); } // OPAC服务器 // 元素<opacServer> // 属性url node = dom.DocumentElement.SelectSingleNode("//opacServer") as XmlElement; if (node != null) { app.OpacServerUrl = DomUtil.GetAttr(node, "url"); } node = dom.DocumentElement.SelectSingleNode("mongoDB") as XmlElement; if (node != null) { app.MongoDbConnStr = DomUtil.GetAttr(node, "connectionString"); app.MongoDbInstancePrefix = node.GetAttribute("instancePrefix"); } // // string strDebugInfo = ""; // return: // -2 dp2Library版本不匹配 // -1 出错 // 0 成功 nRet = GetXmlDefs( false, out strDebugInfo, out strError); if (nRet != 0) { app.WriteErrorLog("ERR001 首次初始化XmlDefs失败: " + strError); // goto ERROR1; } else { // 初始化虚拟库集合定义对象 nRet = InitialVdbs( out strError); if (nRet == -1) { app.WriteErrorLog("ERR002 初始化vdbs失败: " + strError); goto ERROR1; // 这样的初始化失败不是因为通讯问题,而是数据本身的问题,所以不再继续load()函数后面的部分。应当在解决问题后重新启动opac } // <biblioDbGroup> nRet = app.LoadBiblioDbGroupParam( out strError); if (nRet == -1) { app.WriteErrorLog("ERR005 初始化BiblioDbGroup失败: " + strError); goto ERROR1; } } // // 初始化扩展SSO接口 nRet = app.InitialExternalSsoInterfaces( out strError); if (nRet == -1) { strError = "初始化扩展的SSO接口时出错: " + strError; app.WriteErrorLog(strError); // goto ERROR1; } // *** 进入内存的参数结束 if (this.ChannelPool != null) { this.ChannelPool.Close(); this.ChannelPool.BeforeLogin -= new BeforeLoginEventHandle(ChannelPool_BeforeLogin); this.ChannelPool = null; this.ChannelPool = new LibraryChannelPool(); this.ChannelPool.BeforeLogin -= new BeforeLoginEventHandle(ChannelPool_BeforeLogin); this.ChannelPool.BeforeLogin += new BeforeLoginEventHandle(ChannelPool_BeforeLogin); } // 启动批处理任务 if (bReload == false) { // string strBreakPoint = ""; // 启动DefaultThread try { DefaultThread defaultThread = new DefaultThread(this, null); this.BatchTasks.Add(defaultThread); defaultThread.StartWorkerThread(); this.defaultManagerThread = defaultThread; } catch (Exception ex) { app.WriteErrorLog("启动管理任务DefaultThread时出错:" + ex.Message); goto ERROR1; } // 启动CacheBuilder try { if (this.CacheBuilder == null) { this.CacheBuilder = new CacheBuilder(this, null); this.BatchTasks.Add(this.CacheBuilder); this.CacheBuilder.StartWorkerThread(); } } catch (Exception ex) { app.WriteErrorLog("启动批处理任务CacheBuilder时出错:" + ex.Message); goto ERROR1; } } // searchLog XmlElement nodeSearchLog = this.OpacCfgDom.DocumentElement.SelectSingleNode("searchLog") as XmlElement; if (nodeSearchLog != null) { string strEnable = nodeSearchLog.GetAttribute("enable"); // TODO: 如果以前已经有这个对象,需要先关闭它 // TODO: 如果因为MongoDB启动落后于dp2OPAC怎么办? 是否需要重试? this.SearchLog = new SearchLog(); nRet = this.SearchLog.Open(this, strEnable, out strError); if (nRet == -1) { app.WriteErrorLog("启动 SearchLog 时出错:" + strError); this.SearchLog = null; } } // chat room XmlNode nodeDef = this.OpacCfgDom.DocumentElement.SelectSingleNode("chatRoomDef"); nRet = this.ChatRooms.Initial(nodeDef, PathUtil.MergePath(this.DataDir, "chatrooms"), out strError); if (nRet == -1) { app.WriteErrorLog("启动批处理任务CacheBuilder时出错:" + strError); goto ERROR1; } // 公共查询最大命中数 { XmlNode nodeTemp = this.OpacCfgDom.DocumentElement.SelectSingleNode("//virtualDatabases"); if (nodeTemp != null) { try { string strMaxCount = DomUtil.GetAttr(nodeTemp, "searchMaxResultCount"); if (String.IsNullOrEmpty(strMaxCount) == false) this.SearchMaxResultCount = Convert.ToInt32(strMaxCount); } catch { } } } if (bReload == false) { PathUtil.CreateDirIfNeed(strColumnDir); // 确保目录创建 nRet = LoadCommentColumn( PathUtil.MergePath(strColumnDir, "comment"), out strError); if (nRet == -1) { app.WriteErrorLog("装载栏目存储时出错: " + strError); } } if (bReload == true) app.WriteErrorLog("opac service结束重新装载 " + this.m_strFileName); else { var version = System.Reflection.Assembly.GetAssembly(typeof(OpacApplication)).GetName().Version; app.WriteErrorLog("opac service 成功启动。版本: " + System.Reflection.Assembly.GetAssembly(typeof(OpacApplication)).GetName().ToString()); // 写入down机检测文件 app.WriteAppDownDetectFile("opac service启动。"); if (this.watcher == null) BeginWatcher(); #if NO if (this.virtual_watcher == null) BeginVirtualDirWatcher(); #endif } } finally { this.m_lock.ReleaseWriterLock(); } return 0; ERROR1: if (bReload == false) { if (this.watcher == null) BeginWatcher(); #if NO if (this.virtual_watcher == null) BeginVirtualDirWatcher(); #endif } return -1; }