public async Task CreateMessageAsync(EventEntity eventEntity, DateTime time, MessageType type, IComponent component, ComponentStatus status) { using (_logger.Scope("Creating new message of type {Type} for event {EventRowKey} at {Timestamp} affecting {ComponentPath} with status {ComponentStatus}.", type, eventEntity.RowKey, time, component.Path, status)) { var existingMessage = await _table.RetrieveAsync <MessageEntity>(MessageEntity.GetRowKey(eventEntity, time)); if (existingMessage != null) { _logger.LogInformation("Message already exists, will not recreate."); return; } var contents = _builder.Build(type, component, status); var messageEntity = new MessageEntity(eventEntity, time, contents, type); _logger.LogInformation("Creating message with time {MessageTimestamp} and contents {MessageContents}.", messageEntity.Time, messageEntity.Contents); await _table.InsertAsync(messageEntity); } }
public async Task Handle(EditStatusMessageManualChangeEntity entity) { var eventRowKey = EventEntity.GetRowKey(entity.EventAffectedComponentPath, entity.EventStartTime); var eventEntity = await _table.RetrieveAsync <EventEntity>(eventRowKey); if (eventEntity == null) { throw new ArgumentException("Cannot edit a message for an event that does not exist."); } var messageEntity = await _table.RetrieveAsync <MessageEntity>(MessageEntity.GetRowKey(eventRowKey, entity.MessageTimestamp)); if (messageEntity == null) { throw new ArgumentException("Cannot edit a message that does not exist."); } messageEntity.Contents = entity.MessageContents; messageEntity.Type = (int)MessageType.Manual; await _table.ReplaceAsync(messageEntity); }
public async Task Handle(EditStatusEventManualChangeEntity entity) { var eventRowKey = EventEntity.GetRowKey(entity.EventAffectedComponentPath, entity.EventStartTime); var eventEntity = await _table.RetrieveAsync <EventEntity>(eventRowKey); if (eventEntity == null) { throw new ArgumentException("Cannot edit an event that does not exist."); } eventEntity.AffectedComponentStatus = entity.EventAffectedComponentStatus; ManualStatusChangeUtility.UpdateEventIsActive(eventEntity, entity.EventIsActive, entity.Timestamp.UtcDateTime); await _table.ReplaceAsync(eventEntity); }
public async Task Handle(AddStatusMessageManualChangeEntity entity) { var time = entity.Timestamp.UtcDateTime; var eventRowKey = EventEntity.GetRowKey(entity.EventAffectedComponentPath, entity.EventStartTime); var eventEntity = await _table.RetrieveAsync <EventEntity>(eventRowKey); if (eventEntity == null) { throw new ArgumentException("Cannot create a message for an event that does not exist."); } var messageEntity = new MessageEntity(eventEntity, time, entity.MessageContents, MessageType.Manual); await _table.InsertAsync(messageEntity); if (ManualStatusChangeUtility.UpdateEventIsActive(eventEntity, entity.EventIsActive, time)) { await _table.ReplaceAsync(eventEntity); } }
public async Task <DateTime> Get(string name) { name = name ?? throw new ArgumentNullException(nameof(name)); using (_logger.Scope("Fetching cursor with name {CursorName}.", name)) { var cursor = await _table.RetrieveAsync <CursorEntity>(name); DateTime value; if (cursor == null) { // If we can't find a cursor, the job is likely uninitialized, so start at the beginning of time. value = DateTime.MinValue; _logger.LogInformation("Could not fetch cursor, reinitializing cursor at {CursorValue}.", value); } else { value = cursor.Value; _logger.LogInformation("Fetched cursor with value {CursorValue}.", value); } return(value); } }