// return: // -1 出错 // 0 成功 public int Initial(RmsChannelCollection Channels, string strServerUrl, string strLang, out string strError) { strError = ""; int nRet = 0; ResInfoItem[] root_dir_results = null; RmsChannel channel = Channels.GetChannel(strServerUrl); // 列出所有数据库 root_dir_results = null; long lRet = channel.DoDir("", strLang, "alllang", out root_dir_results, out strError); if (lRet == -1) { return(-1); } // 针对数据库的循环 for (int i = 0; i < root_dir_results.Length; i++) { ResInfoItem info = root_dir_results[i]; if (info.Type != ResTree.RESTYPE_DB) { continue; } ResInfoItem[] db_dir_result = null; lRet = channel.DoDir(info.Name, strLang, "alllang", out db_dir_result, out strError); if (lRet == -1) { return(-1); } KernelDbInfo db = new KernelDbInfo(); nRet = db.Initial(info.Names, db_dir_result, out strError); if (nRet == -1) { return(-1); } this.Add(db); } return(0); }
// 一次性获得许多消息 // parameters: // message_ids 消息ID的数组。如果字符串中包含'/',则是路径,否则就是id public int GetMessage( RmsChannelCollection Channels, string strUserID, string[] message_ids, MessageLevel messagelevel, out List <MessageData> messages, out string strError) { strError = ""; messages = new List <MessageData>(); RmsChannel channel = Channels.GetChannel(this.ServerUrl); if (channel == null) { strError = "get channel error"; return(-1); } for (int i = 0; i < message_ids.Length; i++) { string strID = message_ids[i]; string strPath = strID; if (strID.IndexOf("/") == -1) { strPath = this.MessageDbName + "/" + strID; } MessageData message = null; int nRet = 0; nRet = GetMessageByPath( channel, strPath, messagelevel, out message, out strError); if (nRet == -1) { return(-1); } if (strUserID != null && message.strUserName != strUserID) { // text-level: 用户提示 strError = string.Format(this.GetString("此条消息不属于用户s, 不允许察看"), // "此条消息不属于用户 '{0}', 不允许察看。" strUserID); // "此条消息不属于用户 '" +strUserID+ "', 不允许察看。"; return(-1); } messages.Add(message); } return(1); }
// 列出目录信息 // 列出2级。第二级在Hashtable中 int GetDirInfo(RmsChannelCollection Channels, string strServerUrl, out ResInfoItem[] root_dir_results, out Hashtable db_dir_results, out string strError) { root_dir_results = null; db_dir_results = null; RmsChannel channel = Channels.GetChannel(this.ServerUrl); // 列出所有数据库 root_dir_results = null; long lRet = channel.DoDir("", this.Lang, "alllang", out root_dir_results, out strError); if (lRet == -1) { return(-1); } db_dir_results = new Hashtable(); for (int i = 0; i < root_dir_results.Length; i++) { ResInfoItem info = root_dir_results[i]; if (info.Type != ResTree.RESTYPE_DB) { continue; } ResInfoItem[] db_dir_result = null; lRet = channel.DoDir(info.Name, this.Lang, "alllang", out db_dir_result, out strError); if (lRet == -1) { return(-1); } db_dir_results[info.Name] = db_dir_result; } return(0); }
// 获得未读消息数 public int GetUntouchedMessageCount( RmsChannelCollection Channels, string strUserID, string strBoxType, out string strError) { RmsChannel channel = Channels.GetChannel(this.ServerUrl); if (channel == null) { strError = "get channel error"; return(-1); } string strQueryXml = ""; // 构造检索式 int nRet = MakeSearchQuery( strUserID, strBoxType, "untouched", // 信箱内全部邮件 out strQueryXml, out strError); if (nRet == -1) { // text-level: 内部错误 strError = "构造检索式出错: " + strError; return(-1); } long lRet = channel.DoSearch(strQueryXml, "null", "", // strOuputStyle out strError); if (lRet == -1) { // text-level: 内部错误 strError = "检索失败: " + strError; return(-1); } return((int)lRet); }
// 根据消息记录id获得消息详细内容 // 本函数还将检查消息是否属于strUserID指明的用户 // parameters: // strUserID 如果==null,表示不检查消息属于何用户 public int GetMessage( RmsChannelCollection Channels, string strUserID, string strMessageID, MessageLevel messagelevel, out MessageData message, out string strError) { strError = ""; message = null; int nRet = 0; RmsChannel channel = Channels.GetChannel(this.ServerUrl); if (channel == null) { strError = "get channel error"; return(-1); } string strPath = this.MessageDbName + "/" + strMessageID; nRet = GetMessageByPath( channel, strPath, messagelevel, out message, out strError); if (nRet == -1) { return(-1); } if (strUserID != null && message.strUserName != strUserID) { // text-level: 用户提示 strError = string.Format(this.GetString("此条消息不属于用户s, 不允许察看"), // "此条消息不属于用户 '{0}', 不允许察看。" strUserID); // "此条消息不属于用户 '" +strUserID+ "', 不允许察看。"; return(-1); } return(1); }
/// <summary> /// 获得配置文件 /// </summary> /// <param name="strServerUrl">服务器URL。如果为null,则自动使用this.ServerUrl</param> /// <param name="strCfgFilePath">配置文件纯路径,不包含ServerUrl部分</param> /// <param name="strContent">返回配置文件内容</param> /// <param name="strError">返回错误信息</param> /// <returns>-1出错;0没有找到;1找到</returns> public int GetCfgFile( string strServerUrl, string strCfgFilePath, out string strContent, out string strError) { strError = ""; strContent = ""; if (strServerUrl == "" || strServerUrl == null) { strServerUrl = this.ServerUrl; } if (strServerUrl == "") { strError = "尚未指定服务器URL"; return(-1); } RmsChannel channelSave = channel; channel = Channels.GetChannel(strServerUrl); if (channel == null) { strError = "get channel error"; return(-1); } try { this.BeginLoop("正在下载文件" + strCfgFilePath); byte[] baTimeStamp = null; string strMetaData; string strOutputPath; long lRet = channel.GetRes( this.cfgCache, strCfgFilePath, out strContent, out strMetaData, out baTimeStamp, out strOutputPath, out strError); this.EndLoop(); if (lRet == -1) { if (channel.ErrorCode == ChannelErrorCode.NotFound) { return(0); // not found } return(-1); } return(1); // found } finally { this.channel = channelSave; } }
// 检索获得消息, 或者从结果集中获得消息 // parameters: // strStyle search / untouched / touched // 有search表示进行检索和获取,没有search就表示不检索而获取先前检索的结果集。 // untoched和touched应当和search联用。否则只能获取先前的结果数 public int GetMessage( RmsChannelCollection Channels, string strResultsetName, string strStyle, string strUserID, string strBoxType, MessageLevel messagelevel, int nStart, int nCount, out int nTotalCount, out List <MessageData> messages, out string strError) { nTotalCount = 0; messages = new List <MessageData>(); strError = ""; if (String.IsNullOrEmpty(this.MessageDbName) == true) { strError = "消息库尚未定义"; return(-1); } int nRet = 0; long lRet = 0; if (String.IsNullOrEmpty(strBoxType) == true) { strBoxType = MessageCenter.INBOX; } RmsChannel channel = Channels.GetChannel(this.ServerUrl); if (channel == null) { strError = "get channel error"; return(-1); } if (String.IsNullOrEmpty(strResultsetName) == true) { strResultsetName = "messages_of_" + strBoxType; } bool bSearch = true; if (StringUtil.IsInList("search", strStyle) == true) { bSearch = true; } else { bSearch = false; } string strQueryStyle = ""; if (StringUtil.IsInList("touched", strStyle) == true) { strQueryStyle = "touched"; } else if (StringUtil.IsInList("untouched", strStyle) == true) { strQueryStyle = "untouched"; } // 检索 if (bSearch == true) { string strQueryXml = ""; // 构造检索式 nRet = MakeSearchQuery( strUserID, strBoxType, strQueryStyle, out strQueryXml, out strError); if (nRet == -1) { // text-level: 内部错误 strError = "构造检索式出错: " + strError; return(-1); } lRet = channel.DoSearch(strQueryXml, strResultsetName, "", // strOuputStyle out strError); if (lRet == -1) { // text-level: 内部错误 strError = "检索失败: " + strError; return(-1); } // not found if (lRet == 0) { // text-level: 用户提示 strError = this.GetString("没有任何消息"); // "没有任何消息" return(0); } nTotalCount = (int)lRet; } if (nCount == 0) { return(nTotalCount); // 如果不需要获得结果集 } Debug.Assert(nStart >= 0, ""); // 获得结果集中指定范围的记录路径 ArrayList aLine = null; lRet = channel.DoGetSearchFullResult( strResultsetName, nStart, nCount, "zh", null, out aLine, out strError); if (lRet == -1) { // 虽然返回-1,但是aLine中仍然有内容了 if (aLine == null) { // text-level: 内部错误 strError = "获取浏览格式失败: " + strError; return(-1); } } // 返回数据 for (int i = 0; i < aLine.Count; i++) { string[] cols = null; cols = (string[])aLine[i]; string strPath = cols[0]; MessageData data = null; // TODO: level == none 只返回路径 nRet = GetMessageByPath( channel, strPath, messagelevel, out data, out strError); if (nRet == -1) { return(-1); } messages.Add(data); } return(aLine.Count); }
/// <summary> /// 检索实用库 /// </summary> /// <param name="Channels"></param> /// <param name="strServerUrl"></param> /// <param name="strDbName"></param> /// <param name="strFrom"></param> /// <param name="strKey"></param> /// <param name="strValueAttrName"></param> /// <param name="strValue"></param> /// <param name="strError"></param> /// <returns></returns> public static int SearchUtilDb( RmsChannelCollection Channels, string strServerUrl, string strDbName, string strFrom, string strKey, string strValueAttrName, out string strValue, out string strError) { strError = ""; strValue = ""; string strPath = ""; RmsChannel channel = Channels.GetChannel(strServerUrl); if (channel == null) { strError = "get channel error"; return(-1); } int nRet = SearchOnePath(channel, strDbName, strFrom, strKey, out strPath, out strError); if (nRet == -1) { return(-1); } if (nRet == 0) { return(0); } // 取记录 string strStyle = "content,data,timestamp"; string strMetaData; string strOutputPath; string strXml = ""; byte[] baTimeStamp = null; long lRet = channel.GetRes(strPath, strStyle, out strXml, out strMetaData, out baTimeStamp, out strOutputPath, out strError); if (lRet == -1) { strError = "检索 '" + strPath + "' 记录体时出错: " + strError; return(-1); } XmlDocument domRecord = new XmlDocument(); try { domRecord.LoadXml(strXml); } catch (Exception ex) { strError = "装载路径为'" + strPath + "'的xml记录时出错: " + ex.Message; return(-1); } strValue = DomUtil.GetAttr(domRecord.DocumentElement, strValueAttrName); return(1); }
// 保存消息到"草稿"箱 // parameters: // strOldRecordID 原来在草稿箱中的记录id。如果有此id,用覆盖方式写入,否则用追加方式写入 public int SaveMessage( RmsChannelCollection Channels, string strRecipient, string strSender, string strSubject, string strMime, string strBody, string strOldRecordID, byte [] baOldTimeStamp, out byte[] baOutputTimeStamp, out string strOutputID, out string strError) { strError = ""; baOutputTimeStamp = null; strOutputID = ""; XmlDocument dom = new XmlDocument(); dom.LoadXml("<root />"); DomUtil.SetElementText(dom.DocumentElement, "sender", strSender); DomUtil.SetElementText(dom.DocumentElement, "recipient", strRecipient); DomUtil.SetElementText(dom.DocumentElement, "subject", strSubject); DomUtil.SetElementText(dom.DocumentElement, "date", DateTimeUtil.Rfc1123DateTimeStringEx(DateTime.UtcNow.ToLocalTime())); DomUtil.SetElementText(dom.DocumentElement, "size", Convert.ToString(strBody.Length)); DomUtil.SetElementText(dom.DocumentElement, "touched", "0"); DomUtil.SetElementText(dom.DocumentElement, "username", strSender); DomUtil.SetElementText(dom.DocumentElement, "box", MessageCenter.TEMP); DomUtil.SetElementTextPure(dom.DocumentElement, "content", strBody); DomUtil.SetElementText(dom.DocumentElement, "mime", strMime); RmsChannel channel = Channels.GetChannel(this.ServerUrl); // byte[] timestamp = null; // byte[] output_timestamp = null; string strOutputPath = ""; string strPath = ""; if (String.IsNullOrEmpty(strOldRecordID) == true) { strPath = this.MessageDbName + "/?"; } else { strPath = this.MessageDbName + "/" + strOldRecordID; } // 写回册记录 long lRet = channel.DoSaveTextRes(strPath, dom.OuterXml, false, "content,ignorechecktimestamp", baOldTimeStamp, out baOutputTimeStamp, out strOutputPath, out strError); if (lRet == -1) { return(-1); } strOutputID = ResPath.GetRecordId(strOutputPath); return(0); }
// 发送消息 // parameters: // bVerifyRecipient 是否验证收件人地址 // return: // -1 出错 // 0 成功 public int SendMessage( RmsChannelCollection Channels, string strRecipient, string strSender, string strSubject, string strMime, string strBody, bool bVerifyRecipient, out string strError) { strError = ""; int nRet = 0; if (String.IsNullOrEmpty(strRecipient) == true) { // text-level: 用户提示 strError = this.GetString("收件人不能为空"); // "收件人不能为空" return(-1); } List <string> userids = null; List <string> origins = null; nRet = ParseAddress(strRecipient, out userids, out origins, out strError); if (nRet == -1) { strError = "收件人地址格式不正确: " + strError; return(-1); } for (int i = 0; i < userids.Count; i++) { string strUserID = userids[i]; string strOrigin = origins[i]; if (bVerifyRecipient == true) { // 校验收件人是否存在 // parameters: // return: // -1 error // 0 not exist // 1 exist nRet = DoVerifyRecipient( Channels, strUserID, out strError); if (nRet == -1 || nRet == 0) { return(-1); } } XmlDocument dom = new XmlDocument(); dom.LoadXml("<root />"); DomUtil.SetElementText(dom.DocumentElement, "sender", strSender); DomUtil.SetElementText(dom.DocumentElement, "recipient", strOrigin); // fullname DomUtil.SetElementText(dom.DocumentElement, "subject", strSubject); DomUtil.SetElementText(dom.DocumentElement, "date", DateTimeUtil.Rfc1123DateTimeStringEx(DateTime.UtcNow.ToLocalTime())); DomUtil.SetElementText(dom.DocumentElement, "size", Convert.ToString(strBody.Length)); DomUtil.SetElementText(dom.DocumentElement, "touched", "0"); DomUtil.SetElementText(dom.DocumentElement, "username", strUserID); DomUtil.SetElementText(dom.DocumentElement, "box", MessageCenter.INBOX); DomUtil.SetElementTextPure(dom.DocumentElement, "content", strBody); DomUtil.SetElementText(dom.DocumentElement, "mime", strMime); RmsChannel channel = Channels.GetChannel(this.ServerUrl); byte[] timestamp = null; byte[] output_timestamp = null; string strOutputPath = ""; // 写入收件箱 long lRet = channel.DoSaveTextRes(this.MessageDbName + "/?", dom.OuterXml, false, "content,ignorechecktimestamp", timestamp, out output_timestamp, out strOutputPath, out strError); if (lRet == -1) { // text-level: 内部错误 strError = "写入收件箱时出错: " + strError; return(-1); } DomUtil.SetElementText(dom.DocumentElement, "username", strSender); DomUtil.SetElementText(dom.DocumentElement, "box", MessageCenter.OUTBOX); // 写入已发送信箱 lRet = channel.DoSaveTextRes(this.MessageDbName + "/?", dom.OuterXml, false, "content,ignorechecktimestamp", null, out output_timestamp, out strOutputPath, out strError); if (lRet == -1) { // text-level: 内部错误 strError = "写入已发送信箱时出错: " + strError; return(-1); } } return(0); }
// 删除一条消息 public int DeleteMessage( bool bMoveToRecycleBin, RmsChannelCollection Channels, string strID, byte [] timestamp, out string strError) { RmsChannel channel = Channels.GetChannel(this.ServerUrl); string strPath = this.MessageDbName + "/" + strID; long lRet = 0; byte[] output_timestamp = null; // 要移动到废件箱 if (bMoveToRecycleBin == true) { string strXml = ""; string strMetaData = ""; string strOutputPath = ""; // 读出记录 lRet = channel.GetRes(strPath, out strXml, out strMetaData, out output_timestamp, out strOutputPath, out strError); if (lRet == -1) { // text-level: 内部错误 strError = "读出记录 '" + strPath + "' 时出错: " + strError; return(-1); } XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strXml); } catch (Exception ex) { // text-level: 内部错误 strError = "装载XML记录进入DOM时出错: " + ex.Message; return(-1); } // 修改box参数 DomUtil.SetElementText(dom.DocumentElement, "box", MessageCenter.RECYCLEBIN); timestamp = output_timestamp; // 写回 lRet = channel.DoSaveTextRes(strPath, dom.OuterXml, false, "content,ignorechecktimestamp", timestamp, out output_timestamp, out strOutputPath, out strError); if (lRet == -1) { // text-level: 内部错误 strError = "写回记录 '" + strPath + "' 时出错: " + strError; return(-1); } return(0); } bool bNullTimeStamp = false; if (timestamp == null) { bNullTimeStamp = true; } REDO: lRet = channel.DoDeleteRes(strPath, timestamp, out output_timestamp, out strError); if (lRet == -1) { if (bNullTimeStamp == true && channel.ErrorCode == ChannelErrorCode.TimestampMismatch) { timestamp = output_timestamp; goto REDO; } // text-level: 内部错误 strError = "删除记录 '" + strPath + "' 时发生错误: " + strError; return(-1); } return(0); }
private void menuItem_deleteObject_Click(object sender, System.EventArgs e) { try { string strError = ""; if (treeView_res.SelectedNode == null) { MessageBox.Show("请选择一个数据库、目录或文件节点"); return; } ResPath respath = new ResPath(treeView_res.SelectedNode); string strPath = ""; if (respath.Path != "") { strPath = respath.Path; // strPath = StringUtil.GetFirstPartPath(ref strPath); } else { // Debug.Assert(false, ""); MessageBox.Show("请选择一个数据库、目录或文件节点"); return; } string strText = ""; if (treeView_res.SelectedNode.ImageIndex == ResTree.RESTYPE_DB) { strText = "确实要删除位于 " + respath.Url + "\r\n的数据库 '" + strPath + "' ?\r\n\r\n***警告:数据库一旦删除,就无法恢复。"; } else { strText = "确实要删除位于 " + respath.Url + "\r\n的对象 '" + strPath + "' ?\r\n\r\n***警告:对象一旦删除,就无法恢复。"; } // DialogResult result = MessageBox.Show(this, strText, "dp2manager", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result != DialogResult.Yes) { return; } RmsChannel channel = Channels.GetChannel(respath.Url); if (channel == null) { strError = "Channels.GetChannel 异常"; goto ERROR1; } long lRet = 0; if (treeView_res.SelectedNode.ImageIndex == ResTree.RESTYPE_DB) { // 删除数据库 lRet = channel.DoDeleteDB(strPath, out strError); } else { byte[] timestamp = null; byte[] output_timestamp = null; REDODELETE: // 删除其他资源 lRet = channel.DoDeleteRes(strPath, timestamp, out output_timestamp, out strError); if (lRet == -1 && channel.ErrorCode == ChannelErrorCode.TimestampMismatch) { timestamp = output_timestamp; goto REDODELETE; } } if (lRet == -1) { goto ERROR1; } if (treeView_res.SelectedNode.ImageIndex == ResTree.RESTYPE_DB) { MessageBox.Show(this, "数据库 '" + strPath + "' 已被成功删除"); } else { MessageBox.Show(this, "对象 '" + strPath + "' 已被成功删除"); } this.treeView_res.Refresh(ResTree.RefreshStyle.All); return; ERROR1: MessageBox.Show(this, strError); return; } catch (Exception ex) { MessageBox.Show(this, "menuItem_deleteObject_Click() 抛出异常: " + ExceptionUtil.GetDebugText(ex)); } }
/// <summary> /// 检索实用库 /// </summary> /// <param name="Channels"></param> /// <param name="strServerUrl"></param> /// <param name="strDbName"></param> /// <param name="strFrom"></param> /// <param name="strKey"></param> /// <param name="strXml"></param> /// <param name="strError"></param> /// <returns></returns> public static int SearchUtilDb( RmsChannelCollection Channels, string strServerUrl, string strDbName, string strFrom, string strKey, out string strXml, out string strError) { strError = ""; strXml = ""; RmsChannel channel = Channels.GetChannel(strServerUrl); if (channel == null) { strError = "get channel error"; return(-1); } string[] paths = null; int nRet = SearchPath(channel, strDbName, strFrom, strKey, 1, out paths, out strError); if (nRet == -1) { return(-1); } if (nRet == 0) { return(0); } string strPath = paths[0]; // 取记录 string strStyle = "content,data,timestamp"; string strMetaData; string strOutputPath; byte[] baTimeStamp = null; long lRet = channel.GetRes(strPath, strStyle, out strXml, out strMetaData, out baTimeStamp, out strOutputPath, out strError); if (lRet == -1) { strError = "检索 '" + strPath + "' 记录体时出错: " + strError; return(-1); } return(1); }
/// <summary> /// 写入实用库 /// </summary> /// <param name="Channels"></param> /// <param name="strServerUrl"></param> /// <param name="strDbName"></param> /// <param name="strFrom"></param> /// <param name="strRootElementName"></param> /// <param name="strKeyAttrName"></param> /// <param name="strValueAttrName"></param> /// <param name="strKey"></param> /// <param name="strValue"></param> /// <param name="strError"></param> /// <returns></returns> public static int WriteUtilDb( RmsChannelCollection Channels, string strServerUrl, string strDbName, string strFrom, string strRootElementName, string strKeyAttrName, string strValueAttrName, string strKey, string strValue, out string strError) { strError = ""; string strPath = ""; RmsChannel channel = Channels.GetChannel(strServerUrl); if (channel == null) { strError = "get channel error"; return(-1); } int nRet = SearchOnePath(channel, strDbName, strFrom, strKey, out strPath, out strError); if (nRet == -1) { return(-1); } string strXml = ""; if (nRet == 0) { strPath = strDbName + "/?"; strXml = "<" + strRootElementName + " " + strKeyAttrName + "='" + strKey + "' " + strValueAttrName + "='" + strValue + "'/>"; //bNewRecord = true; } else { string strPartXml = "/xpath/<locate>@" + strValueAttrName + "</locate><create>@" + strValueAttrName + "</create>"; strPath += strPartXml; strXml = strValue; //bNewRecord = false; } byte[] baTimestamp = null; byte[] baOutputTimeStamp = null; string strOutputPath = ""; REDO: channel = Channels.GetChannel(strServerUrl); if (channel == null) { strError = "get channel error"; return(-1); } long lRet = channel.DoSaveTextRes(strPath, strXml, false, // bInlucdePreamble "ignorechecktimestamp", // style baTimestamp, out baOutputTimeStamp, out strOutputPath, out strError); if (lRet == -1) { if (channel.ErrorCode == ChannelErrorCode.TimestampMismatch) { baTimestamp = baOutputTimeStamp; goto REDO; } return(-1); } return(1); }
// 检测管理用户是否已经存在? // return: // -1 出错 // 0 不存在 // 1 存在, 且密码一致 // 2 存在, 但密码不一致 int DetectManageUser(out string strError) { strError = ""; if (this.textBox_kernelUrl.Text == "") { strError = "尚未指定dp2Kernel服务器URL"; return(-1); } if (this.textBox_manageUserName.Text == "") { strError = "尚未指定代理帐户的用户名"; return(-1); } if (this.textBox_managePassword.Text != this.textBox_confirmManagePassword.Text) { strError = "代理帐户 密码 和 再次输入密码 不一致。请重新输入。"; return(-1); } using (RmsChannelCollection channels = new RmsChannelCollection()) { RmsChannel channel = channels.GetChannel(this.textBox_kernelUrl.Text); if (channel == null) { strError = "channel == null"; return(-1); } // Debug.Assert(false, ""); int nRet = channel.Login(this.textBox_manageUserName.Text, this.textBox_managePassword.Text, out strError); if (nRet == -1) { strError = "以用户名 '" + this.textBox_manageUserName.Text + "' 和密码登录失败: " + strError; return(-1); } channel.DoLogout(out strError); if (nRet == 0) { channels.AskAccountInfo -= new AskAccountInfoEventHandle(channels_AskAccountInfo); channels.AskAccountInfo += new AskAccountInfoEventHandle(channels_AskAccountInfo); nRet = channel.UiLogin("为确认代理帐户是否存在, 请用root用户身份登录。", "", LoginStyle.None, out strError); if (nRet == -1 || nRet == 0) { strError = "以root用户身份登录失败: " + strError + "\r\n\r\n因此无法确定代理帐户是否存在"; return(-1); } string strRecPath = ""; string strXml = ""; byte[] baTimeStamp = null; // 获得用户记录 // return: // -1 error // 0 not found // >=1 检索命中的条数 nRet = GetUserRecord( channel, this.textBox_manageUserName.Text, out strRecPath, out strXml, out baTimeStamp, out strError); if (nRet == -1) { strError = "获取用户 '" + this.textBox_manageUserName.Text + "' 信息时发生错误: " + strError + "\r\n\r\n因此无法确定代理帐户是否存在。"; return(-1); } if (nRet == 1) { strError = "代理帐户 '" + this.textBox_manageUserName.Text + "' 已经存在, 但其密码和当前面板拟设置的密码不一致。"; return(2); } if (nRet >= 1) { strError = "以 '" + this.textBox_manageUserName.Text + "' 为用户名 的用户记录存在多条,这是一个严重错误,请利用root身份启用dp2manager尽快修正此错误。"; return(-1); } strError = "代理帐户 '" + this.textBox_manageUserName.Text + "' 不存在。"; return(0); } strError = "代理帐户 '" + this.textBox_manageUserName.Text + "' 代理帐户经检验存在。"; return(1); } }
// 重设置代理帐户密码 int ResetManageUserPassword(out string strError) { strError = ""; if (this.textBox_kernelUrl.Text == "") { strError = "尚未指定dp2Kernel服务器URL"; return(-1); } if (this.textBox_manageUserName.Text == "") { strError = "尚未指定代理帐户的用户名"; return(-1); } if (this.textBox_managePassword.Text != this.textBox_confirmManagePassword.Text) { strError = "代理帐户 密码 和 再次输入密码 不一致。请重新输入。"; return(-1); } using (RmsChannelCollection channels = new RmsChannelCollection()) { channels.AskAccountInfo -= new AskAccountInfoEventHandle(channels_AskAccountInfo); channels.AskAccountInfo += new AskAccountInfoEventHandle(channels_AskAccountInfo); RmsChannel channel = channels.GetChannel(this.textBox_kernelUrl.Text); if (channel == null) { strError = "channel == null"; return(-1); } int nRet = channel.UiLogin("请用root用户身份登录,以便重设代理帐户密码。", "", LoginStyle.None, out strError); if (nRet == -1 || nRet == 0) { strError = "以root用户身份登录失败: " + strError; return(-1); } // 获得用户库名 string strRecPath = ""; string strXml = ""; byte[] baTimeStamp = null; // 查重,看这个用户名是否已经存在 // 获得用户记录 // return: // -1 error // 0 not found // >=1 检索命中的条数 nRet = GetUserRecord( channel, this.textBox_manageUserName.Text, out strRecPath, out strXml, out baTimeStamp, out strError); if (nRet == -1) { strError = "获取用户 '" + this.textBox_manageUserName.Text + "' 信息时发生错误: " + strError; return(-1); } if (nRet == 0) { strError = "用户 '" + this.textBox_manageUserName.Text + "' 尚不存在,因此无法重设其密码。请直接创建。"; return(-1); } if (nRet > 1) { strError = "以 '" + this.textBox_manageUserName.Text + "' 为用户名 的用户记录存在多条,这是一个严重错误,请利用root身份启用dp2manager尽快修正此错误。"; return(-1); } // 修改密码 nRet = ResetUserRecordPassword(ref strXml, out strError); if (nRet == -1) { strError = "构造用户记录时发生错误: " + strError; return(-1); } string strOutputPath = ""; byte[] baOutputTimeStamp; if (strRecPath == "") { Debug.Assert(false, "不可能出现的情况。"); strRecPath = Defs.DefaultUserDb.Name + "/" + "?"; } long lRet = channel.DoSaveTextRes( strRecPath, strXml, false, // bInlucdePreamble "", // style baTimeStamp, // baTimeStamp, out baOutputTimeStamp, out strOutputPath, out strError); if (lRet == -1) { strError = "保存用户记录时发生错误: " + strError; return(-1); } channel.DoLogout(out strError); return(0); } }
// 删除应用服务器在dp2Kernel内核中创建的数据库 // parameters: // strXmlFileName library.xml 文件的全路径 // return: // -1 出错 // 0 用户放弃删除 // 1 已经删除 public static int DeleteKernelDatabases( IWin32Window owner, string strInstanceName, string strXmlFilename, out string strError) { strError = ""; int nRet = 0; DialogResult result = MessageBox.Show(owner == null ? ForegroundWindow.Instance : owner, "是否要删除应用服务器实例 '" + strInstanceName + "' 在数据库内核中创建过的全部数据库?\r\n\r\n(注:如果现在不删除,将来也可以用内核管理(dp2manager)工具进行删除)", "安装 dp2Library", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == DialogResult.No) { return(0); } XmlDocument dom = new XmlDocument(); try { dom.Load(strXmlFilename); } catch (Exception ex) { strError = "XML文件 '" + strXmlFilename + "' 装载到DOM时发生错误: " + ex.Message; return(-1); } XmlNode rmsserver_node = dom.DocumentElement.SelectSingleNode("rmsserver"); if (rmsserver_node == null) { strError = "<rmsserver>元素没有找到"; return(-1); } string strKernelUrl = DomUtil.GetAttr(rmsserver_node, "url"); if (String.IsNullOrEmpty(strKernelUrl) == true) { strError = "<rmsserver>元素的url属性为空"; return(-1); } using (RmsChannelCollection channels = new RmsChannelCollection()) { RmsChannel channel = channels.GetChannel(strKernelUrl); if (channel == null) { strError = "channel == null"; return(-1); } string strUserName = DomUtil.GetAttr(rmsserver_node, "username"); string strPassword = DomUtil.GetAttr(rmsserver_node, "password"); string EncryptKey = "dp2circulationpassword"; try { strPassword = Cryptography.Decrypt( strPassword, EncryptKey); } catch { strError = "<rmsserver>元素password属性中的密码设置不正确"; return(-1); } nRet = channel.Login(strUserName, strPassword, out strError); if (nRet == -1) { strError = "以用户名 '" + strUserName + "' 和密码登录内核时失败: " + strError; return(-1); } nRet = DeleteAllDatabase( channel, dom, out strError); if (nRet == -1) { return(-1); } return(1); } }