예제 #1
0
 /// <summary>
 /// Add a RequestId so the audit events can be grouped per request
 /// </summary>
 public static void UseAuditCorrelationId(this IApplicationBuilder app, IHttpContextAccessor ctxAccesor)
 {
     Configuration.AddCustomAction(ActionType.OnScopeCreated, scope =>
     {
         HttpContext httpContext = ctxAccesor.HttpContext;
         scope.Event.CustomFields[CorrelationIdField] = httpContext.TraceIdentifier;
     });
 }
        public static IServiceCollection AddPersistenceLayer(this IServiceCollection services,
                                                             string databaseConnection)
        {
            services
            .AddDbContext <AIDungeonPromptsDbContext>(options => options.UseNpgsql(databaseConnection, builder =>
            {
                // See: https://docs.microsoft.com/en-us/ef/core/querying/single-split-queries
                builder.UseQuerySplittingBehavior(QuerySplittingBehavior.SingleQuery);
            }))
            .AddScoped <IAIDungeonPromptsDbContext>(provider => provider.GetService <AIDungeonPromptsDbContext>() !);

            Configuration.AddCustomAction(ActionType.OnScopeCreated, scope =>
            {
                scope.SetCustomField(AuditScopeId, Guid.NewGuid());
            });
            _ = Configuration.Setup()
                .UseEntityFramework(ef => ef
                                    .AuditTypeExplicitMapper(m => m
                                                             .Map <Prompt, AuditPrompt>((prompt, auditEntity) =>
            {
                auditEntity.PromptId = prompt.Id;
            })
                                                             .Map <PromptTag, AuditPrompt>((tag, auditEntity) =>
            {
                auditEntity.PromptId = tag.PromptId;
            })
                                                             .Map <WorldInfo, AuditPrompt>((wi, auditEntity) =>
            {
                auditEntity.PromptId = wi.PromptId;
            })
                                                             .AuditEntityAction <AuditPrompt>((evt, entry, auditEntity) =>
            {
                auditEntity.DateCreated  = DateTime.UtcNow;
                auditEntity.Entry        = entry.ToJson();
                auditEntity.AuditScopeId = (Guid)evt.CustomFields[AuditScopeId];
            })
                                                             ).IgnoreMatchedProperties()
                                    );

            return(services);
        }
예제 #3
0
 public void OnEventSaved(Action <AuditScope> action)
 {
     Configuration.AddCustomAction(ActionType.OnEventSaved, action);
 }
예제 #4
0
 public void OnScopeCreated(Func <AuditScope, Task> action)
 {
     //TODO: FDCG: Pending test
     Configuration.AddCustomAction(ActionType.OnScopeCreated, action);
 }
예제 #5
0
 public void OnScopeCreated(Action <AuditScope> action)
 {
     Configuration.AddCustomAction(ActionType.OnScopeCreated, action);
 }
예제 #6
0
 public void OnEventSaving(Func <AuditScope, Task> action)
 {
     //TODO: FDCG: Pending test
     Configuration.AddCustomAction(ActionType.OnEventSaving, action);
 }
예제 #7
0
 public void OnEventSaving(Func <AuditScope, Task> action)
 {
     Configuration.AddCustomAction(ActionType.OnEventSaving, action);
 }