/// <summary> /// Sends the notification messages for the speficed entity. /// </summary> /// <typeparam name="T">The data object type.</typeparam> /// <param name="entity">The changed entity.</param> /// <param name="auditHistory">The audit history.</param> public void SendNotifications <T>(T entity, DbAuditHistory auditHistory) { // No action if broker list not configured if (string.IsNullOrWhiteSpace(KafkaSettings.BrokerList)) { return; } var uri = auditHistory.Uri.ToLowerInvariant(); var xml = WitsmlParser.ToXml(entity); var topic = auditHistory.LastChangeType == ChangeInfoType.delete ? KafkaSettings.DeleteTopicName : KafkaSettings.UpsertTopicName; Task.Run(() => { try { using (var producer = new Producer <string, string>(_config, _serializer, _serializer)) { _log.Debug($"{producer.Name} producing on {topic}."); var task = producer.ProduceAsync(topic, uri, xml); var result = task.Result; _log.Debug($"Partition: {result.Partition}; Offset: {result.Offset}"); } } catch (Exception ex) { _log.Warn($"Error producing on topic: {topic}", ex); } }); }
public void TestSetUp() { _devKit = new DevKit141Aspect(TestContext); _dataAdapter = _devKit.Container.Resolve <IWitsmlDataAdapter <DbAuditHistory> >(); _changeLog = new DbAuditHistory { Uid = _devKit.Uid(), Name = _devKit.Name(), UidObject = _devKit.Uid(), NameObject = _devKit.Name(), ObjectType = ObjectTypes.Well, LastChangeType = ChangeInfoType.add, LastChangeInfo = $"Well was added for test {TestContext.TestName}", ChangeHistory = new List <ChangeHistory>() }; _changeLog.CommonData = _changeLog.CommonData.Create(); _changeLog.ChangeHistory.Add(new ChangeHistory { ChangeInfo = _changeLog.LastChangeInfo, ChangeType = _changeLog.LastChangeType, DateTimeChange = _changeLog.CommonData.DateTimeLastChange }); }
/// <summary> /// Sends the notification messages for the specified entity. /// </summary> /// <typeparam name="T">The data object type.</typeparam> /// <param name="entity">The changed entity.</param> /// <param name="auditHistory">The audit history.</param> public void SendNotifications <T>(T entity, DbAuditHistory auditHistory) { // No action if broker list not configured if (string.IsNullOrWhiteSpace(KafkaSettings.BrokerList)) { return; } var uri = auditHistory.Uri.ToLowerInvariant(); var xml = WitsmlParser.ToXml(entity); var topic = auditHistory.LastChangeType == ChangeInfoType.delete ? KafkaSettings.DeleteTopicName : auditHistory.LastChangeType == ChangeInfoType.add ? KafkaSettings.InsertTopicName : KafkaSettings.UpdateTopicName; SendNotification(topic, uri, xml); // For backward compatibility with ETP v1.1 if (auditHistory.LastChangeType != ChangeInfoType.delete) { SendNotification(KafkaSettings.UpsertTopicName, uri, xml); } }
/// <summary> /// Audits the entity. Override this method to adjust the audit record /// before it is submitted to the database or to prevent the audit. /// </summary> /// <param name="entity">The changed entity.</param> /// <param name="auditHistory">The audit history.</param> /// <param name="isNewEntry">if set to <c>true</c> add a new entry.</param> protected virtual void AuditEntity(T entity, DbAuditHistory auditHistory, bool isNewEntry) { // Ensure change log support has not been disabled if (!_isDbAuditHistoryEnabled) { return; } if (isNewEntry) { AuditHistoryAdapter?.InsertEntity(auditHistory); } else { AuditHistoryAdapter?.ReplaceEntity(auditHistory, auditHistory.GetUri()); } var dataObject = entity as IDataObject; if (dataObject != null) { var collection = dataObject.CreateCollection(); AuditHistoryAdapter?.QueueNotification(collection, auditHistory); } else { AuditHistoryAdapter?.QueueNotification(entity, auditHistory); } }
/// <summary> /// Audits the entity. Override this method to adjust the audit record /// before it is submitted to the database or to prevent the audit. /// </summary> /// <param name="entity">The changed entity.</param> /// <param name="auditHistory">The audit history.</param> /// <param name="isNewEntry">if set to <c>true</c> add a new entry.</param> protected virtual void AuditEntity(T entity, DbAuditHistory auditHistory, bool isNewEntry) { if (isNewEntry) { AuditHistoryAdapter?.InsertEntity(auditHistory); } else { AuditHistoryAdapter?.ReplaceEntity(auditHistory, auditHistory.GetUri()); } var dataObject = entity as IDataObject; if (dataObject != null) { var collection = dataObject.CreateCollection(); AuditHistoryAdapter?.QueueNotification(collection, auditHistory); } else { AuditHistoryAdapter?.QueueNotification(entity, auditHistory); } }
/// <summary> /// Audits the entity. Override this method to adjust the audit record /// before it is submitted to the database or to prevent the audit. /// </summary> /// <param name="entity">The changed entity.</param> /// <param name="auditHistory">The audit history.</param> /// <param name="exists">if set to <c>true</c> the entry exists.</param> protected override void AuditEntity(DbGrowingObject entity, DbAuditHistory auditHistory, bool exists) { // Excluding DbGrowingObject from audit history }
/// <summary> /// Audits the entity. Override this method to adjust the audit record /// before it is submitted to the database or to prevent the audit. /// </summary> /// <param name="entity">The changed entity.</param> /// <param name="auditHistory">The audit history.</param> /// <param name="exists">if set to <c>true</c> the entry exists.</param> protected override void AuditEntity(DbTransaction entity, DbAuditHistory auditHistory, bool exists) { // Excluding DbTransaction from audit history }