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

            var         languagesQuery = new LanguagesQuery(LanguageShortName.Unknown, LanguageShortName.Unknown);
            List <long> 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 (long languageId in languagesIds)
                {
                    IUserRepetitionKnowledgeQuery repetitionQuery = new UserRepetitionKnowledgeQuery(userId, languageId,
                                                                                                     KnowledgeDataType.
                                                                                                     All);
                    IUserRepetitionIntervalQuery userRepetitionIntervalQuery = new UserRepetitionIntervalQuery(userId,
                                                                                                               languageId,
                                                                                                               KnowledgeSourceType
                                                                                                               .
                                                                                                               Knowledge,
                                                                                                               repetitionQuery,
                                                                                                               RepetitionType
                                                                                                               .All);
                    if (!userRepetitionIntervalQuery.RemoveWithoutData())
                    {
                        Console.WriteLine(
                            "Не удалось удалить данные о повторениях для пользователя {0} для языка {1}!", userId,
                            languageId);
                        result = false;
                    }
                }
                if (i % 100 == 0)
                {
                    Console.WriteLine("Удалены данные о повторениях для {0} несуществующих пользователей из {1}!", i,
                                      userIds.Count);
                }
                i++;
            }
            return(result);
        }
Example #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);
                }
            });
        }