public bool RemoveDeleted(List <long> userIds)
        {
            bool result = true;
            int  i      = 1;

            var languagesQuery = new LanguagesQuery(LanguageShortName.Unknown, LanguageShortName.Unknown);
            var languagesIds   = Enum.GetValues(typeof(LanguageShortName)).Cast <LanguageShortName>()
                                 .Where(e => languagesQuery.GetByShortName(e) != null)
                                 .Select(e => languagesQuery.GetByShortName(e).Id).ToList();

            foreach (long userId in userIds)
            {
                foreach (var languageId in languagesIds)
                {
                    IUserKnowledgeQuery userKnowledgeQuery = new UserKnowledgeQuery(userId, languageId);
                    if (!userKnowledgeQuery.RemoveDeleted())
                    {
                        Console.WriteLine("Не удалось удалить знания пользователя {0} по языку {1}!", userId);
                        result = false;
                    }
                }
                if (i % 100 == 0)
                {
                    Console.WriteLine("Удалены старые данные для {0} пользователей из {1}!", i, userIds.Count);
                }
                i++;
            }
            return(result);
        }
Esempio n. 2
0
        public UserIdAttribute(bool needCreate = false, string uniqueParamName = "userId")
        {
            _needCreate      = needCreate;
            _uniqueParamName = uniqueParamName;
            _usersQuery      = new UsersQuery();
            _usersQuery.OnChangeLastActivity = userId => Task.Factory.StartNew(() => {
                try {
                    long languageId = WebSettingsConfig.Instance.GetLanguageFromId();
                    IUserKnowledgeQuery userKnowledgeQuery = new UserKnowledgeQuery(userId, languageId);
                    userKnowledgeQuery.RemoveDeleted();

                    var repetitionQuery = new UserRepetitionKnowledgeQuery(userId, languageId, KnowledgeDataType.All);
                    IUserRepetitionIntervalQuery userRepetitionIntervalQuery =
                        new UserRepetitionIntervalQuery(userId, languageId,
                                                        KnowledgeSourceType.Knowledge,
                                                        repetitionQuery, RepetitionType.All);
                    userRepetitionIntervalQuery.RemoveWithoutData();
                } catch (Exception e) {
                    LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat(
                        "UserIdAttribute.Constructor. СЮДА НЕ ДОЛЖНЫ БЫЛИ ПОПАСТЬ! При вызове для пользователя с идентификатором {0} возникло исключение {1}!",
                        userId, e);
                }
            });
        }