本文整理汇总了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); });
}