// 列出服务器下当前帐户有显示权限的数据库 // 线:不安全的 // parameters: // strStyle 是否要列出所有语言的名字? "alllang"表示要列出所有语言的名字 public int GetDirableChildren(User user, string strLang, string strStyle, out ArrayList aItem, out string strError) { aItem = new ArrayList(); strError = ""; if (this.NodeDbs == null) { strError = "服装器配置文件不合法,未定义<dbs>元素"; return -1; } foreach (XmlNode child in this.NodeDbs.ChildNodes) { string strChildName = DomUtil.GetAttr(child, "name"); if (String.Compare(child.Name, "database", true) != 0 && strChildName == "") continue; if (String.Compare(child.Name, "database", true) != 0 && String.Compare(child.Name, "dir", true) != 0 && String.Compare(child.Name, "file", true) != 0) { continue; } string strExistRights; bool bHasRight = false; ResInfoItem resInfoItem = new ResInfoItem(); if (String.Compare(child.Name, "database", true) == 0) { string strID = DomUtil.GetAttr(child, "id"); Database db = this.GetDatabaseByID("@" + strID); if (db == null) { strError = "未找到id为'" + strID + "'的数据库"; return -1; } bHasRight = user.HasRights(db.GetCaption("zh"), ResType.Database, "list", out strExistRights); if (bHasRight == false) continue; if (StringUtil.IsInList("account", db.GetDbType(), true) == true) resInfoItem.Style = 1; else resInfoItem.Style = 0; resInfoItem.TypeString = db.GetDbType(); resInfoItem.Name = db.GetCaptionSafety(strLang); resInfoItem.Type = 0; // 数据库 resInfoItem.HasChildren = true; // 如果要获得全部语言的名字 if (StringUtil.IsInList("alllang", strStyle) == true) { List<string> results = db.GetAllLangCaptionSafety(); string [] names = new string[results.Count]; results.CopyTo(names); resInfoItem.Names = names; } } else if (String.Compare(child.Name, "dir", true) == 0) { bHasRight = user.HasRights(strChildName, ResType.Directory, "list", out strExistRights); if (bHasRight == false) continue; resInfoItem.HasChildren = true; resInfoItem.Type = 4; // 目录 resInfoItem.Name = strChildName; resInfoItem.TypeString = DomUtil.GetAttr(child, "type"); // xietao 2006/6/5 add } else { bHasRight = user.HasRights(strChildName, ResType.File, "list", out strExistRights); if (bHasRight == false) continue; resInfoItem.HasChildren = false; resInfoItem.Name = strChildName; resInfoItem.Type = 5; // 文件? resInfoItem.TypeString = DomUtil.GetAttr(child, "type"); // xietao 2006/6/5 add } aItem.Add(resInfoItem); } return 0; }
// 根据服务器上的指定路径列出其下级的事项 // parameters: // strPath 路径,不带服务器部分, // 格式为: "数据库名/下级名/下级名", // 当为null或者为""时,表示列出该服务器下所有的数据库 // lStart 起始位置,从0开始 ,不能小于0 // lLength 长度 -1表示从lStart到最后 // strLang 语言版本 用标准字母表示法,如zh-cn // strStyle 是否要列出所有语言的名字? "alllang"表示要列出全部语言 // items out参数,返回下级事项数组 // return: // -1 出错 // -6 权限不够 // 0 正常 // 说明 只有当前帐户对事项有"list"权限时,才能列出来。 // 如果列本服务器的数据库时,对所有的数据库都没有list权限,都按错误处理,与没有数据库事项区分开。 public int Dir(string strResPath, long lStart, long lLength, long lMaxLength, string strLang, string strStyle, User user, out ResInfoItem[] items, out int nTotalLength, out string strError) { items = new ResInfoItem[0]; nTotalLength = 0; ArrayList aItem = new ArrayList(); strError = ""; int nRet = 0; //******************加库集合加读锁****** this.m_lock.AcquireReaderLock(m_nTimeOut); #if DEBUG_LOCK this.WriteDebugInfo("Dir(),对库集合加读锁。"); #endif try { if (strResPath == "" || strResPath == null) { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 1.取服务器下的数据库 nRet = this.GetDirableChildren(user, strLang, strStyle, out aItem, out strError); if (this.Count > 0 && aItem.Count == 0) { strError = "您的帐户名为'" + user.Name + "',对所有的数据库都没有'显示(list)'权限。"; return -6; } } else { string strPath = strResPath; string strDbName = StringUtil.GetFirstPartPath(ref strPath); // 可以是数据库也可以是配置事项 if (strPath == "") { Database db = this.GetDatabase(strDbName); if (db != null) { // return: // -1 出错 // 0 成功 nRet = db.GetDirableChildren(user, strLang, strStyle, out aItem, out strError); if (nRet == -1) return -1; goto END1; } } // return: // -1 出错 // 0 成功 nRet = this.DirCfgItem(user, strResPath, out aItem, out strError); if (nRet == -1) return -1; } } finally { m_lock.ReleaseReaderLock(); //*************对库集合解读锁*********** #if DEBUG_LOCK this.WriteDebugInfo("Dir(),对库集合解读锁。"); #endif } END1: // 列出实际需要的项 nTotalLength = aItem.Count; int nOutputLength; // return: // -1 出错 // 0 成功 nRet = DatabaseUtil.GetRealLength((int)lStart, (int)lLength, nTotalLength, (int)lMaxLength, out nOutputLength, out strError); if (nRet == -1) return -1; items = new ResInfoItem[(int)nOutputLength]; for (int i = 0; i < items.Length; i++) { items[i] = (ResInfoItem)(aItem[i + (int)lStart]); } return 0; }
// 得到某一指定路径strPath的可以显示的下级 // parameters: // oUser 当前帐户 // db 当前数据库 // strPath 配置事项的路径 // strLang 语言版本 // aItem out参数,返回可以显示的下级 // strError out参数,出错信息 // return: // -1 出错 // 0 成功 private int DirCfgItem(User user, string strCfgItemPath, out ArrayList aItem, out string strError) { strError = ""; aItem = new ArrayList(); if (this.NodeDbs == null) { strError = "服务器配置文件未定义<dbs>元素"; return -1; } List<XmlNode> list = DatabaseUtil.GetNodes(this.NodeDbs, strCfgItemPath); if (list.Count == 0) { strError = "未找到路径为'" + strCfgItemPath + "'对应的事项。"; return -1; } if (list.Count > 1) { strError = "服务器端总配置文件不合法,检查到路径为'" + strCfgItemPath + "'对应的节点有'" + Convert.ToString(list.Count) + "'个,有且只能有一个。"; return -1; } XmlNode node = list[0]; for (int i = 0; i < node.ChildNodes.Count; i++) { XmlNode child = node.ChildNodes[i]; string strChildName = DomUtil.GetAttr(child, "name"); if (strChildName == "") continue; string strTempPath = strCfgItemPath + "/" + strChildName; string strExistRights; bool bHasRight = false; ResInfoItem resInfoItem = new ResInfoItem(); resInfoItem.Name = strChildName; if (child.Name == "dir") { bHasRight = user.HasRights(strTempPath, ResType.Directory, "list", out strExistRights); if (bHasRight == false) continue; resInfoItem.HasChildren = true; resInfoItem.Type = 4; resInfoItem.TypeString = DomUtil.GetAttr(child, "type"); // xietao 2006/6/5 add } else { bHasRight = user.HasRights(strTempPath, ResType.File, "list", out strExistRights); if (bHasRight == false) continue; resInfoItem.HasChildren = false; resInfoItem.Type = 5; resInfoItem.TypeString = DomUtil.GetAttr(child, "type"); // xietao 2006/6/5 add } aItem.Add(resInfoItem); } return 0; }
// 得到数据库可以显示的下级 // parameters: // oUser 帐户对象 // db 数据库对象 // strLang 语言版本 // aItem out参数,返回数据库可以显示的下级 // strError out参数,返回出错信息 // return: // -1 出错 // 0 成功 public int GetDirableChildren(User user, string strLang, string strStyle, out ArrayList aItem, out string strError) { aItem = new ArrayList(); strError = ""; //**********对数据库加读锁************** this.m_db_lock.AcquireReaderLock(m_nTimeOut); #if DEBUG_LOCK this.container.WriteDebugInfo("Dir(),对'" + this.GetCaption("zh-CN") + "'数据库加读锁。"); #endif try { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 1.配置事项 foreach (XmlNode child in this.m_selfNode.ChildNodes) { string strElementName = child.Name; if (String.Compare(strElementName, "dir", true) != 0 && String.Compare(strElementName, "file", true) != 0) { continue; } string strChildName = DomUtil.GetAttr(child, "name"); if (strChildName == "") continue; string strCfgPath = this.GetCaption("zh-CN") + "/" + strChildName; string strExistRights; bool bHasRight = false; ResInfoItem resInfoItem = new ResInfoItem(); resInfoItem.Name = strChildName; if (child.Name == "dir") { bHasRight = user.HasRights(strCfgPath, ResType.Directory, "list", out strExistRights); if (bHasRight == false) continue; resInfoItem.HasChildren = true; resInfoItem.Type = 4; // 目录 resInfoItem.TypeString = DomUtil.GetAttr(child, "type"); // xietao 2006/6/5 } else { bHasRight = user.HasRights(strCfgPath, ResType.File, "list", out strExistRights); if (bHasRight == false) continue; resInfoItem.HasChildren = false; resInfoItem.Type = 5; // 文件 resInfoItem.TypeString = DomUtil.GetAttr(child, "type"); // xietao 2006/6/5 add } aItem.Add(resInfoItem); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 2.检索途径 KeysCfg keysCfg = null; int nRet = this.GetKeysCfg(out keysCfg, out strError); if (nRet == -1) return -1; if (keysCfg != null) { List<TableInfo> aTableInfo = null; nRet = keysCfg.GetTableInfosRemoveDup( out aTableInfo, out strError); if (nRet == -1) return -1; // 对于检索途径,全部都有权限 for (int i = 0; i < aTableInfo.Count; i++) { TableInfo tableInfo = aTableInfo[i]; Debug.Assert(tableInfo.Dup == false, "不可能再有重复的了。"); ResInfoItem resInfoItem = new ResInfoItem(); resInfoItem.Type = 1; resInfoItem.Name = tableInfo.GetCaption(strLang); resInfoItem.HasChildren = false; resInfoItem.TypeString = tableInfo.TypeString; // xietao 2006/6/5 add // 2012/5/16 if (string.IsNullOrEmpty(tableInfo.ExtTypeString) == false) { if (string.IsNullOrEmpty(resInfoItem.TypeString) == false) resInfoItem.TypeString += ","; resInfoItem.TypeString += tableInfo.ExtTypeString; } // 如果需要, 列出所有语言下的名字 if (StringUtil.IsInList("alllang", strStyle) == true) { List<string> results = tableInfo.GetAllLangCaption(); string[] names = new string[results.Count]; results.CopyTo(names); resInfoItem.Names = names; } aItem.Add(resInfoItem); } } // 加__id ResInfoItem resInfoItemID = new ResInfoItem(); resInfoItemID.Type = 1; resInfoItemID.Name = "__id"; resInfoItemID.HasChildren = false; resInfoItemID.TypeString = "recid"; aItem.Add(resInfoItemID); return 0; } finally { //***************对数据库解读锁************ this.m_db_lock.ReleaseReaderLock(); #if DEBUG_LOCK this.container.WriteDebugInfo("Dir(),对'" + this.GetCaption("zh-CN") + "'数据库解读锁。"); #endif } }