public void TestContains()
        {
            var array = new BsonArray {
                1, 2
            };

            Assert.IsTrue(array.Contains(1));
            Assert.IsTrue(array.Contains(2));
            Assert.IsFalse(array.Contains(3));
        }
Пример #2
0
        public static BsonArray simple2TQNames(List <string> simpleRules, string taskOrQuality, int taskOrQualityLength)//task = 4, quality = 7
        {
            try
            {
                List <string> nodes = new List <string>();
                BsonArray     res   = new BsonArray();
                foreach (string rule in simpleRules)
                {
                    int indexOfSecondNode = sizeOfPart1(rule);
                    if (indexOfSecondNode >= 0)
                    {
                        ///get first node
                        int    lengthOfFirstNode = sizeOfFirstNode(rule);
                        string firstNode         = rule.Substring(0, lengthOfFirstNode);

                        ////get second node
                        indexOfSecondNode++;
                        string secondNode = rule.Substring(indexOfSecondNode);

                        if (!nodes.Contains(firstNode) && !res.Contains(firstNode) && firstNode.Length >= taskOrQualityLength && firstNode.ToLower().Substring(0, taskOrQualityLength).Equals(taskOrQuality))
                        {
                            nodes.Add(firstNode);
                            firstNode = firstNode.Substring(taskOrQualityLength + 1);
                            res.Add(firstNode);
                        }
                        if (!nodes.Contains(secondNode) && !res.Contains(secondNode) && secondNode.Length >= taskOrQualityLength && secondNode.ToLower().Substring(0, taskOrQualityLength).Equals(taskOrQuality))
                        {
                            nodes.Add(firstNode);
                            secondNode = secondNode.Substring(taskOrQualityLength + 1);
                            res.Add(secondNode);
                        }
                    }
                    else
                    {
                        if (!nodes.Contains(rule) && !res.Contains(rule) && rule.Length >= taskOrQualityLength && rule.ToLower().Substring(0, taskOrQualityLength).Equals(taskOrQuality))
                        {
                            nodes.Add(rule);
                            string node = rule.Substring(taskOrQualityLength + 1);
                            res.Add(node);
                        }
                    }
                }
                return(res);
            }
            catch (Exception e)
            {
                throw new Exception();
            }
        }
 /// <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;
 }
        public void TestContainsNull()
        {
            var array = new BsonArray {
                1, 2
            };

            Assert.IsFalse(array.Contains(null));
        }
Пример #5
0
        public TagsSystem(BsonArray ListTag, Action UpdateArray)
        {
            List = ListTag;
            DashboardGame.Dashboard.Root.Children.Add(this);

            InitializeComponent();

            foreach (var item in ListTag)
            {
                PlaceTags.Children.Add(new ModelTag(item.AsBsonDocument, this));
            }


            Root.MouseDown += (s, e) =>
            {
                if (e.Source.GetType() == typeof(Grid))
                {
                    Close();
                    UpdateArray();
                }
            };

            //action add tag to array
            BTN_AddTag.MouseDown += (s, e) =>
            {
                var NewTag = new BsonDocument
                {
                    { "Name", TextNewTag.Text },
                    { "Color", SelectedColor.Background.ToString() }
                };

                if (!ListTag.Contains(NewTag) && TextNewTag.Text.Length >= 1)
                {
                    PlaceTags.Children.Add(new ModelTag(NewTag, this));
                    ListTag.Add(NewTag);

                    UpdateArray();
                    TextNewTag.Text = "";
                }
                else
                {
                    DashboardGame.Notifaction("Tag Duplicated", Notifaction.StatusMessage.Warrning);
                }
            };
            //ation btn seleceted color
            SelectedColor.MouseDown += (s, e) =>
            {
                ColorPallet.Visibility = Visibility.Visible;
            };
        }
Пример #6
0
 /// <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;
 }
Пример #7
0
        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);
                }
            }

        }
        /// <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和当前数据库角色合并
            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(Role.UserRole_dbAdminAnyDatabase))
                {
                    roles.Add(Role.UserRole_dbAdminAnyDatabase);
                }
                if (UserList[MongoDbHelper.DATABASE_NAME_ADMIN].roles.Contains(Role.UserRole_readAnyDatabase))
                {
                    roles.Add(Role.UserRole_readAnyDatabase);
                }
                if (
                    UserList[MongoDbHelper.DATABASE_NAME_ADMIN].roles.Contains(
                        Role.UserRole_readWriteAnyDatabase))
                {
                    roles.Add(Role.UserRole_readWriteAnyDatabase);
                }
                if (
                    UserList[MongoDbHelper.DATABASE_NAME_ADMIN].roles.Contains(
                        Role.UserRole_userAdminAnyDatabase))
                {
                    roles.Add(Role.UserRole_userAdminAnyDatabase);
                }
            }
            return(roles);
        }
