/// <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); }
/// <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); }
/// <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(); }
private void UpdateIndexInfo(EtpUri uri, IList <ChannelIndexInfo> indexInfos, TimeSpan?offset) { var entity = GetEntity(uri); Logger.DebugFormat("Updating index info for uid '{0}' and name '{1}'.", entity.Uuid, entity.Citation.Title); // Add ChannelIndex for each index var headerUpdate = MongoDbUtility.BuildPushEach <ChannelSet, ChannelIndex>(null, "Index", indexInfos.Select(CreateChannelIndex)); // TODO: Update Citation //headerUpdate = UpdateCommonData(headerUpdate, entity, offset); var mongoUpdate = new MongoDbUpdate <ChannelSet>(Container, GetCollection(), null); var filter = GetEntityFilter(uri); mongoUpdate.UpdateFields(filter, headerUpdate); }
private void UpdateChannels(EtpUri uri, ChannelDataReader reader, TimeSpan?offset) { var entity = GetEntity(uri); Logger.DebugFormat("Updating channels for uid '{0}' and name '{1}'.", entity.Uuid, entity.Citation.Title); var isTimeIndex = reader.Indices.Take(1).Select(x => x.IsTimeIndex).FirstOrDefault(); var channels = reader.Mnemonics .Select((x, i) => new { Mnemonic = x, Index = i }) .Where(x => entity.Channel.GetByMnemonic(x.Mnemonic) == null) .Select(x => CreateChannel(uri, x.Mnemonic, reader.Units[x.Index], reader.DataTypes[x.Index], isTimeIndex, entity.Index)); var mongoUpdate = new MongoDbUpdate <ChannelSet>(Container, GetCollection(), null); var headerUpdate = MongoDbUtility.BuildPushEach <ChannelSet, Channel>(null, "Channel", channels); var filter = GetEntityFilter(uri); mongoUpdate.UpdateFields(filter, headerUpdate); }
/// <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); } } }