public static GetTagPath ( string objectTag ) : string | ||
objectTag | string | |
Résultat | string |
/// <summary> /// 获得ServerKey /// </summary> /// <returns></returns> public static string GetCurrentServerKey() { var strSvrPath = TagInfo.GetTagPath(SelectObjectTag); var strPath = strSvrPath.Split("/".ToCharArray()); return(strPath[0]); }
/// <summary> /// 根据路径字符获得客户端 /// </summary> /// <param name="strObjTag">[Tag:Connection/Host@Port/DBName/Collection]</param> /// <returns></returns> /// <param name="mongoConnSvrLst"></param> public static MongoClient GetMongoClientBySvrPath(string strObjTag, Dictionary <string, MongoClient> mongoConnSvrLst) { var strSvrPath = TagInfo.GetTagPath(strObjTag); var strPath = strSvrPath.Split("/".ToCharArray()); if (strPath.Length == 1) { //[Tag:Connection if (mongoConnSvrLst.ContainsKey(strPath[0])) { return(mongoConnSvrLst[strPath[0]]); } } if (strPath.Length > (int)EnumMgr.PathLevel.Instance) { if (strPath[0] == strPath[1]) { //[Tag:Connection/Connection/DBName/Collection] return(mongoConnSvrLst[strPath[0]]); } //[Tag:Connection/Host@Port/DBName/Collection] var strInstKey = strPath[(int)EnumMgr.PathLevel.Connection] + "/" + strPath[(int)EnumMgr.PathLevel.Instance]; if (MongoInstanceLst.ContainsKey(strInstKey)) { return(mongoConnSvrLst[strPath[0]]); } } return(null); }
/// <summary> /// 通过路径获得数据集 /// </summary> /// <param name="strObjTag">[Tag:Connection/Host@Port/DBName/Collection]</param> /// <returns></returns> public static MongoCollection GetMongoCollectionBySvrPath(string strObjTag, MongoDatabase mongoDb) { MongoCollection rtnMongoCollection = null; if (mongoDb != null) { var strSvrPath = TagInfo.GetTagPath(strObjTag); var strPathArray = strSvrPath.Split("/".ToCharArray()); if (strPathArray.Length > (int)EnumMgr.PathLevel.Collection) { rtnMongoCollection = mongoDb.GetCollection(strPathArray[(int)EnumMgr.PathLevel.Collection]); } } return(rtnMongoCollection); }
/// <summary> /// 根据路径字符获得数据库 /// </summary> /// <param name="strObjTag"></param> /// <param name="mongoSvr"></param> /// <returns></returns> public static IMongoDatabase GetMongoDBBySvrPath(string strObjTag, MongoClient mongoSvr) { IMongoDatabase rtnMongoDb = null; if (mongoSvr != null) { var strSvrPath = TagInfo.GetTagPath(strObjTag); var strPathArray = strSvrPath.Split("/".ToCharArray()); if (strPathArray.Length > (int)EnumMgr.PathLevel.Database) { rtnMongoDb = mongoSvr.GetDatabase(strPathArray[(int)EnumMgr.PathLevel.Database]); } } return(rtnMongoDb); }
/// <summary> /// 通过路径获得数据集 /// </summary> /// <param name="strObjTag"></param> /// <param name="mongoDb"></param> /// <returns></returns> public static IMongoCollection <BsonDocument> GetMongoCollectionBySvrPath(string strObjTag, IMongoDatabase mongoDb) { IMongoCollection <BsonDocument> rtnMongoCollection = null; if (mongoDb != null) { var strSvrPath = TagInfo.GetTagPath(strObjTag); var strPathArray = strSvrPath.Split("/".ToCharArray()); if (strPathArray.Length > (int)EnumMgr.PathLevel.CollectionAndView) { rtnMongoCollection = mongoDb.GetCollection <BsonDocument>(strPathArray[(int)EnumMgr.PathLevel.CollectionAndView]); } } return(rtnMongoCollection); }