// 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); }
// 列出目录信息 // 列出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); }
// 从db_dir_result数组找到针对特定数据库名的事项 public static ResInfoItem GetDbItem( ResInfoItem[] root_dir_results, string strDbName) { for (int i = 0; i < root_dir_results.Length; i++) { ResInfoItem info = root_dir_results[i]; if (info.Type != ResTree.RESTYPE_DB) { continue; } if (info.Name == strDbName) { return(info); } } return(null); }
// 获得一个普通数据库的定义(包括数据库名captions,froms name captions) // 格式为 /* * <database> * <caption lang="zh-cn">中文图书</caption> * <caption lang="en">Chinese book</caption> * <from style="title"> * <caption lang="zh-cn">题名</caption> * <caption lang="en">Title</caption> * </from> * ... * <from name="__id" /> * </database> * */ // return: // -1 error // 0 not found such database // 1 found and succeed public int GetDatabaseDef( string strDbName, out string strDef, out string strError) { strError = ""; strDef = ""; int nRet = 0; XmlDocument dom = new XmlDocument(); dom.LoadXml("<database />"); { ResInfoItem dbitem = KernelDbInfo.GetDbItem( this.root_dir_results, strDbName); if (dbitem == null) { strError = "根目录下没有找到名字为 '" + strDbName + "' 的数据库目录事项"; return(0); } // 在根下加入<caption>元素 for (int i = 0; i < dbitem.Names.Length; i++) { string strText = dbitem.Names[i]; nRet = strText.IndexOf(":"); if (nRet == -1) { strError = "names字符串 '" + strText + "' 格式不正确。"; return(-1); } string strLang = strText.Substring(0, nRet); string strName = strText.Substring(nRet + 1); XmlNode newnode = dom.CreateElement("caption"); dom.DocumentElement.AppendChild(newnode); DomUtil.SetAttr(newnode, "lang", strLang); DomUtil.SetNodeText(newnode, strName); } } // ResInfoItem[] fromitems = (ResInfoItem[])this.db_dir_results[strDbName]; if (fromitems == null) { strError = "db_dir_results中没有找到关于 '" + strDbName + "' 的下级目录事项"; return(0); } for (int i = 0; i < fromitems.Length; i++) { ResInfoItem item = fromitems[i]; if (item.Type != ResTree.RESTYPE_FROM) { continue; } // 插入<from>元素 XmlNode fromnode = dom.CreateElement("from"); dom.DocumentElement.AppendChild(fromnode); DomUtil.SetAttr(fromnode, "style", item.TypeString); // style if (item.Names == null) { continue; } // 插入caption for (int j = 0; j < item.Names.Length; j++) { string strText = item.Names[j]; nRet = strText.IndexOf(":"); if (nRet == -1) { strError = "names字符串 '" + strText + "' 格式不正确。"; return(-1); } string strLang = strText.Substring(0, nRet); string strName = strText.Substring(nRet + 1); XmlNode newnode = dom.CreateElement("caption"); fromnode.AppendChild(newnode); DomUtil.SetAttr(newnode, "lang", strLang); DomUtil.SetNodeText(newnode, strName); } } strDef = dom.OuterXml; return(1); }
// 初始化数据库和From的一些属性, 以便将来运行起来快速方便 // 在<database>元素下要插入若干<from>元素 // 这些信息属于软件初始化的范畴, 避免人工去配置 public int InitialAllProperty( ResInfoItem[] root_dir_results, Hashtable db_dir_results, out string strError) { strError = ""; int nRet = 0; if (nodeDatabase == null) { strError = "nodeDatabase尚未设置值"; return(-1); } if (this.IsVirtual != false) { strError = "该函数只适用于<database>元素的初始化"; return(-1); } string strDbName = DomUtil.GetAttr(nodeDatabase, "name"); RemoveChildren(nodeDatabase); ResInfoItem dbitem = KernelDbInfo.GetDbItem( root_dir_results, strDbName); if (dbitem == null) { strError = "根目录下没有找到名字为 '" + strDbName + "' 的数据库目录事项"; return(-1); } // 在下级加入<caption>元素 for (int i = 0; i < dbitem.Names.Length; i++) { string strText = dbitem.Names[i]; nRet = strText.IndexOf(":"); if (nRet == -1) { strError = "names字符串 '" + strText + "' 格式不正确。"; return(-1); } string strLang = strText.Substring(0, nRet); string strName = strText.Substring(nRet + 1); XmlNode newnode = nodeDatabase.OwnerDocument.CreateElement("caption"); newnode = nodeDatabase.AppendChild(newnode); DomUtil.SetAttr(newnode, "lang", strLang); DomUtil.SetNodeText(newnode, strName); } // ResInfoItem[] fromitems = (ResInfoItem[])db_dir_results[strDbName]; if (fromitems == null) { strError = "db_dir_results中没有找到关于 '" + strDbName + "' 的下级目录事项"; return(-1); } for (int i = 0; i < fromitems.Length; i++) { ResInfoItem item = fromitems[i]; if (item.Type != ResTree.RESTYPE_FROM) { continue; } // 插入<from>元素 XmlNode fromnode = nodeDatabase.OwnerDocument.CreateElement("from"); fromnode = nodeDatabase.AppendChild(fromnode); DomUtil.SetAttr(fromnode, "name", item.Name); // 当前工作语言下的名字 if (item.Names == null) { continue; } // 插入caption for (int j = 0; j < item.Names.Length; j++) { string strText = item.Names[j]; nRet = strText.IndexOf(":"); if (nRet == -1) { strError = "names字符串 '" + strText + "' 格式不正确。"; return(-1); } string strLang = strText.Substring(0, nRet); string strName = strText.Substring(nRet + 1); XmlNode newnode = fromnode.OwnerDocument.CreateElement("caption"); newnode = fromnode.AppendChild(newnode); DomUtil.SetAttr(newnode, "lang", strLang); DomUtil.SetNodeText(newnode, strName); } } return(0); }
// 根据虚拟的From名获得真实的From名。这个From是工作语言下的名字 // 如果匹配多个From名,将在字符串中以逗号分隔 2007/7/8改造 public string GetRealFromName( Hashtable db_dir_results, string strRealDbName, string strVirtualFromName) { List <string> styles = new List <string>(); if (String.IsNullOrEmpty(strVirtualFromName) == true || strVirtualFromName == "<全部>" || strVirtualFromName.ToLower() == "<all>") { XmlNodeList nodes = this.nodeDatabase.SelectNodes("from"); for (int i = 0; i < nodes.Count; i++) { string strStyle = DomUtil.GetAttr(nodes[i], "style"); styles.Add(strStyle); } } else { XmlNode node = null; XmlNodeList nodes = this.nodeDatabase.SelectNodes("from/caption"); for (int i = 0; i < nodes.Count; i++) { node = nodes[i]; if (strVirtualFromName == node.InnerText.Trim()) { goto FOUND; } } return(null); // not found FOUND: string strStyle = DomUtil.GetAttr(node.ParentNode, "style"); styles.Add(strStyle); } List <string> results = new List <string>(); for (int i = 0; i < styles.Count; i++) { string strStyle = styles[i]; // 从物理库的From事项中,找到style符合的 ResInfoItem[] froms = (ResInfoItem[])db_dir_results[strRealDbName]; if (froms == null) { // return null; // from目录事项居然没有找到 continue; } for (int j = 0; j < froms.Length; j++) { ResInfoItem item = froms[j]; string strStyles = item.TypeString; /* * if (StringUtil.IsInList(strStyle, strStyles) == true) * { * return item.Name; * } * */ if (StringUtil.IsInList(strStyle, strStyles) == true) { results.Add(item.Name); } } } if (results.Count == 0) { return(null); // style没有发现匹配的 } string[] list = new string[results.Count]; results.CopyTo(list); return(String.Join(",", list)); }
public int Initial( string [] names, ResInfoItem[] db_dir_result, out string strError) { strError = ""; List <Caption> captions = null; int nRet = BuildCaptions(names, out captions, out strError); if (nRet == -1) { return(-1); } this.Captions = captions; this.Froms = new List <From>(); for (int i = 0; i < db_dir_result.Length; i++) { ResInfoItem info = db_dir_result[i]; if (info.Type != ResTree.RESTYPE_FROM) { continue; } From from = new From(); if (info.Names != null) { captions = null; nRet = BuildCaptions(info.Names, out captions, out strError); if (nRet == -1) { return(-1); } from.Captions = captions; } else { if (String.IsNullOrEmpty(info.Name) == true) { strError = "出现了一个ResInfoItem事项,Names和Name均为空,这是不合法的"; return(-1); } // 加入一个语言中立的名字 from.Captions = new List <Caption>(); from.Captions.Add(new Caption(null, info.Name)); } from.Styles = info.TypeString; this.Froms.Add(from); } return(0); }
// 填充全部内容 int Fill(LibraryChannel channel_param, TreeNode node, out string strError) { strError = ""; TreeNodeCollection children = null; if (node == null) children = this.Nodes; else children = node.Nodes; if (string.IsNullOrEmpty(this.Lang)) this.Lang = "zh"; LibraryChannel channel = null; TimeSpan old_timeout = new TimeSpan(0); if (channel_param != null) channel = channel_param; else { channel = this.CallGetChannel(true); old_timeout = channel.Timeout; channel.Timeout = new TimeSpan(0, 5, 0); } bool restoreLoading = IsLoading(node); try { string start_path = GetNodePath(node); { DirItemLoader loader = new DirItemLoader(channel, null, start_path, "", this.Lang); children.Clear(); foreach (ResInfoItem item in loader) { TreeNode nodeNew = new TreeNode(item.Name, item.Type, item.Type); nodeNew.Tag = item; if (item.HasChildren) SetLoading(nodeNew); if (EnabledIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false) nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor); if (HideIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, HideIndices) == true) continue; children.Add(nodeNew); } } // 在根级追加 '!' 下的 dp2library 本地文件或目录 if (string.IsNullOrEmpty(start_path)) { ResInfoItem item = new ResInfoItem(); item.Name = "!"; item.Type = 4; item.HasChildren = true; TreeNode nodeNew = new TreeNode(item.Name, item.Type, item.Type); nodeNew.Tag = item; if (item.HasChildren) SetLoading(nodeNew); if (EnabledIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false) nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor); if (HideIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, HideIndices) == true) { } else children.Add(nodeNew); } restoreLoading = false; // 防止 finally 复原 return 0; } catch(ChannelException ex) { strError = ex.Message; return -1; #if NO if (ex.ErrorCode == ErrorCode.AccessDenied) { strError = ex.Message; return -1; } strError = "Fill() 过程出现异常: " + ExceptionUtil.GetExceptionText(ex); return -1; #endif } catch (Exception ex) { strError = "Fill() 过程出现异常: " + ExceptionUtil.GetExceptionText(ex); return -1; } finally { if (channel_param == null) { channel.Timeout = old_timeout; this.CallReturnChannel(channel, true); } if (restoreLoading) { SetLoading(node); if (node != null) node.Collapse(); } } }
// 列资源目录 public long DoDir(string strPath, string strLang, string strStyle, out ResInfoItem[] results, out string strError) { strError = ""; results = null; ResInfoItem[] items = null; int nStart = 0; int nPerCount = -1; int nCount = 0; ArrayList aItem = new ArrayList(); for (; ; ) { DoIdle(); // 出让控制权,避免CPU资源耗费过度 REDO: try { REDODIR: IAsyncResult soapresult = this.ws.BeginDir(strPath, nStart, nPerCount, strLang, strStyle, null, null); for (; ; ) { DoIdle(); // 出让控制权,避免CPU资源耗费过度 bool bRet = soapresult.AsyncWaitHandle.WaitOne(100, false); if (bRet == true) break; } if (this.m_ws == null) { strError = "用户中断"; this.ErrorCode = ChannelErrorCode.RequestCanceled; return -1; } Result result = this.ws.EndDir( out items,soapresult); if (result.Value == -1) { if (result.ErrorCode == ErrorCodeValue.NotLogin && this.Container != null) { // return: // -1 error // 0 login failed // 1 login succeed int nRet = this.UiLogin(strPath, out strError); if (nRet == -1 || nRet == 0) { return -1; } goto REDODIR; } ConvertErrorCode(result); strError = result.ErrorString; return -1; } if (items != null) { nStart += items.Length; nCount += items.Length; } // 做事 for (int i = 0; i < items.Length; i++) { aItem.Add(items[i]); } if (nCount >= result.Value) break; } catch (Exception ex) { /* strError = ConvertWebError(ex); return -1; * */ int nRet = ConvertWebError(ex, out strError); if (nRet == 0) return -1; goto REDO; } } // end of for results = new ResInfoItem[aItem.Count]; for (int i = 0; i < results.Length; i++) { results[i] = (ResInfoItem)aItem[i]; } this.ClearRedoCount(); return 0; }
// 填充全部内容 int Fill(LibraryChannel channel_param, TreeNode node, out string strError) { strError = ""; TreeNodeCollection children = null; if (node == null) { children = this.Nodes; } else { children = node.Nodes; } if (string.IsNullOrEmpty(this.Lang)) { this.Lang = "zh"; } LibraryChannel channel = null; TimeSpan old_timeout = new TimeSpan(0); if (channel_param != null) { channel = channel_param; } else { channel = this.CallGetChannel(true); old_timeout = channel.Timeout; channel.Timeout = new TimeSpan(0, 5, 0); } bool restoreLoading = IsLoading(node); try { string start_path = GetNodePath(node); { DirItemLoader loader = new DirItemLoader(channel, null, start_path, "", this.Lang); children.Clear(); foreach (ResInfoItem item in loader) { // 2017/9/23 if (string.IsNullOrEmpty(item.Name)) { continue; } TreeNode nodeNew = new TreeNode(item.Name, item.Type, item.Type); nodeNew.Tag = item; if (item.HasChildren) { SetLoading(nodeNew); } if (EnabledIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false) { nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor); } if (HideIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, HideIndices) == true) { continue; } children.Add(nodeNew); } } // 在根级追加 '!' 下的 dp2library 本地文件或目录 if (string.IsNullOrEmpty(start_path)) { ResInfoItem item = new ResInfoItem(); item.Name = "!"; item.Type = 4; item.HasChildren = true; TreeNode nodeNew = new TreeNode(item.Name, item.Type, item.Type); nodeNew.Tag = item; if (item.HasChildren) { SetLoading(nodeNew); } if (EnabledIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false) { nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor); } if (HideIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, HideIndices) == true) { } else { children.Add(nodeNew); } } restoreLoading = false; // 防止 finally 复原 return(0); } catch (ChannelException ex) { strError = ex.Message; return(-1); #if NO if (ex.ErrorCode == ErrorCode.AccessDenied) { strError = ex.Message; return(-1); } strError = "Fill() 过程出现异常: " + ExceptionUtil.GetExceptionText(ex); return(-1); #endif } catch (Exception ex) { strError = "Fill() 过程出现异常: " + ExceptionUtil.GetExceptionText(ex); return(-1); } finally { if (channel_param == null) { channel.Timeout = old_timeout; this.CallReturnChannel(channel, true); } if (restoreLoading) { SetLoading(node); if (node != null) { node.Collapse(); } } } }