/// <inheritdoc/> protected override async Task <AuditEventModel> ProtectedHandleAsync(CreateAuditEventCommand request, CancellationToken cancellationToken) { XDASv2Net.Model.EventType parsedEventType = Enum.TryParse(request.Event.Action.Event.Name, out XDASv2Net.Model.EventType eventType) ? eventType : XDASv2Net.Model.EventType.INVOKE_SERVICE; SubEventType parsedSubEventType = Enum.TryParse(request.Event.Action.SubEvent.Name, out SubEventType subEventType) ? subEventType : SubEventType.None; var eventEntity = new AuditEventEntity() { Id = idGenerator.GenerateId(), Timestamp = DateTime.UtcNow, EventType = (int)parsedEventType, SubEventType = (int)parsedSubEventType, EventSerialized = serializer.Serialize(request.Event) }; Context.AuditEventRepository.Add(eventEntity); await Context.SaveChangesAsync(cancellationToken); var result = AuditEventModel.Create(eventEntity, serializer); await Gateway.NotifyGroupsAsync(string.Empty, EventType.AuditEventCreated, result, cancellationToken); return(result); }
private XDASv2Event CreateXDASEvent(ICustomPrincipal principal, SubEventType subEventType, OutcomeType outcomeType) { return(new XDASv2Event() { Initiator = CreateInitiator(principal), Observer = CreateObserver(), Action = CreateAction(subEventType, outcomeType) }); }
private XDASv2Net.Model.Action CreateAction(SubEventType subEventType, OutcomeType outcomeType) { XDASv2Net.Model.Action action = new XDASv2Net.Model.Action() { Event = new Event(), SubEvent = new SubEvent() { Name = subEventType.ToString() }, Time = new Time() { Offset = (int)new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds() }, Outcome = outcomeType.ToString() }; BaseEventType baseEventType = subEventType.GetAttribute <EventTypeAttribute>().BaseEventType; switch (baseEventType) { case BaseEventType.Create: action.Event.Id = XDASv2Net.Model.EventType.CREATE_DATA_ITEM.GetAttribute <EventInformationAttribute>().EventIdentifier; action.Event.Name = XDASv2Net.Model.EventType.CREATE_DATA_ITEM.ToString(); break; case BaseEventType.Update: action.Event.Id = XDASv2Net.Model.EventType.MODIFY_DATA_ITEM_ATTRIBUTE.GetAttribute <EventInformationAttribute>().EventIdentifier; action.Event.Name = XDASv2Net.Model.EventType.MODIFY_DATA_ITEM_ATTRIBUTE.ToString(); break; case BaseEventType.Delete: action.Event.Id = XDASv2Net.Model.EventType.DELETE_DATA_ITEM.GetAttribute <EventInformationAttribute>().EventIdentifier; action.Event.Name = XDASv2Net.Model.EventType.DELETE_DATA_ITEM.ToString(); break; case BaseEventType.Read: default: action.Event.Id = XDASv2Net.Model.EventType.QUERY_DATA_ITEM_ATTRIBUTE.GetAttribute <EventInformationAttribute>().EventIdentifier; action.Event.Name = XDASv2Net.Model.EventType.QUERY_DATA_ITEM_ATTRIBUTE.ToString(); break; } return(action); }
/// <inheritdoc/> public async Task AddDefaultEventAsync(ICustomPrincipal principal, object data, SubEventType subEventType, OutcomeType outcomeType = OutcomeType.Success) { try { Ensure.ArgumentNotNull(principal, nameof(principal)); if (!principal.IsInRole(RoleType.Service)) { XDASv2Event xdasEvent = CreateXDASEvent(principal, subEventType, outcomeType); Target target = new Target() { Entity = CreateTargetEntity() }; target.Data = data; xdasEvent.Target = target; var command = new CreateAuditEventCommand() { Event = xdasEvent }; await mediator.Send(command); } } catch (Exception e) { logger.LogError(e, e.Message); } }