Example #1
0
        /// <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);
            }
        }
Example #2
0
        /// <summary>
        /// Audits the entity.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="changeType">Type of the change.</param>
        protected virtual void AuditEntity(EtpUri uri, Witsml141.ReferenceData.ChangeInfoType changeType)
        {
            // Ensure change log support has not been disabled
            if (!_isDbAuditHistoryEnabled)
            {
                return;
            }

            if (AuditHistoryAdapter == null || ObjectTypes.ChangeLog.Equals(uri.ObjectType))
            {
                return;
            }

            var current      = GetEntity(uri); //, GetAuditProjectionPropertyNames());
            var auditHistory = AuditHistoryAdapter.GetAuditHistory(uri, current, changeType);
            var isNewEntry   = string.IsNullOrWhiteSpace(auditHistory.Uid);

            if (isNewEntry)
            {
                auditHistory.Uid  = auditHistory.NewUid();
                auditHistory.Name = auditHistory.Uid;
            }

            AuditEntity(current, auditHistory, isNewEntry);
        }
Example #3
0
        private void UpdateGrowingObject(T current, bool isHeaderUpdateOnly, bool?isAppending = null, double?startIndex = null, double?endIndex = null, string indexUom = null)
        {
            // Currently growing
            if (IsObjectGrowing(current))
            {
                return;
            }

            var changeHistory = AuditHistoryAdapter.GetCurrentChangeHistory();

            changeHistory.UpdatedHeader = true;

            // Currently not growing with header only update
            if (isHeaderUpdateOnly)
            {
                UpdateGrowingObject(current.GetUri());
                return;
            }

            // Currently not growing with start/end indexes changed
            AuditHistoryAdapter.SetChangeHistoryIndexes(changeHistory, startIndex, endIndex, indexUom);

            // Currently not growing with mudlog geology intervals updated/appended/deleted
            var isObjectGrowingToggled = isAppending.GetValueOrDefault() ? true : (bool?)null;

            UpdateGrowingObject(current, null, isObjectGrowingToggled);
        }
Example #4
0
        /// <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);
            }
        }
Example #5
0
        /// <summary>
        /// Updates the growing status for the specified growing object. If isObjectGrowing has a value it will update
        /// the objectGrowing flag for the entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="updates">The header update definition.</param>
        /// <param name="isObjectGrowing">Is the object currently growing.</param>
        protected virtual void UpdateGrowingObject(T entity, UpdateDefinition <T> updates, bool?isObjectGrowing = null)
        {
            var uri = GetUri(entity);
            var isCurrentObjectGrowing = IsObjectGrowing(entity);
            var isAuditUpdate          = !isObjectGrowing.GetValueOrDefault();

            // Set change history object growing flag
            var changeHistory = AuditHistoryAdapter.GetCurrentChangeHistory();

            changeHistory.ObjectGrowingState = isCurrentObjectGrowing;

            // Check to see if the object growing flag needs to be toggled
            if (isObjectGrowing.HasValue && isCurrentObjectGrowing != isObjectGrowing)
            {
                // Only allow DbGrowingObjectDataAdapter to set flag to false
                Logger.Debug($"Updating object growing flag for URI: {uri}; Value: {isObjectGrowing.Value}");
                var flag = MongoDbUtility.CreateObjectGrowingFields <T>(isObjectGrowing.Value);
                updates = MongoDbUtility.BuildUpdate(updates, flag);

                // Only audit an append of data when first toggling object growing flag
                changeHistory.ObjectGrowingState = isObjectGrowing;
                isAuditUpdate = true;
            }

            UpdateGrowingObject(uri, updates, isAuditUpdate);

            // If the object is not currently growing do not update wellbore isActive
            if (!isObjectGrowing.GetValueOrDefault())
            {
                return;
            }

            // Update dbGrowingObject timestamp
            DbGrowingObjectAdapter.UpdateLastAppendDateTime(uri, GetWellboreUri(uri));
            // Update Wellbore isActive
            UpdateWellboreIsActive(uri, true);
        }
Example #6
0
        /// <summary>
        /// Replaces an object in the data store.
        /// </summary>
        /// <typeparam name="TObject">The type of the object.</typeparam>
        /// <param name="dbCollectionName">The name of the database collection.</param>
        /// <param name="entity">The object to be replaced.</param>
        /// <param name="uri">The data object URI.</param>
        /// <param name="ignoreServerProperties">if set to <c>true</c> ignores server properties.</param>
        /// <exception cref="WitsmlException"></exception>
        protected void ReplaceEntity <TObject>(string dbCollectionName, TObject entity, EtpUri uri, bool ignoreServerProperties = true)
        {
            try
            {
                Logger.DebugFormat("Replacing {0} MongoDb collection", dbCollectionName);

                var collection = GetCollection <TObject>(dbCollectionName);
                var current    = GetEntity <TObject>(uri, dbCollectionName);
                //var updates = MongoDbUtility.CreateUpdateFields<TObject>();
                var ignores = MongoDbUtility.CreateIgnoreFields <TObject>(null, true);

                if (ignoreServerProperties)
                {
                    ignores.AddRange(GetIgnoredElementNamesForUpdate(null) ?? Enumerable.Empty <string>());
                }

                var mapper = new DataObjectMapper <TObject>(Container, null, ignores);
                mapper.Map(current, entity);

                // Update Last Change Date
                AuditHistoryAdapter.SetDateTimeLastChange(entity);

                var filter = GetEntityFilter <TObject>(uri, IdPropertyName);
                collection.ReplaceOne(filter, entity);

                var transaction = Transaction;
                transaction.Attach(MongoDbAction.Update, dbCollectionName, IdPropertyName, current.ToBsonDocument(), uri);
                transaction.Save();

                AuditUpdate(uri);
            }
            catch (MongoException ex)
            {
                Logger.ErrorFormat("Error replacing {0} MongoDb collection: {1}", dbCollectionName, ex);
                throw new WitsmlException(ErrorCodes.ErrorReplacingInDataStore, ex);
            }
        }