private async Task UpdateAsync(EventTracking entity)
        {
            await using var connection = new NpgsqlConnection(Database.ConnectionString);
            await connection.OpenAsync();

            await using var transaction = connection.BeginTransaction();
            try
            {
                await connection.ExecuteAsync(
                    $@"UPDATE shoppingcart.event_tracking
                            SET resource_name = @resource_name, last_message_number = @last_message_number, timestamp = @timestamp
                            WHERE resource_name = @resource_name",
                    new
                {
                    resource_name       = entity.ResourceName,
                    last_message_number = entity.LastMessageNumber,
                    timestamp           = DateTimeOffset.UtcNow
                });

                await transaction.CommitAsync();
            }
            catch (Exception)
            {
                await transaction.RollbackAsync();

                throw;
            }
        }
Esempio n. 2
0
        public Task <MessageNumber> GetLastMessageNumber(string resourceName)
        {
            var eventTracking = _eventTrackingList.SingleOrDefault(x => x.ResourceName == resourceName);

            if (eventTracking == null)
            {
                eventTracking = EventTracking.New(resourceName);
                _eventTrackingList.Add(eventTracking);
            }

            return(Task.FromResult(eventTracking.LastMessageNumber));
        }
        public async Task <MessageNumber> GetLastMessageNumber(string resourceName)
        {
            await using var connection = new NpgsqlConnection(Database.ConnectionString);
            await connection.OpenAsync();

            var eventTracking = await GetEventTracking(resourceName);

            if (eventTracking == null)
            {
                eventTracking = EventTracking.New(resourceName);
                await SaveAsync(eventTracking);
            }

            return(eventTracking.LastMessageNumber);
        }