Пример #9
0
        /// <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);
        }
Пример #10
0
        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)
            BsonArray availableQuests = MongoUtils.MongoData.GetCollection("Characters", "NPCQuests").FindOneAs <BsonArray>(MongoDB.Driver.Builders.Query.EQ("_id", npcID));

            //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 (BsonDocument 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"].AsString);
                }
            }
        }
Пример #11
0
 /// <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;
 }
Пример #12
0
        /// <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);
        }
 public void TestContainsNull()
 {
     var array = new BsonArray { 1, 2 };
     Assert.IsFalse(array.Contains(null));
 }
        public bool Execute(IMongoDatabase database, MongoStorageOptions storageOptions, IMongoMigrationBag migrationBag)
        {
            var jobGraph = database.GetCollection <BsonDocument>(storageOptions.Prefix + ".jobGraph");

            var counters    = jobGraph.Find(new BsonDocument("_t", "CounterDto")).ToList();
            var idsToRemove = new BsonArray();

            foreach (var countersByKey in counters.GroupBy(c => c["Key"].AsString))
            {
                var key             = countersByKey.Key;
                var groupedCounters = countersByKey.ToList();

                // if only one, nothing to do, continue...
                if (groupedCounters.Count == 1)
                {
                    continue;
                }

                // if all have the same value take the newest
                var allSameValue = groupedCounters.Select(c => Convert.ToInt32(c["Value"])).Distinct().Count() == 1;
                if (allSameValue)
                {
                    var newestObjectId = groupedCounters.Select(c => c["_id"].AsObjectId).Max();
                    idsToRemove.AddRange(groupedCounters.Where(c => c["_id"].AsObjectId != newestObjectId).Select(c => c["_id"]));
                    continue;
                }

                // if more with different values delete all with value = '1' and sum the rest, most likely there have been
                // created a new counterDto, which will have been counted instead of the aggregated one.
                idsToRemove.AddRange(groupedCounters.Where(c => Convert.ToInt32(c["Value"]) == 1).Select(c => c["_id"]));

                // verify there is only one counter left. if more, sum the results and put in a new document,
                // delete the existing
                groupedCounters.RemoveAll(c => idsToRemove.Contains(c["_id"].AsObjectId));

                if (groupedCounters.Count <= 1)
                {
                    continue;
                }

                var sum = groupedCounters.Sum(c =>
                {
                    var value = c["Value"];
                    return(value.IsInt32 ? value.AsInt32 : value.AsInt64);
                });

                var expireAt = groupedCounters.Any(c => c.Contains("ExpireAt") && c["ExpireAt"] != BsonNull.Value)
                    ? (BsonValue)groupedCounters.Select(c => c["ExpireAt"].ToUniversalTime()).Max()
                    : BsonNull.Value;

                var counterToInsert = new BsonDocument
                {
                    ["Key"]      = key,
                    ["Value"]    = sum,
                    ["_id"]      = ObjectId.GenerateNewId(),
                    ["ExpireAt"] = expireAt,
                    ["_t"]       = new BsonArray(new[] { "BaseJobDto", "ExpiringJobDto", "KeyJobDto", "CounterDto" })
                };
                jobGraph.InsertOne(counterToInsert);
                idsToRemove.AddRange(groupedCounters.Select(c => c["_id"]));
            }

            if (!idsToRemove.Any())
            {
                return(true);
            }

            jobGraph.DeleteMany(new BsonDocument("_id", new BsonDocument("$in", idsToRemove)));
            return(true);
        }
 public void TestContains()
 {
     var array = new BsonArray { 1, 2 };
     Assert.IsTrue(array.Contains(1));
     Assert.IsTrue(array.Contains(2));
     Assert.IsFalse(array.Contains(3));
 }
Пример #16
0
 public void TestContainsNull()
 {
     var array = new BsonArray { 1, 2 };
     Assert.Throws<ArgumentNullException>(() => { array.Contains(null); });
 }
 /// <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;
 }
Пример #18
0
 /// <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;
 }
Пример #19
0
 public bool Contains(object value)
 {
     return(_array.Contains(Actor.ToBsonValue(value)));
 }