Exemplo n.º 1
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);
        }