예제 #1
0
        public int CommitChanges()
        {
            if (string.IsNullOrEmpty(this.token))
                return 0;

            if(ScoreItems.Count > 0)
            {
                TableBatchOperation batch = new TableBatchOperation();
                ScoreItems.ToList().ForEach(x =>
                {
                    batch.InsertOrReplace(x.Value);
                });
                eventScoreTable.ExecuteBatch(batch);
            }

            TableQuery<EventScoreItem> query = new TableQuery<EventScoreItem>()
                .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, this.token));

            var eventScore = eventScoreTable.ExecuteQuery(query).Sum(x=>x.Score);

            var totalItem = new EventScoreItem
            {
                PartitionKey = dddEventId.ToString(),
                RowKey = this.token,
                DDDEventId = dddEventId,
                UserName = userName,
                Score = eventScore
            };

            TableOperation insert = TableOperation.InsertOrReplace(totalItem);
            eventScoreTable.Execute(insert);

            return eventScore;
        }
예제 #2
0
        private void AddItem(int? timeSlotId, string key, int score = 1)
        {
            var fullKey = timeSlotId != null ? timeSlotId.ToString() + "_" + key : key;

            if (!ScoreItems.ContainsKey(fullKey))
            {
                var scoreItem = new EventScoreItem
                {
                    PartitionKey = token,
                    RowKey = fullKey,
                    DDDEventId = dddEventId,
                    UserName = userName,
                    Score = score
                };
                ScoreItems.Add(fullKey, scoreItem);
            }
        }