Exemplo n.º 1
0
        /// <summary>
        /// Partials the delete entity.
        /// </summary>
        /// <typeparam name="TObject">The type of the object.</typeparam>
        /// <param name="dbCollectionName">Name of the database collection.</param>
        /// <param name="parser">The parser.</param>
        /// <param name="uri">The URI.</param>
        /// <exception cref="WitsmlException"></exception>
        protected void PartialDeleteEntity <TObject>(string dbCollectionName, WitsmlQueryParser parser, EtpUri uri)
        {
            try
            {
                Logger.DebugFormat("Partial Deleting {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>(GetIgnoredElementNamesForUpdate(parser));

                var partialDelete = new MongoDbDelete <TObject>(Container, collection, parser, IdPropertyName, ignores);
                partialDelete.PartialDelete(current, uri, updates);

                var transaction = Transaction;
                if (transaction == null)
                {
                    return;
                }

                transaction.Attach(MongoDbAction.Update, dbCollectionName, IdPropertyName, current.ToBsonDocument(), uri);
                transaction.Save();
            }
            catch (MongoException ex)
            {
                Logger.ErrorFormat("Error partial deleting {0} MongoDb collection: {1}", dbCollectionName, ex);
                throw new WitsmlException(ErrorCodes.ErrorUpdatingInDataStore, ex);
            }
        }
Exemplo n.º 2
0
        public void MongoDbUtility_CreateUpdateFields_Returns_Dictionary_Of_common_Objects_For_Update()
        {
            var commonPropertiesToUpdate = MongoDbUtility.CreateUpdateFields <Well>();

            Assert.AreEqual(1, commonPropertiesToUpdate.Count);
            Assert.IsNotNull(commonPropertiesToUpdate["CommonData.DateTimeLastChange"]);

            commonPropertiesToUpdate = MongoDbUtility.CreateUpdateFields <Witsml200.Well>();
            Assert.AreEqual(1, commonPropertiesToUpdate.Count);
            Assert.IsNotNull(commonPropertiesToUpdate["Citation.LastUpdate"]);

            commonPropertiesToUpdate = MongoDbUtility.CreateUpdateFields <DateTime>();
            Assert.AreEqual(0, commonPropertiesToUpdate.Count);
        }