Ejemplo n.º 1
0
        /// <summary>
        /// Updates the data row count for the log.
        /// </summary>
        /// <param name="uri">The URI.</param>
        protected override void UpdateDataRowCount(EtpUri uri)
        {
            var current      = GetEntity(uri);
            var dataRowCount = ChannelDataChunkAdapter.GetDataRowCount(uri);

            if (current.DataRowCount.Equals(dataRowCount))
            {
                return;
            }

            // Update the dataRowCount in the header
            var updates = GetDataRowCountUpdate(null, current, dataRowCount);
            var filter  = MongoDbUtility.GetEntityFilter <Log>(uri);
            var fields  = MongoDbUtility.CreateUpdateFields <Log>();

            Logger.Debug($"Updating dataRowCount for URI: {uri}");
            updates = MongoDbUtility.BuildUpdate(updates, fields);

            var mongoUpdate = new MongoDbUpdate <Log>(Container, GetCollection(), null, IdPropertyName);

            mongoUpdate.UpdateFields(filter, updates);

            // Join existing Transaction
            var transaction = Transaction;

            transaction.Attach(MongoDbAction.Update, DbCollectionName, IdPropertyName, current.ToBsonDocument(), uri);
            transaction.Save();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the IsActive field of a wellbore.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="isActive">IsActive flag on wellbore is set to the value.</param>
        public void UpdateIsActive(EtpUri uri, bool isActive)
        {
            var wellboreEntity = GetEntity(uri);

            if (wellboreEntity == null)
            {
                Logger.DebugFormat("Wellbore not found with uri '{0}'", uri);
                return;
            }

            if (wellboreEntity.IsActive.GetValueOrDefault() == isActive)
            {
                return;
            }

            Logger.DebugFormat("Updating wellbore isActive for uid '{0}' and name '{1}'.", wellboreEntity.Uuid, wellboreEntity.Citation.Title);

            Transaction.Attach(MongoDbAction.Update, DbCollectionName, IdPropertyName, wellboreEntity.ToBsonDocument(), uri);
            Transaction.Save();

            var filter         = MongoDbUtility.GetEntityFilter <Wellbore>(uri);
            var wellboreUpdate = MongoDbUtility.BuildUpdate <Wellbore>(null, "IsActive", isActive);
            var mongoUpdate    = new MongoDbUpdate <Wellbore>(Container, GetCollection(), null);

            mongoUpdate.UpdateFields(filter, wellboreUpdate);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the growing object's header and change history.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="updates">The header update definition.</param>
        /// <param name="isAuditUpdate">if set to <c>true</c> audit the update.</param>
        protected virtual void UpdateGrowingObject(EtpUri uri, UpdateDefinition <T> updates = null, bool isAuditUpdate = true)
        {
            var current = GetEntity(uri);

            // Update the growing object's header
            var filter = MongoDbUtility.GetEntityFilter <T>(uri);
            var fields = MongoDbUtility.CreateUpdateFields <T>();

            Logger.Debug($"Updating date time last change for URI: {uri}");
            updates = MongoDbUtility.BuildUpdate(updates, fields);

            var mongoUpdate = new MongoDbUpdate <T>(Container, GetCollection(), null, IdPropertyName);

            mongoUpdate.UpdateFields(filter, updates);

            // Join existing Transaction
            var transaction = Transaction;

            transaction.Attach(MongoDbAction.Update, DbCollectionName, IdPropertyName, current.ToBsonDocument(), uri);
            transaction.Save();

            if (!isAuditUpdate)
            {
                return;
            }

            var changeType = WitsmlOperationContext.Current.Request.Function == Functions.AddToStore
                ? Witsml141.ReferenceData.ChangeInfoType.add
                : Witsml141.ReferenceData.ChangeInfoType.update;

            // Audit entity
            AuditEntity(uri, changeType);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the data row count update.
        /// </summary>
        /// <param name="logHeaderUpdate">The log header update.</param>
        /// <param name="currentLog">The current log.</param>
        /// <param name="dataRowCount">The data row count.</param>
        /// <returns>
        /// The current log header update.
        /// </returns>
        protected override UpdateDefinition <Log> GetDataRowCountUpdate(UpdateDefinition <Log> logHeaderUpdate, Log currentLog, int dataRowCount)
        {
            if (dataRowCount.Equals(currentLog.DataRowCount))
            {
                return(logHeaderUpdate);
            }

            logHeaderUpdate = MongoDbUtility.BuildUpdate(logHeaderUpdate, "DataRowCountSpecified", true);
            return(MongoDbUtility.BuildUpdate(logHeaderUpdate, "DataRowCount", dataRowCount));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates the entities.
        /// </summary>
        /// <param name="transactionId">The transaction identifier.</param>
        /// <param name="newTransactionId">The new transaction identifier.</param>
        public void UpdateEntities(string transactionId, string newTransactionId)
        {
            Logger.Debug($"Transferring transactions from Transaction ID: {transactionId} to {newTransactionId}");
            var filter = MongoDbUtility.BuildFilter <DbTransaction>(TransactionIdField, transactionId);
            var update = MongoDbUtility.BuildUpdate <DbTransaction>(null, TransactionIdField, newTransactionId);

            var collection = GetCollection();

            collection.UpdateMany(filter, update);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Updates the common data.
        /// </summary>
        /// <param name="logHeaderUpdate">The log header update.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="offset">The offset.</param>
        /// <returns></returns>
        protected override UpdateDefinition <Log> UpdateCommonData(UpdateDefinition <Log> logHeaderUpdate, Log entity, TimeSpan?offset)
        {
            if (entity?.CommonData == null)
            {
                return(logHeaderUpdate);
            }

            if (entity.CommonData.DateTimeCreation.HasValue)
            {
                var creationTime = entity.CommonData.DateTimeCreation.ToOffsetTime(offset);
                logHeaderUpdate = MongoDbUtility.BuildUpdate(logHeaderUpdate, "CommonData.DateTimeCreation", creationTime?.ToString("o"));
                Logger.DebugFormat("Updating Common Data create time to '{0}'", creationTime);
            }

            if (entity.CommonData.DateTimeLastChange.HasValue)
            {
                var updateTime = entity.CommonData.DateTimeLastChange.ToOffsetTime(offset);
                logHeaderUpdate = MongoDbUtility.BuildUpdate(logHeaderUpdate, "CommonData.DateTimeLastChange", updateTime?.ToString("o"));
                Logger.DebugFormat("Updating Common Data update time to '{0}'", updateTime);
            }

            return(logHeaderUpdate);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Updates the IsActive field of a wellbore.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="isActive">IsActive flag on wellbore is set to the value.</param>
        public void UpdateIsActive(EtpUri uri, bool isActive)
        {
            var wellboreEntity = GetEntity(uri);

            if (wellboreEntity == null)
            {
                Logger.DebugFormat("Wellbore not found with uri '{0}'", uri);
                return;
            }

            if (wellboreEntity.IsActive.GetValueOrDefault() == isActive)
            {
                return;
            }

            Logger.DebugFormat("Updating wellbore isActive for uid '{0}' and name '{1}'.", wellboreEntity.Uuid, wellboreEntity.Citation.Title);

            var filter = MongoDbUtility.GetEntityFilter <Wellbore>(uri);
            var fields = MongoDbUtility.CreateUpdateFields <Wellbore>();

            var wellboreUpdate = MongoDbUtility.BuildUpdate <Wellbore>(null, "IsActive", isActive);

            wellboreUpdate = MongoDbUtility.BuildUpdate(wellboreUpdate, fields);

            var mongoUpdate = new MongoDbUpdate <Wellbore>(Container, GetCollection(), null);

            mongoUpdate.UpdateFields(filter, wellboreUpdate);

            // Join existing Transaction
            var transaction = Transaction;

            transaction.Attach(MongoDbAction.Update, DbCollectionName, IdPropertyName, wellboreEntity.ToBsonDocument(), uri);
            transaction.Save();

            // Audit entity
            AuditEntity(uri, Energistics.DataAccess.WITSML141.ReferenceData.ChangeInfoType.update);
        }
        private void UpdateIndexRange(EtpUri uri, ChannelSet entity, Dictionary <string, Range <double?> > ranges, IEnumerable <string> mnemonics)
        {
            var mongoUpdate        = new MongoDbUpdate <ChannelSet>(Container, GetCollection(), null);
            var channelIndexUpdate = default(UpdateDefinition <ChannelSet>);
            var filter             = GetEntityFilter(uri);

            if (entity.Citation != null)
            {
                if (entity.Citation.Creation.HasValue)
                {
                    var creationTime = entity.Citation.Creation;
                    channelIndexUpdate = MongoDbUtility.BuildUpdate(channelIndexUpdate, "Citation.Creation", creationTime.Value.ToUniversalTime().ToString(_utcFormat));
                }
                if (entity.Citation.LastUpdate.HasValue)
                {
                    var updateTime = entity.Citation.LastUpdate;
                    channelIndexUpdate = MongoDbUtility.BuildUpdate(channelIndexUpdate, "Citation.LastUpdate", updateTime.Value.ToUniversalTime().ToString(_utcFormat));
                }
            }

            var indexChannel  = entity.Index.FirstOrDefault();
            var indexType     = indexChannel.IndexType;
            var indexMnemonic = indexChannel.Mnemonic;
            var range         = ranges[indexMnemonic];

            if (range.Start.HasValue)
            {
                var start = UpdateIndexValue(indexType, entity.StartIndex, range.Start.Value);
                channelIndexUpdate = MongoDbUtility.BuildUpdate(channelIndexUpdate, "StartIndex", start);
            }

            if (range.End.HasValue)
            {
                var end = UpdateIndexValue(indexType, entity.EndIndex, range.End.Value);
                channelIndexUpdate = MongoDbUtility.BuildUpdate(channelIndexUpdate, "EndIndex", end);
            }

            if (channelIndexUpdate != null)
            {
                mongoUpdate.UpdateFields(filter, channelIndexUpdate);
            }

            var idField = MongoDbUtility.LookUpIdField(typeof(Channel), "Uuid");

            foreach (var mnemonic in mnemonics)
            {
                var channel = entity.Channel.FirstOrDefault(c => c.Mnemonic.EqualsIgnoreCase(mnemonic));
                if (channel == null)
                {
                    continue;
                }

                var channelFilter = Builders <ChannelSet> .Filter.And(filter,
                                                                      MongoDbUtility.BuildFilter <ChannelSet>("Channel." + idField, channel.Uuid));

                UpdateDefinition <ChannelSet> updates = null;
                range = ranges[mnemonic];

                if (range.Start.HasValue)
                {
                    var start = UpdateIndexValue(indexType, channel.StartIndex, range.Start.Value);
                    updates = MongoDbUtility.BuildUpdate(updates, "Channel.$.StartIndex", start);
                }

                if (range.End.HasValue)
                {
                    var end = UpdateIndexValue(indexType, channel.EndIndex, range.End.Value);
                    updates = MongoDbUtility.BuildUpdate(updates, "Channel.$.EndIndex", end);
                }

                if (updates != null)
                {
                    mongoUpdate.UpdateFields(channelFilter, updates);
                }
            }
        }