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);
        }
예제 #5
0
 public SuccessfulMessageHandler(
     IAuditContext auditContext,
     IBus bus,
     IMessageLogFactory messageLogFactory)
 {
     this.auditContext      = auditContext;
     this.bus               = bus;
     this.messageLogFactory = messageLogFactory;
 }
예제 #6
0
 public DataVaultContext(
     IDataVaultConfiguration dataConfiguration,
     IAuditContext auditContext,
     IDistributedCache <LookupItem[]> cache)
     : base(new Lazy <IDataSession>(dataConfiguration.CreateSession))
 {
     _auditContext = auditContext;
     Cache         = cache;
 }
예제 #7
0
        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();
            }
        }
예제 #8
0
 public BackOfficeHub(
     IBus bus,
     IBrokerConnectionManager brokerConnectionManager,
     IAuditContext auditContext,
     IJsonSerializer jsonSerializer)
 {
     this.bus = bus;
     this.brokerConnectionManager = brokerConnectionManager;
     this.auditContext            = auditContext;
     this.jsonSerializer          = jsonSerializer;
 }
예제 #9
0
        /// <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();
        }
예제 #10
0
 /// <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;
 }
예제 #11
0
        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));
        }
예제 #14
0
        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());
                }
            }
        }
예제 #15
0
        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));
 }
예제 #17
0
 /// <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;
 }
예제 #18
0
 public ClienteEnderecoRepository(IAuditContext context) : base(context)
 {
 }
예제 #19
0
 public DataContext(DbContextOptions <DataContext> options, IAuditContext auditContext)
     : base(options)
 {
     _auditContext = auditContext;
 }
 public ItemAuditRepository(IAuditContext context, IHeaderAuditRepository headerAuditRepository) : base(context, headerAuditRepository)
 {
 }
예제 #21
0
 public UnitOfWork(IAuditContext iAuditContext)
 {
     this.iAuditContext = iAuditContext;
 }
예제 #22
0
        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>();
 }
예제 #24
0
 internal static DataVaultCommand UpdateStoredProcedure(IDataSession dataSession, IAuditContext auditContext, string stpName)
 {
     dataSession.BeginTransaction(IsolationLevel.Unspecified);
     return(ReadOnlyStoredProcedure(dataSession, stpName).WithMd(auditContext.AuditInfo));
 }
예제 #25
0
        internal void EndAudit(IAuditContext ac)
        {
            PrepareChanges(ac);

            ac.SaveChanges();
        }
예제 #26
0
 public Repository(IAuditContext context)
 {
     DbContext = context;
     DbSet     = DbContext.Set <TEntity>();
 }
예제 #27
0
        internal async Task<int> EndAuditAsync(IAuditContext ac)
        {
            PrepareChanges(ac);

            return await ac.SaveChangesAsync();
        }
예제 #28
0
 public ClienteRepository(IAuditContext context) : base(context)
 {
 }
예제 #29
0
        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;
 }
예제 #31
0
        internal async Task <int> EndAuditAsync(IAuditContext ac)
        {
            PrepareChanges(ac);

            return(await ac.SaveChangesAsync());
        }