Example #1
0
        public TypeListOpinion(IEnumerable<Type> inclusions, IEnumerable<Type> exclusions)
        {
            var inclusionsSet = new HashSet<Type>(inclusions ?? new Type[] { });
            var exclusionsSet = new HashSet<Type>(exclusions ?? new Type[] { });

            var intersection = inclusionsSet.Join(exclusionsSet, outer => outer, inner => inner, (outer, inner) => true);

            if (intersection.Any())
                throw new Exception("A type can only be either included or excluded, not both.");

            Inclusions = inclusionsSet;
            Exclusions = exclusionsSet;
        }
        static FileFilterProvider()
        {
			_managedFileExtensions = GetManagedFileExtensions();
			_tagFileRegex = new Regex(@".*\.(" + _managedFileExtensions.Join("|") +")", RegexOptions.IgnoreCase | RegexOptions.Compiled);
			_pruneHistoryMatcherRegex = new Regex(@"^.*\" + PruneOperation.PRUNE_INVENTORY_FILE + "$", RegexOptions.Compiled);
        }
Example #3
0
        public object Any(Vote request)
        {
            Guid userId = UserSession.GetUserId();

            VoteResponse response = new VoteResponse
            {
                Result = ErrorCode.OK,
            };

            TableRepository tableRepository = new TableRepository();

            UserQuestionEntry userQuestionEntry = tableRepository.Get<UserQuestionEntry>(Tables.UserQuestion, request.QuestionId, userId);

            // Création d'un nouveau vote
            if (userQuestionEntry == null)
            {
                DateTime dateTime = DateTime.UtcNow;
                userQuestionEntry = new UserQuestionEntry(request.QuestionId, userId)
                {
                    Creation = dateTime,
                    Modification = dateTime
                };
            }
            else
            {
                userQuestionEntry.Modification = DateTime.UtcNow;
            }

            Guid target = request.VoteTarget == VoteTarget.Question ? request.QuestionId : request.OwnerId;

            HashSet<string> votesUp = new HashSet<string>(userQuestionEntry.VotesUp?.Split('|') ?? new string[] { });
            HashSet<string> votesDown = new HashSet<string>(userQuestionEntry.VotesDown?.Split('|') ?? new string[] { });

            VoteKind oldValue = VoteKind.None;
            if (votesUp.Contains(target.ToString()))
                oldValue = VoteKind.Up;
            else if (votesDown.Contains(target.ToString()))
                oldValue = VoteKind.Down;

            response.VoteKind = request.VoteKind;

            votesUp.Remove(target.ToString());
            votesDown.Remove(target.ToString());

            if (response.VoteKind == oldValue) response.VoteKind = VoteKind.None;
            else
            {
                switch (response.VoteKind)
                {
                    case VoteKind.Up:
                        votesUp.Add(target.ToString());
                        break;
                    case VoteKind.Down:
                        votesDown.Add(target.ToString());
                        break;
                }
            }

            userQuestionEntry.VotesUp = votesUp.Join("|");
            userQuestionEntry.VotesDown = votesDown.Join("|");

            if (request.VoteTarget == VoteTarget.Answer)
            {
                AnswerEntry answerEntry = tableRepository.Get<AnswerEntry>(Tables.Answers, request.QuestionId, request.OwnerId);
                answerEntry.Votes -= (int)oldValue;
                answerEntry.Votes += (int)response.VoteKind;
                tableRepository.InsertOrMerge(answerEntry, Tables.Answers);
                response.VoteValue = answerEntry.Votes;

                // badges
                if (response.VoteKind == VoteKind.Up)
                {
                    switch (answerEntry.Votes)
                    {
                        case 1: AllBadges.Approved.CreateIfNotExist(tableRepository, answerEntry.GetAnswerOwnerId()); break;
                        case 10: AllBadges.NiceAnswer.CreateForQuestion(tableRepository, answerEntry.GetAnswerOwnerId(), request.QuestionId); break;
                        case 25: AllBadges.GoodAnswer.CreateForQuestion(tableRepository, answerEntry.GetAnswerOwnerId(), request.QuestionId); break;
                        case 100: AllBadges.GreatAnswer.CreateForQuestion(tableRepository, answerEntry.GetAnswerOwnerId(), request.QuestionId); break;
                    }
                }
            }
            else
            {
                QuestionEntry questionEntry = tableRepository.Get<QuestionEntry>(Tables.Questions, request.OwnerId, request.QuestionId);
                questionEntry.Votes -= (int)oldValue;
                questionEntry.Votes += (int)response.VoteKind;
                tableRepository.InsertOrMerge(questionEntry, Tables.Questions);
                response.VoteValue = questionEntry.Votes;

                // badges
                if (response.VoteKind == VoteKind.Up)
                {
                    switch (questionEntry.Votes)
                    {
                        case 1: AllBadges.Padawan.CreateIfNotExist(tableRepository, questionEntry.GetOwnerId()); break;
                        case 10: AllBadges.NiceQuestion.CreateForQuestion(tableRepository, questionEntry.GetOwnerId(), request.QuestionId); break;
                        case 25: AllBadges.GoodQuestion.CreateForQuestion(tableRepository, questionEntry.GetOwnerId(), request.QuestionId); break;
                        case 100: AllBadges.GreatQuestion.CreateForQuestion(tableRepository, questionEntry.GetOwnerId(), request.QuestionId); break;
                    }
                }
            }

            // insert le vote
            tableRepository.InsertOrReplace(userQuestionEntry, Tables.UserQuestion);

            // badges
            if (response.VoteKind == VoteKind.Up)
                AllBadges.Supporter.CreateIfNotExist(tableRepository, userId);
            else if (response.VoteKind == VoteKind.Down)
                AllBadges.Critic.CreateIfNotExist(tableRepository, userId);

            return response;
        }