示例#1
0
        public SerializedEvent Serialize(IAggregateEvent aggregateEvent, IEnumerable <KeyValuePair <string, string> > metadatas)
        {
            var eventDefinition = _eventDefinitionService.GetEventDefinition(aggregateEvent.GetType());

            var metadata = new Metadata(metadatas.Concat(new[]
            {
                new KeyValuePair <string, string>(MetadataKeys.EventName, eventDefinition.Name),
                new KeyValuePair <string, string>(MetadataKeys.EventVersion, eventDefinition.Version.ToString(CultureInfo.InvariantCulture)),
            }));

            var dataJson = _jsonSerializer.Serialize(aggregateEvent);
            var metaJson = _jsonSerializer.Serialize(metadata);

            return(new SerializedEvent(
                       metaJson,
                       dataJson,
                       metadata.AggregateSequenceNumber));
        }
        public ActionResult ManualExistingEvent(int userID, string feedMessage, string eventDefinitionID)
        {
            var user            = _userService.GetUser(userID);
            var eventDefinition = _eventDefinitionService.GetEventDefinition(eventDefinitionID);

            if (user != null && eventDefinition != null)
            {
                _eventPublisher.ProcessEvent(feedMessage, user, eventDefinition.EventDefinitionID, false);
            }
            return(RedirectToAction("ManualEvent"));
        }
        public void ProcessOneCalculation()
        {
            var nextItem = _awardCalcRepository.Dequeue();

            if (String.IsNullOrEmpty(nextItem.Key))
            {
                return;
            }
            var eventDefinition = _eventDefinitionService.GetEventDefinition(nextItem.Key);
            var user            = _userRepository.GetUser(nextItem.Value);

            if (eventDefinition == null)
            {
                _errorLog.Log(new Exception(String.Format("Event calculation attempt on nonexistent event \"{0}\"", nextItem.Key)), ErrorSeverity.Warning);
                return;
            }
            if (user == null)
            {
                _errorLog.Log(new Exception(String.Format("Event calculation attempt on nonexistent user {0}", nextItem.Value)), ErrorSeverity.Warning);
                return;
            }
            var associatedAwards = _awardDefinitionService.GetByEventDefinitionID(eventDefinition.EventDefinitionID);

            foreach (var award in associatedAwards)
            {
                if (award.IsSingleTimeAward)
                {
                    var isAwarded = _userAwardService.IsAwarded(user, award);
                    if (isAwarded)
                    {
                        continue;
                    }
                }
                var conditions    = _awardDefinitionService.GetConditions(award.AwardDefinitionID);
                var conditionsMet = 0;
                foreach (var condition in conditions)
                {
                    var eventCount = _pointLedgerRepository.GetEntryCount(user.UserID, condition.EventDefinitionID);
                    if (eventCount >= condition.EventCount)
                    {
                        conditionsMet++;
                    }
                }
                if (conditions.Count != 0 && conditionsMet == conditions.Count)
                {
                    _userAwardService.IssueAward(user, award);
                }
            }
        }
        public async Task ProcessCalculation(string eventDefinitionID, int userID)
        {
            var eventDefinition = await _eventDefinitionService.GetEventDefinition(eventDefinitionID);

            var user = await _userRepository.GetUser(userID);

            if (eventDefinition == null)
            {
                _errorLog.Log(new Exception($"Event calculation attempt on nonexistent event \"{eventDefinitionID}\""), ErrorSeverity.Warning);
                return;
            }
            if (user == null)
            {
                _errorLog.Log(new Exception($"Event calculation attempt on nonexistent user {userID}"), ErrorSeverity.Warning);
                return;
            }
            var associatedAwards = await _awardDefinitionService.GetByEventDefinitionID(eventDefinition.EventDefinitionID);

            foreach (var award in associatedAwards)
            {
                if (award.IsSingleTimeAward)
                {
                    var isAwarded = await _userAwardService.IsAwarded(user, award);

                    if (isAwarded)
                    {
                        continue;
                    }
                }
                var conditions = await _awardDefinitionService.GetConditions(award.AwardDefinitionID);

                var conditionsMet = 0;
                foreach (var condition in conditions)
                {
                    var eventCount = await _pointLedgerRepository.GetEntryCount(user.UserID, condition.EventDefinitionID);

                    if (eventCount >= condition.EventCount)
                    {
                        conditionsMet++;
                    }
                }
                if (conditions.Count != 0 && conditionsMet == conditions.Count)
                {
                    await _userAwardService.IssueAward(user, award);
                }
            }
        }
示例#5
0
        public void ProcessEvent(string feedMessage, User user, string eventDefinitionID, bool overridePublishToActivityFeed)
        {
            var timeStamp       = DateTime.UtcNow;
            var eventDefinition = _eventDefinitionService.GetEventDefinition(eventDefinitionID);
            var ledgerEntry     = new PointLedgerEntry {
                UserID = user.UserID, EventDefinitionID = eventDefinitionID, Points = eventDefinition.PointValue, TimeStamp = timeStamp
            };

            _pointLedgerRepository.RecordEntry(ledgerEntry);
            _profileService.UpdatePointTotal(user);
            if (eventDefinition.IsPublishedToFeed && !overridePublishToActivityFeed)
            {
                _feedService.PublishToFeed(user, feedMessage, eventDefinition.PointValue, timeStamp);
                _feedService.PublishToActivityFeed(feedMessage);
            }
            _awardCalculator.QueueCalculation(user, eventDefinition);
        }