本文整理匯總了C#中BsonArray.Contains方法的典型用法代碼示例。如果您正苦於以下問題:C# BsonArray.Contains方法的具體用法?C# BsonArray.Contains怎麽用?C# BsonArray.Contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BsonArray
的用法示例。
在下文中一共展示了BsonArray.Contains方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetRolesByDBName
/// <summary>
/// 獲得數據庫角色
/// </summary>
/// <param name="DatabaseName"></param>
/// <returns></returns>
public BsonArray GetRolesByDBName(String DatabaseName)
{
BsonArray roles = new BsonArray();
//當前DB的System.user的角色
if (UserList.ContainsKey(DatabaseName)) {
roles = UserList[DatabaseName].roles;
}
///Admin的OtherDBRoles和當前數據庫角色合並
BsonArray adminRoles = GetOtherDBRoles(DatabaseName);
foreach (String item in adminRoles)
{
if (!roles.Contains(item)) {
roles.Add(item);
}
}
///ADMIN的ANY係角色的追加
if (UserList.ContainsKey(MongoDBHelper.DATABASE_NAME_ADMIN)) {
if (UserList[MongoDBHelper.DATABASE_NAME_ADMIN].roles.Contains(MongoDBHelper.UserRole_dbAdminAnyDatabase)){
roles.Add(MongoDBHelper.UserRole_dbAdminAnyDatabase);
}
if (UserList[MongoDBHelper.DATABASE_NAME_ADMIN].roles.Contains(MongoDBHelper.UserRole_readAnyDatabase))
{
roles.Add(MongoDBHelper.UserRole_readAnyDatabase);
}
if (UserList[MongoDBHelper.DATABASE_NAME_ADMIN].roles.Contains(MongoDBHelper.UserRole_readWriteAnyDatabase))
{
roles.Add(MongoDBHelper.UserRole_readWriteAnyDatabase);
}
if (UserList[MongoDBHelper.DATABASE_NAME_ADMIN].roles.Contains(MongoDBHelper.UserRole_userAdminAnyDatabase))
{
roles.Add(MongoDBHelper.UserRole_userAdminAnyDatabase);
}
}
return roles;
}
示例2: GetRolesByDBName
/// <summary>
/// 獲得數據庫角色
/// </summary>
/// <param name="DatabaseName"></param>
/// <returns></returns>
public BsonArray GetRolesByDBName(String DatabaseName)
{
BsonArray roles = new BsonArray();
if (UserList.ContainsKey(DatabaseName)) {
roles = UserList[DatabaseName].roles;
}
///Admin和當前數據庫角色合並
BsonArray adminRoles = GetOtherDBRoles(DatabaseName);
foreach (String item in adminRoles)
{
if (!roles.Contains(item)) {
roles.Add(item);
}
}
return roles;
}
示例3: GetCurrentQuests
private void GetCurrentQuests(string npcID, string playerID, BsonArray playerQuestsInProgress) {
//get the list of available quests the NPC can give
//may need to modify this in the future what if an NPC gets killed? If they respawn they will have a new ID.
//maybe some quests qet lost when an NPC dies and maybe some other NPC's can't die only get knocked unconcious. (gonna need a flag for that)
var availableQuests = MongoUtils.MongoData.RetrieveObjectsAsync<Quests.Quest>(MongoUtils.MongoData.GetCollection<Quests.Quest>("Characters", "NPCQuests"), q => q.Id == npcID).Result;
//I'm going to want to keep the in-progress and completed quests under the Player information
//need to find all the in progress quests this player has with this NPC that way they can have multiple quests from the same NPC
//and not have to visit the NPC once for every single quest he can give.
foreach (var quest in availableQuests) {
if (playerQuestsInProgress.Contains(quest.Id)) { //if the player has an in-progress quest that belongs to this NPC load it.
CurrentQuest.Add(quest.Id);
}
}
}
示例4: GetRolesByDbName
/// <summary>
/// 獲得數據庫角色
/// </summary>
/// <param name="databaseName"></param>
/// <returns></returns>
public BsonArray GetRolesByDbName(string databaseName)
{
var roles = new BsonArray();
//當前DB的System.user的角色
if (UserList.ContainsKey(databaseName))
{
roles = UserList[databaseName].Roles;
}
//Admin的OtherDBRoles和當前數據庫角色合並
var adminRoles = GetOtherDbRoles(databaseName);
foreach (string item in adminRoles)
{
if (!roles.Contains(item))
{
roles.Add(item);
}
}
//ADMIN的ANY係角色的追加
if (UserList.ContainsKey(ConstMgr.DatabaseNameAdmin))
{
if (UserList[ConstMgr.DatabaseNameAdmin].Roles.Contains(Role.UserRoleDbAdminAnyDatabase))
{
roles.Add(Role.UserRoleDbAdminAnyDatabase);
}
if (UserList[ConstMgr.DatabaseNameAdmin].Roles.Contains(Role.UserRoleReadAnyDatabase))
{
roles.Add(Role.UserRoleReadAnyDatabase);
}
if (
UserList[ConstMgr.DatabaseNameAdmin].Roles.Contains(
Role.UserRoleReadWriteAnyDatabase))
{
roles.Add(Role.UserRoleReadWriteAnyDatabase);
}
if (
UserList[ConstMgr.DatabaseNameAdmin].Roles.Contains(
Role.UserRoleUserAdminAnyDatabase))
{
roles.Add(Role.UserRoleUserAdminAnyDatabase);
}
}
return roles;
}
示例5: TestContainsNull
public void TestContainsNull()
{
var array = new BsonArray { 1, 2 };
Assert.IsFalse(array.Contains(null));
}
示例6: TestContains
public void TestContains()
{
var array = new BsonArray { 1, 2 };
Assert.IsTrue(array.Contains(1));
Assert.IsTrue(array.Contains(2));
Assert.IsFalse(array.Contains(3));
}
示例7: DealWithMailAddress
/// <summary>
/// 處理郵件地址
/// </summary>
/// <param name="AStr">郵件地址字符串</param>
/// <returns>返回處理結果</returns>
public BsonArray DealWithMailAddress(String AStr)
{
BsonDocument AddressDoc = null;//定義郵件地址文檔
BsonDocument NickNameDoc = null;//定義昵稱文檔
String Address = mh.MatcheMailPattern(AStr, "MailAddress");
if (!String.IsNullOrWhiteSpace(Address))//判斷是否包含郵件地址
{
String NickName = AStr.Replace("<" + Address + ">", "").Replace("<", "").Replace(">", "").Replace("\"", "").Trim();//提取昵稱
NickNameDoc = nnm.DealWithNickName(NickName);
AddressDoc = mas.ExitAddress(Address);//查找是否已存在該郵件地址信息
if (AddressDoc == null)//不存在該郵件地址信息
{
AddressDoc = new BsonDocument();//創建郵件地址文檔
AddressDoc.Add("Address", Address);//添加郵件地址到文檔
AddressDoc.Add("RepeatTimes", 1);//初始化出現次數
AddressDoc.Add("ForCase", CaseInfo.CaseName);
if (NickNameDoc != null)//該郵件地址字符串中存在昵稱
{
AddressDoc.Add("NickNames", new BsonArray().Add(NickNameDoc.GetValue("_id")));//關聯地址和昵稱
}
AddressDoc = mas.AddAddress(AddressDoc);//添加右鍵地址信息到數據庫
}
else//如果存在該郵件地址信息
{
if (!String.IsNullOrWhiteSpace(NickName))//判斷昵稱是否為空
{
BsonArray NickNames = new BsonArray();//創建郵件地址關聯的昵稱文檔
if (AddressDoc.Contains("NickNames"))//判斷郵件地址是否已經存在昵稱文檔
{
NickNames = AddressDoc.GetValue("NickNames").AsBsonArray;//提取已關聯的昵稱文檔
}
if (NickNameDoc != null)//該郵件地址字符串中存在昵稱
{
if (!NickNames.Contains(NickNameDoc.GetValue("_id")))//判斷郵件地址是否已經關聯該昵稱
{
NickNames.Add(NickNameDoc.GetValue("_id"));//添加新的昵稱到文檔
}
}
BsonDocument Update = new BsonDocument();
Update.Add("NickNames", NickNames); Update.Add("RepeatTimes", AddressDoc.GetValue("RepeatTimes").AsInt32 + 1);
mas.UpdateAddress(new BsonDocument("Address", Address), new BsonDocument("$set", Update));
AddressDoc.Set("NickNames", NickNames);
}
}
}
else//不包含郵件地址
{
String NickName = AStr.Replace("\"", "").Trim();//提取昵稱
NickNameDoc = nnm.DealWithNickName(NickName);
}
BsonArray AddressId = new BsonArray();//郵件地址的Id信息
if (NickNameDoc != null)
{
AddressId.Add(NickNameDoc.GetValue("_id"));//添加昵稱到該郵件地址的Id信息中
}
else
{
AddressId.Add(BsonNull.Value);
}
if (AddressDoc != null)
{
AddressId.Add(AddressDoc.GetValue("_id"));//添加郵件地址到該Id信息中
}
else
{
AddressId.Add(BsonNull.Value);
}
return AddressId;
}
示例8: JudgeRightByRole
/// <summary>
/// 根據角色判斷能否執行操作
/// </summary>
/// <param name="roles"></param>
/// <returns></returns>
public static Boolean JudgeRightByRole(BsonArray roles, MongoOperate opt)
{
Boolean CanDoIt = false;
switch (opt)
{
case MongoOperate.DelMongoDB:
case MongoOperate.RepairDB:
if (roles.Contains(MongoDBHelper.UserRole_clusterAdmin))
{
CanDoIt = true;
}
break;
case MongoOperate.EvalJS:
//http://docs.mongodb.org/manual/reference/user-privileges/
//Combined Access
//Requires readWriteAnyDatabase, userAdminAnyDatabase, dbAdminAnyDatabase and clusterAdmin (on the admin database.)
if (roles.Contains(MongoDBHelper.UserRole_readWriteAnyDatabase) &&
roles.Contains(MongoDBHelper.UserRole_userAdminAnyDatabase) &&
roles.Contains(MongoDBHelper.UserRole_dbAdminAnyDatabase) &&
roles.Contains(MongoDBHelper.UserRole_clusterAdmin))
{
CanDoIt = true;
}
break;
case MongoOperate.CreateMongoCollection:
case MongoOperate.InitGFS:
if (roles.Contains(MongoDBHelper.UserRole_readWrite) ||
roles.Contains(MongoDBHelper.UserRole_readWriteAnyDatabase) ||
roles.Contains(MongoDBHelper.UserRole_dbAdmin))
{
CanDoIt = true;
}
break;
case MongoOperate.AddUser:
if (roles.Contains(MongoDBHelper.UserRole_userAdmin) ||
roles.Contains(MongoDBHelper.UserRole_userAdminAnyDatabase))
{
CanDoIt = true;
}
break;
default:
break;
}
return CanDoIt;
}
示例9: TestContainsNull
public void TestContainsNull()
{
var array = new BsonArray { 1, 2 };
Assert.Throws<ArgumentNullException>(() => { array.Contains(null); });
}