public AcknowledgementController( IBus bus, IAuditContext auditContext) { this.bus = bus; this.auditContext = auditContext; }
public AcknowledgementController( IBus bus, IAuditContext auditContext) { this.bus = bus; this.auditContext = auditContext; }
public AuditService(ILogger logger, HighlightClient client, IAuditContext context) { _logger = logger; _client = client; _auditFile = context.AuditFile; _companyIds = context.CompanyIds.ToArray(); }
/// <summary> /// Creates a <see cref="IRoutingContext" /> based on the current context. /// </summary> public static IRoutingContext CreateRoutingContext(this StageConnector<IAuditContext, IRoutingContext> stageConnector, OutgoingMessage outgoingMessage, RoutingStrategy routingStrategy, IAuditContext sourceContext) { Guard.AgainstNull(nameof(outgoingMessage), outgoingMessage); Guard.AgainstNull(nameof(routingStrategy), routingStrategy); Guard.AgainstNull(nameof(sourceContext), sourceContext); return new RoutingContext(outgoingMessage, routingStrategy, sourceContext); }
public SuccessfulMessageHandler( IAuditContext auditContext, IBus bus, IMessageLogFactory messageLogFactory) { this.auditContext = auditContext; this.bus = bus; this.messageLogFactory = messageLogFactory; }
public DataVaultContext( IDataVaultConfiguration dataConfiguration, IAuditContext auditContext, IDistributedCache <LookupItem[]> cache) : base(new Lazy <IDataSession>(dataConfiguration.CreateSession)) { _auditContext = auditContext; Cache = cache; }
private void UpdateMessageRetries(Message replayedMessage, IAuditContext auditContext) { using (var transaction = auditContext.BeginTransaction()) { var messageToUpdate = auditContext.MessageLog.First(a => a.BrokerId == replayedMessage.BrokerId); messageToUpdate.Retries++; auditContext.SaveChanges(); transaction.Commit(); } }
public BackOfficeHub( IBus bus, IBrokerConnectionManager brokerConnectionManager, IAuditContext auditContext, IJsonSerializer jsonSerializer) { this.bus = bus; this.brokerConnectionManager = brokerConnectionManager; this.auditContext = auditContext; this.jsonSerializer = jsonSerializer; }
/// <summary> /// Constructs membersip service /// </summary> /// <param name="ctx"> /// context injection /// </param> /// <param name="principal"> /// current user injection /// </param> /// <param name="dataService"> /// Common Data Service /// </param> /// <param name="configService"> /// Site Configuration Service /// </param> /// <param name="auditContext"> /// The audit Context. /// </param> public MembershipService(IDataContext ctx, IPrincipal principal, ICommonDataService dataService, IConfigService configService, IAuditContext auditContext) { Debug.Assert(ctx != null, "Data context should not be null"); Debug.Assert(principal != null, "User should not be null"); this.context = ctx; this.principal = principal; this.dataService = dataService; this.configService = configService; this.currentUser = this.principal.Identity.IsAuthenticated ? this.GetUserByName(this.principal.Identity.Name) : null; this.auditContext = auditContext; this.audit = ((DbContext)this.context).BeginAudit(); }
/// <summary> /// Creates an instance of the <see cref="OpenApiOperationInvoker{TRequest, TResponse}"/>. /// </summary> /// <param name="operationLocator">The operation locator.</param> /// <param name="parameterBuilder">The parameter builder.</param> /// <param name="accessChecker">The access checker.</param> /// <param name="exceptionMapper">The exception mapper.</param> /// <param name="resultBuilder">The result builder.</param> /// <param name="configuration">The <see cref="IOpenApiConfiguration"/>.</param> /// <param name="auditContext">The audit context.</param> /// <param name="logger">The logger.</param> /// <param name="operationsInstrumentation">Operations instrumentation.</param> /// <param name="exceptionsInstrumentation">Exceptions instrumentation.</param> public OpenApiOperationInvoker( IOpenApiServiceOperationLocator operationLocator, IOpenApiParameterBuilder <TRequest> parameterBuilder, IOpenApiAccessChecker accessChecker, IOpenApiExceptionMapper exceptionMapper, IOpenApiResultBuilder <TResponse> resultBuilder, IOpenApiConfiguration configuration, IAuditContext auditContext, ILogger <OpenApiOperationInvoker <TRequest, TResponse> > logger, IOperationsInstrumentation <OpenApiOperationInvoker <TRequest, TResponse> > operationsInstrumentation, IExceptionsInstrumentation <OpenApiOperationInvoker <TRequest, TResponse> > exceptionsInstrumentation) { this.operationLocator = operationLocator; this.parameterBuilder = parameterBuilder; this.accessChecker = accessChecker; this.exceptionMapper = exceptionMapper; this.resultBuilder = resultBuilder; this.auditContext = auditContext; this.logger = logger; this.operationsInstrumentation = operationsInstrumentation; this.configuration = configuration; this.exceptionsInstrumentation = exceptionsInstrumentation; }
private IEnumerable <InsertDocumentIntoRemoteBackOfficeCommand> GetUnacknowledgedMessages(IAuditContext auditContext) { var brokerId = GetBrokerId(); var messageType = typeof(InsertDocumentIntoRemoteBackOfficeCommand).ToString(); var maxiumDeliveryDate = DateTime.Today.AddDays(1); var unacknowledgedMessages = auditContext.MessageLog.Where( m => m.BrokerId == brokerId && m.CompletionDate == null && m.Retries < 10 && m.MessageType == messageType && m.CreateDate <= maxiumDeliveryDate) .ToList(); return (unacknowledgedMessages.Select( unacknowledgedMessage => jsonSerializer.Deserialize <InsertDocumentIntoRemoteBackOfficeCommand>(unacknowledgedMessage.Body)) .ToList()); }
public HubConnectionEventHandler(IAuditContext auditContext) { this.auditContext = auditContext; }
/// <summary> /// Creates a <see cref="IRoutingContext" /> based on the current context. /// </summary> public static IRoutingContext CreateRoutingContext(this StageConnector <IAuditContext, IRoutingContext> stageConnector, OutgoingMessage outgoingMessage, RoutingStrategy routingStrategy, IAuditContext sourceContext) { Guard.AgainstNull(nameof(outgoingMessage), outgoingMessage); Guard.AgainstNull(nameof(routingStrategy), routingStrategy); Guard.AgainstNull(nameof(sourceContext), sourceContext); return(new RoutingContext(outgoingMessage, routingStrategy, sourceContext)); }
private List <DatabaseTable> GetDatabaseTables(IAuditContext db) { db.Database.OpenConnection(); using (var cmd = db.Database.GetDbConnection().CreateCommand()) { cmd.CommandText = @"SELECT DISTINCT S.schema_id AS SchemaId, S.Name as SchemaName, T.object_id AS ObjectId, T.Name AS TableName, C.column_id AS ColumnId, C.Name AS ColumnName, TY.name AS DataTypeName, C.max_length AS MaxLength, C.precision, C.scale, C.is_nullable AS IsNullable, C.is_identity AS IsIdentity, CAST(CASE WHEN PKs.object_id IS NOT NULL THEN 1 ELSE 0 END AS BIT) AS IsPrimaryKey, CAST(CASE WHEN IsNull(C.default_object_id, 0) > 0 THEN 1 ELSE 0 END AS Bit) AS HasDefaultValue FROM sys.schemas S JOIN sys.tables T ON T.schema_id = S.schema_id JOIN sys.columns C ON C.object_id = T.object_id JOIN sys.types TY ON TY.user_type_id = C.user_type_id LEFT OUTER JOIN( SELECT DISTINCT T.object_id, c.column_id FROM sys.tables T JOIN sys.columns C ON C.object_id = T.object_id JOIN sys.index_columns IC ON IC.object_id = C.object_id AND IC.column_id = C.column_id JOIN sys.indexes I ON I.object_id = IC.object_id AND I.index_id = IC.index_id AND I.is_primary_key = 1 ) as PKs ON PKs.object_id = c.object_id AND PKs.column_id = c.column_id ORDER BY S.Name, T.Name, C.Name" ; using (var reader = cmd.ExecuteReader()) { Dictionary <string, DatabaseTable> tables = new Dictionary <string, DatabaseTable>(); while (reader.Read()) { string fullTableName = $"{reader["SchemaName"]}.{reader["TableName"]}"; if (!tables.TryGetValue(fullTableName, out DatabaseTable table)) { table = new DatabaseTable { SchemaId = reader.GetInt32(reader.GetOrdinal("SchemaId")), SchemaName = reader.GetString(reader.GetOrdinal("SchemaName")), ObjectId = reader.GetInt32(reader.GetOrdinal("ObjectId")), TableName = reader.GetString(reader.GetOrdinal("TableName")), Fields = new List <DatabaseField>() }; tables.Add(fullTableName, table); } DatabaseField field = new DatabaseField { ColumnId = reader.GetInt32(reader.GetOrdinal("ColumnId")), ColumnName = reader.GetString(reader.GetOrdinal("ColumnName")), DataTypeName = reader.GetString(reader.GetOrdinal("DataTypeName")), MaxLength = reader.GetInt16(reader.GetOrdinal("MaxLength")), Precision = reader.GetByte(reader.GetOrdinal("Precision")), Scale = reader.GetByte(reader.GetOrdinal("Scale")), IsNullable = reader.GetBoolean(reader.GetOrdinal("IsNullable")), IsIdentity = reader.GetBoolean(reader.GetOrdinal("IsIdentity")), IsPrimaryKey = reader.GetBoolean(reader.GetOrdinal("IsPrimaryKey")), HasDefaultValue = reader.GetBoolean(reader.GetOrdinal("HasDefaultValue")) }; table.Fields.Add(field); } return(tables.Values.ToList()); } } }
private void PrepareChanges(IAuditContext ac) { foreach (var item in Changes.Where(x => x.State == EntityState.Added)) { Type type = item.Entity.GetType(); List <string> keyValues = new List <string>(); foreach (var k in type.GetEntityProperties(true)) { var key = k.GetValue(item.Entity); var pv = item.Values.FirstOrDefault(x => x.Name == k.Name); if (pv == null) { pv = new CFieldValue { Name = k.Name }; item.Values.Add(pv); } pv.NewValue = key; keyValues.Add(key.ToString()); } item.Key = string.Join(",", keyValues); } List <CLinkValue> links = new List <CLinkValue>(); foreach (var change in Changes) { foreach (var item in change.Values) { foreach (var fk in item.Property.FKProperties) { CLinkValue v = new CLinkValue(); v.ObjectName = fk.EntityName; var v1 = item.NewValue ?? item.OldValue; if (v1 == null) { continue; } v.Key = v1.ToString(); if (string.IsNullOrWhiteSpace(v.Key)) { continue; } v.ChildObject = item.Property.Property.DeclaringType.Name; v.ChildKey = change.Key; v.Operation = change.State.ToString(); links.Add(v); } } } foreach (var item in links.GroupBy(x => x.ObjectName)) { string name = item.Key; foreach (var k in item.GroupBy(x => x.Key).ToList()) { string key = k.Key; Change c = Changes.FirstOrDefault(x => x.ObjectName == name && x.Key == key); if (c != null) { c.Links.AddRange(k); } else { c = new Change(EntityState.Modified); c.ObjectName = name; c.Key = key; c.Links.AddRange(k); Changes.Add(c); } } } JavaScriptSerializer sr = new JavaScriptSerializer(); foreach (var change in Changes) { if (change.Entity is IAuditIgnore) { continue; } IAuditItem item = ac.CreateNew(); item.Action = change.State.ToString(); item.AuditTime = DateTime.UtcNow; //item.IPAddress = ac.GetIPAddress(); //item.Username = ac.GetUsername(); item.TableKey = change.Key; item.TableName = change.ObjectName; item.Fields = sr.Serialize(change.Values); item.Links = sr.Serialize(change.Links); //ac.AddAudit(item); } }
public static bool TryGetAuditContext( this IAuditContext context, out AuditFilterContext auditFilterContext) { return(context.Extensions.TryGet(out auditFilterContext)); }
/// <summary>Constructs ChangeLog service</summary> /// <param name="ctx">context injection</param> /// <param name="membershipService">Membership service</param> public ChangeLogService(IAuditContext ctx, IMembershipService membershipService) { this.context = ctx; this.membershipService = membershipService; }
public ClienteEnderecoRepository(IAuditContext context) : base(context) { }
public DataContext(DbContextOptions <DataContext> options, IAuditContext auditContext) : base(options) { _auditContext = auditContext; }
public ItemAuditRepository(IAuditContext context, IHeaderAuditRepository headerAuditRepository) : base(context, headerAuditRepository) { }
public UnitOfWork(IAuditContext iAuditContext) { this.iAuditContext = iAuditContext; }
internal void EndAudit(IAuditContext ac) { PrepareChanges(ac); ac.SaveChanges(); }
public HeaderAuditRepository(IOptions <AppSettings> options, IHttpContextAccessor httpContextAccessor, IAuditContext context) { _context = context; _httpContextAccessor = httpContextAccessor; _entities = _context.Instance.Set <HeaderAudit>(); }
internal static DataVaultCommand UpdateStoredProcedure(IDataSession dataSession, IAuditContext auditContext, string stpName) { dataSession.BeginTransaction(IsolationLevel.Unspecified); return(ReadOnlyStoredProcedure(dataSession, stpName).WithMd(auditContext.AuditInfo)); }
internal void EndAudit(IAuditContext ac) { PrepareChanges(ac); ac.SaveChanges(); }
public Repository(IAuditContext context) { DbContext = context; DbSet = DbContext.Set <TEntity>(); }
internal async Task<int> EndAuditAsync(IAuditContext ac) { PrepareChanges(ac); return await ac.SaveChangesAsync(); }
public ClienteRepository(IAuditContext context) : base(context) { }
private void PrepareChanges(IAuditContext ac) { foreach (var item in Changes.Where(x => x.State == EntityState.Added)) { Type type = item.Entity.GetType(); List<string> keyValues = new List<string>(); foreach (var k in type.GetEntityProperties(true)) { var key = k.GetValue(item.Entity); var pv = item.Values.FirstOrDefault(x => x.Name == k.Name); if (pv == null) { pv = new CFieldValue { Name = k.Name }; item.Values.Add(pv); } pv.NewValue = key; keyValues.Add(key.ToString()); } item.Key = string.Join(",", keyValues); } List<CLinkValue> links = new List<CLinkValue>(); foreach (var change in Changes) { foreach (var item in change.Values) { foreach (var fk in item.Property.FKProperties) { CLinkValue v = new CLinkValue(); v.ObjectName = fk.EntityName; var v1 = item.NewValue ?? item.OldValue; if (v1 == null) continue; v.Key = v1.ToString(); if (string.IsNullOrWhiteSpace(v.Key)) continue; v.ChildObject = item.Property.Property.DeclaringType.Name; v.ChildKey = change.Key; v.Operation = change.State.ToString(); links.Add(v); } } } foreach (var item in links.GroupBy(x => x.ObjectName)) { string name = item.Key; foreach (var k in item.GroupBy(x => x.Key).ToList()) { string key = k.Key; Change c = Changes.FirstOrDefault(x => x.ObjectName == name && x.Key == key); if (c != null) { c.Links.AddRange(k); } else { c = new Change(EntityState.Modified); c.ObjectName = name; c.Key = key; c.Links.AddRange(k); Changes.Add(c); } } } JavaScriptSerializer sr = new JavaScriptSerializer(); foreach (var change in Changes) { if (change.Entity is IAuditIgnore) continue; IAuditItem item = ac.CreateNew(); item.Action = change.State.ToString(); item.AuditTime = DateTime.UtcNow; //item.IPAddress = ac.GetIPAddress(); //item.Username = ac.GetUsername(); item.TableKey = change.Key; item.TableName = change.ObjectName; item.Fields = sr.Serialize(change.Values); item.Links = sr.Serialize(change.Links); //ac.AddAudit(item); } }
public CompletionService(IAuditContext auditContext) { this.auditContext = auditContext; }
internal async Task <int> EndAuditAsync(IAuditContext ac) { PrepareChanges(ac); return(await ac.SaveChangesAsync()); }