// 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 DeleteMessage( bool bMoveToRecycleBin, RmsChannelCollection Channels, List <string> ids, List <byte[]> timestamps, out string strError) { strError = ""; string strError1 = ""; // Channel channel = Channels.GetChannel(this.ServerUrl); for (int i = 0; i < ids.Count; i++) { string strID = ids[i]; // string strPath = this.MessageDbName + "/" + strID; byte [] timestamp = null; // byte[] output_timestamp = null; if (timestamps != null) { timestamp = timestamps[i]; } int nRet = DeleteMessage( bMoveToRecycleBin, Channels, strID, timestamp, out strError); if (nRet == -1) { // text-level: 内部错误 strError1 += "删除记录 '" + strID + "' 时发生错误: " + strError + ";"; } } if (strError1 != "") { strError = strError1; return(-1); } 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); }
// TODO: 需要增加一个功能,把显示名转化为条码号 // 校验收件人是否存在 // parameters: // return: // -1 error // 0 not exist // 1 exist public int DoVerifyRecipient( RmsChannelCollection channels, string strRecipient, out string strError) { strError = ""; if (this.VerifyAccount == null) { // text-level: 内部错误 strError = "MessageCenter 尚未挂接 VerifyRecipient 事件,无法校验收件人的存在与否。"; return(-1); } VerifyAccountEventArgs e = new VerifyAccountEventArgs(); e.Name = strRecipient; e.Channels = channels; this.VerifyAccount(this, e); if (e.Error == true) { strError = e.ErrorInfo; return(-1); } if (e.Exist == false) { if (String.IsNullOrEmpty(e.ErrorInfo) == true) { // text-level: 用户提示 strError = string.Format(this.GetString("收件人s不存在"), // "收件人 '{0}' 不存在。" strRecipient); // "收件人 '" + strRecipient + "' 不存在。"; return(0); } strError = e.ErrorInfo; return(0); } return(1); }
// 检索获得消息, 或者从结果集中获得消息 // 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); }
// 检测管理用户是否已经存在? // 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); } }
// 删除一条消息 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); }
// 删除一个box中的全部消息 public int DeleteMessage( RmsChannelCollection Channels, string strUserID, bool bMoveToRecycleBin, string strBoxType, out string strError) { strError = ""; int nStart = 0; int nCount = -1; int nTotalCount = 0; for (; ;) { List <MessageData> messages = null; int nRet = GetMessage( Channels, "message_deleteall", nStart == 0 ? "search" : "", strUserID, strBoxType, MessageLevel.ID, nStart, nCount, out nTotalCount, out messages, out strError); if (nRet == -1) { return(-1); } if (nCount == -1) { nCount = nTotalCount - nStart; } for (int j = 0; j < messages.Count; j++) { MessageData data = messages[j]; nRet = DeleteMessage( bMoveToRecycleBin, Channels, data.strRecordID, data.TimeStamp, out strError); if (nRet == -1) { return(-1); } } nStart += messages.Count; nCount -= messages.Count; if (nStart >= nTotalCount) { break; } if (nCount <= 0) { break; } } return(nTotalCount); }
/// <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); }
// 构造函数 // 根据XML配置文件, 从服务器获取目录信息, 初始化数据结构 // parameters: // biblio_dbs_root <itemdbgroup>元素 public int Initial(XmlNode root, RmsChannelCollection Channels, string strServerUrl, XmlNode biblio_dbs_root, out string strWarning, out string strError) { strError = ""; strWarning = ""; this.ServerUrl = strServerUrl; this.root_dir_results = null; this.db_dir_results = null; // 列出目录信息 // 列出2级。第二级在Hashtable中 int nRet = GetDirInfo(Channels, strServerUrl, out root_dir_results, out db_dir_results, out strError); if (nRet == -1) { return(-1); } // 列出所有虚拟库XML节点 XmlNodeList virtualnodes = root.SelectNodes("virtualDatabase"); for (int i = 0; i < root.ChildNodes.Count; i++) { XmlNode node = root.ChildNodes[i]; if (node.NodeType != XmlNodeType.Element) { continue; } if (node.Name == "virtualDatabase") { // 构造虚拟数据库对象 VirtualDatabase vdb = new VirtualDatabase(); vdb.nodeDatabase = node; // 初始化From的一些属性, 以便将来运行起来快速方便 // 在<from>元素下要插入若干<database>元素, 这是该From可用的数据库的列表 // 这些信息属于软件初始化的范畴, 避免人工去配置 nRet = vdb.InitialFromProperty( db_dir_results, out strError); if (nRet == -1) { return(-1); } this.Add(vdb); continue; } if (node.Name == "database") // 普通库 { // 构造普通数据库对象 VirtualDatabase vdb = new VirtualDatabase(); vdb.nodeDatabase = node; // 要检查数据库名在<itemdbgroup>里面是否存在 string strDbName = DomUtil.GetAttr(node, "name"); if (biblio_dbs_root != null) { XmlNode nodeBiblio = biblio_dbs_root.SelectSingleNode("database[@biblioDbName='" + strDbName + "']"); if (nodeBiblio == null) { strError = "书目库 '" + strDbName + "' 在<itemdbgroup>内不存在定义,但却在<virtualDatabases>内存在。这表明<virtualDatabases>定义陈旧了,需要利用管理功能加以整理修改,或者直接在library.xml中修改"; return(-1); } } // return: // -2 有数据库没有找到 // -1 出错 // 0 对DOM没有修改 // 1 对DOM发生了修改 nRet = vdb.InitialAllProperty( root_dir_results, db_dir_results, out strError); if (nRet == -1) { return(-1); } if (nRet == -2) { strWarning = strError; } this.Add(vdb); continue; } } 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); }
// 保存消息到"草稿"箱 // 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); }
// 重设置代理帐户密码 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); } }