Example #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();
        }
        private List <Log> GetLogsByUris(List <EtpUri> uris)
        {
            if (uris.Any(u => u.IsBaseUri))
            {
                return(GetAll(null));
            }

            var logUris      = MongoDbUtility.GetObjectUris(uris, ObjectTypes.Log);
            var wellboreUris = MongoDbUtility.GetObjectUris(uris, ObjectTypes.Wellbore);
            var wellUris     = MongoDbUtility.GetObjectUris(uris, ObjectTypes.Well);

            if (wellUris.Any())
            {
                var wellboreFilters = wellUris.Select(wellUri => MongoDbUtility.BuildFilter <Wellbore>("Well.Uuid", wellUri.ObjectId)).ToList();
                var wellbores       = GetCollection <Wellbore>(ObjectNames.Wellbore200)
                                      .Find(Builders <Wellbore> .Filter.Or(wellboreFilters)).ToList();
                wellboreUris.AddRange(wellbores.Select(w => w.GetUri()).Where(u => !wellboreUris.Contains(u)));
            }

            var logFilters = wellboreUris.Select(wellboreUri => MongoDbUtility.BuildFilter <Log>("Wellbore.Uuid", wellboreUri.ObjectId)).ToList();

            logFilters.AddRange(logUris.Select(logUri => MongoDbUtility.GetEntityFilter <Log>(logUri, IdPropertyName)));

            return(logFilters.Any() ? GetCollection().Find(Builders <Log> .Filter.Or(logFilters)).ToList() : new List <Log>());
        }
Example #3
0
        private List <Channel> GetChannelsByUris(params EtpUri[] uris)
        {
            if (uris.Any(u => u.IsBaseUri))
            {
                return(GetAll(null));
            }

            var channelUris  = MongoDbUtility.GetObjectUris(uris, ObjectTypes.Channel);
            var wellboreUris = MongoDbUtility.GetObjectUris(uris, ObjectTypes.Wellbore);
            var wellUris     = MongoDbUtility.GetObjectUris(uris, ObjectTypes.Well);

            if (wellUris.Any())
            {
                var wellboreFilters = wellUris.Select(wellUri => MongoDbUtility.BuildFilter <Wellbore>("Well.Uuid", wellUri.ObjectId)).ToList();
                var wellbores       = GetCollection <Wellbore>(ObjectNames.Wellbore200)
                                      .Find(Builders <Wellbore> .Filter.Or(wellboreFilters)).ToList();
                wellboreUris.AddRange(wellbores.Select(w => w.GetUri()).Where(u => !wellboreUris.Contains(u)));
            }

            var channelFilters = wellboreUris.Select(wellboreUri => MongoDbUtility.BuildFilter <Channel>("Wellbore.Uuid", wellboreUri.ObjectId)).ToList();

            channelFilters.AddRange(channelUris.Select(u => MongoDbUtility.GetEntityFilter <Channel>(u, IdPropertyName)));

            return(channelFilters.Any() ? GetCollection().Find(Builders <Channel> .Filter.Or(channelFilters)).ToList() : new List <Channel>());
        }
Example #4
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);
        }
        public void DatabaseFromUrl()
        {
            var url      = MongoDbUtility.GetMongoUrlFromConfig("MongoFrameworkTests");
            var database = MongoDbUtility.GetDatabase(url);

            Assert.IsNotNull(database);
        }
Example #6
0
        /// <summary>
        /// Deletes the transactions.
        /// </summary>
        /// <param name="transactionId">The tid.</param>
        public void DeleteTransactions(string transactionId)
        {
            var collection = GetCollection();
            var filter     = MongoDbUtility.BuildFilter <MongoDbTransaction>(TransactionIdField, transactionId);

            collection.DeleteMany(filter);
        }
Example #7
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);
        }
Example #8
0
        private List <ChannelDataChunk> GetDataChunks(EtpUri uri)
        {
            var filter     = MongoDbUtility.BuildFilter <ChannelDataChunk>("Uri", uri.ToString());
            var database   = _provider.GetDatabase();
            var collection = database.GetCollection <ChannelDataChunk>("channelDataChunk");

            return(collection.Find(filter).ToList());
        }
Example #9
0
 public void InvalidObjectId()
 {
     Assert.IsFalse(MongoDbUtility.IsValidObjectId(string.Empty));
     Assert.IsFalse(MongoDbUtility.IsValidObjectId("0"));
     Assert.IsFalse(MongoDbUtility.IsValidObjectId("a"));
     Assert.IsFalse(MongoDbUtility.IsValidObjectId("0123456789ABCDEFGHIJKLMN"));
     Assert.IsFalse(MongoDbUtility.IsValidObjectId(null));
 }
Example #10
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));
        }
Example #11
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);
        }
Example #12
0
        public void ValidObjectId()
        {
            var connection = TestConfiguration.GetConnection();
            var context    = new MongoDbContext(connection);

            var entity = new MongoDbUtilityModel();

            context.ChangeTracker.SetEntityState(entity, EntityEntryState.Added);
            context.SaveChanges();

            Assert.IsTrue(MongoDbUtility.IsValidObjectId(entity.Id));
        }
Example #13
0
        /// <summary>
        /// Deletes the transactions.
        /// </summary>
        /// <param name="transactionId">The tid.</param>
        public void DeleteTransactions(string transactionId)
        {
            Logger.Debug($"Deleting transactions for Transaction ID: {transactionId}");

            // Delete the binary files
            DeleteTransactionMongoFiles(transactionId);

            // Delete the document
            var collection = GetCollection();
            var filter     = MongoDbUtility.BuildFilter <DbTransaction>(TransactionIdField, transactionId);

            collection.DeleteMany(filter);
        }
        public void ValidObjectId()
        {
            var database        = TestConfiguration.GetDatabase();
            var entityContainer = new DbEntityCollection <MongoDbUtilityModel>();
            var writer          = new DbEntityWriter <MongoDbUtilityModel>(database);

            var entity = new MongoDbUtilityModel();

            entityContainer.Update(entity, DbEntityEntryState.Added);
            writer.Write(entityContainer);

            Assert.IsTrue(MongoDbUtility.IsValidObjectId(entity.Id));
        }
        public void ValidObjectId()
        {
            var connection       = TestConfiguration.GetConnection();
            var writerPipeline   = new EntityWriterPipeline <MongoDbUtilityModel>(connection);
            var entityCollection = new EntityCollection <MongoDbUtilityModel>();

            writerPipeline.AddCollection(entityCollection);

            var entity = new MongoDbUtilityModel();

            entityCollection.Update(entity, EntityEntryState.Added);
            writerPipeline.Write();

            Assert.IsTrue(MongoDbUtility.IsValidObjectId(entity.Id));
        }
        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 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);
        }
Example #19
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 #20
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 List <ChannelSet> GetChannelSetByUris(List <EtpUri> uris)
        {
            if (uris.Any(u => u.IsBaseUri))
            {
                return(GetAll(null));
            }

            _wellboreUris   = new List <EtpUri>();
            _channelSetUris = new List <EtpUri>();

            var channelSetUris = MongoDbUtility.GetObjectUris(uris, ObjectTypes.ChannelSet);
            var wellboreUris   = MongoDbUtility.GetObjectUris(uris, ObjectTypes.Wellbore);
            var wellUris       = MongoDbUtility.GetObjectUris(uris, ObjectTypes.Well);

            if (wellUris.Any())
            {
                var wellboreFilters = wellUris.Select(wellUri => MongoDbUtility.BuildFilter <Wellbore>("Well.Uuid", wellUri.ObjectId)).ToList();
                var wellbores       = GetCollection <Wellbore>(ObjectNames.Wellbore200)
                                      .Find(Builders <Wellbore> .Filter.Or(wellboreFilters)).ToList();
                wellboreUris.AddRange(wellbores.Select(w => w.GetUri()).Where(u => !wellboreUris.Contains(u)));
            }

            _wellboreUris.AddRange(wellboreUris);
            var channelSetFilters = wellboreUris.Select(wellboreUri => MongoDbUtility.BuildFilter <ChannelSet>("Wellbore.Uuid", wellboreUri.ObjectId)).ToList();

            _channelSetUris.AddRange(channelSetUris);
            channelSetFilters.AddRange(channelSetUris.Select(GetEntityFilter));

            var channelUris = MongoDbUtility.GetObjectUris(uris, ObjectTypes.Channel).Where(u => u.Parent.ObjectType == ObjectTypes.ChannelSet);

            foreach (var channelUri in channelUris)
            {
                channelSetFilters.Add(MongoDbUtility.BuildFilter <ChannelSet>(IdPropertyName, channelUri.Parent.ObjectId));
            }

            return(channelSetFilters.Any() ? GetCollection().Find(Builders <ChannelSet> .Filter.Or(channelSetFilters)).ToList() : new List <ChannelSet>());
        }
        public void UrlFromConfigFound()
        {
            var url = MongoDbUtility.GetMongoUrlFromConfig("MongoFrameworkTests");

            Assert.IsNotNull(url);
        }
        public void Log141Adapter_AddToStore_Can_Add_Data_Chunk_Exceeds_MongoDb_Document_Size()
        {
            var response = _devKit.Add <WellList, Well>(_well);

            // Adjust Points and Nodes for large file
            WitsmlSettings.LogMaxDataPointsAdd = 5000000;
            WitsmlSettings.LogMaxDataNodesAdd  = 15000;
            WitsmlSettings.LogMaxDataPointsGet = 5000000;
            WitsmlSettings.LogMaxDataNodesGet  = 15000;

            _wellbore.UidWell = response.SuppMsgOut;
            response          = _devKit.Add <WellboreList, Wellbore>(_wellbore);

            var xmlfile = Path.Combine(_testDataDir, string.Format(_exceedFileFormat, "log"));
            var xmlin   = File.ReadAllText(xmlfile);

            var logList = EnergisticsConverter.XmlToObject <LogList>(xmlin);

            Assert.IsNotNull(logList);

            var log = logList.Log.FirstOrDefault();

            Assert.IsNotNull(log);

            log.Uid          = null;
            log.UidWell      = _wellbore.UidWell;
            log.UidWellbore  = response.SuppMsgOut;
            log.NameWell     = _well.Name;
            log.NameWellbore = _wellbore.Name;

            var logDataAdded = log.LogData.FirstOrDefault();

            Assert.IsNotNull(logDataAdded);

            response = _devKit.Add <LogList, Log>(log);
            Assert.AreEqual((short)ErrorCodes.Success, response.Result);

            var uidLog = response.SuppMsgOut;

            log.Uid = uidLog;
            var uri = log.GetUri();

            // Query Channel Data Chunk
            var filter     = MongoDbUtility.BuildFilter <ChannelDataChunk>("Uri", uri.ToString());
            var database   = _provider.GetDatabase();
            var collection = database.GetCollection <ChannelDataChunk>("channelDataChunk");
            var chunks     = collection.Find(filter).ToList();

            Assert.IsTrue(chunks.Count > 0);

            // Query Mongo File
            var fileChunks = chunks.Where(c => string.IsNullOrEmpty(c.Data)).ToList();

            Assert.IsTrue(fileChunks.Count > 0);

            var bucket = new GridFSBucket(database, new GridFSBucketOptions
            {
                BucketName     = ChannelDataChunkAdapter.BucketName,
                ChunkSizeBytes = WitsmlSettings.ChunkSizeBytes
            });

            foreach (var fc in fileChunks)
            {
                Assert.IsNull(fc.Data);
                var mongoFileFilter = Builders <GridFSFileInfo> .Filter.Eq(fi => fi.Metadata[ChannelDataChunkAdapter.FileName], fc.Uid);

                var mongoFile = bucket.Find(mongoFileFilter).FirstOrDefault();
                Assert.IsNotNull(mongoFile);
            }

            // Query Log
            var query = new Log
            {
                Uid         = uidLog,
                UidWell     = log.UidWell,
                UidWellbore = log.UidWellbore
            };

            var results = _devKit.Query <LogList, Log>(query, optionsIn: OptionsIn.ReturnElements.All);

            Assert.AreEqual(1, results.Count);

            var result = results.First();

            Assert.IsNotNull(result);

            var logDataReturned = result.LogData.FirstOrDefault();

            Assert.IsNotNull(logDataReturned);

            Assert.AreEqual(logDataAdded.Data.Count, logDataReturned.Data.Count);
        }
 public void DatabaseFromNullUrl()
 {
     MongoDbUtility.GetDatabase((MongoDB.Driver.MongoUrl)null);
 }
 public void DatabaseFromNullOptions()
 {
     MongoDbUtility.GetDatabase((IMongoDbContextOptions)null);
 }
Example #26
0
        private long GetActiveWellboreCount(string wellboreUri)
        {
            var filter = MongoDbUtility.BuildFilter <DbGrowingObject>("WellboreUri", wellboreUri);

            return(GetCollection().CountDocuments(filter));
        }
Example #27
0
 private FilterDefinition <BsonDocument> GetDocumentFilter(EtpUri uri, string idPropertyName)
 {
     return(MongoDbUtility.GetEntityFilter <BsonDocument>(uri, idPropertyName));
 }
        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);
                }
            }
        }
        public void UrlFromConfigMissing()
        {
            var url = MongoDbUtility.GetMongoUrlFromConfig("ThisConnectionStringDoesntExist");

            Assert.IsNull(url);
        }
Example #30
0
 /// <summary>
 /// Gets the entity filter for the specified URI.
 /// </summary>
 /// <typeparam name="TObject">The type of the object.</typeparam>
 /// <param name="uri">The URI.</param>
 /// <param name="idPropertyName">Name of the identifier property.</param>
 /// <returns>The entity filter.</returns>
 protected override FilterDefinition <TObject> GetEntityFilter <TObject>(EtpUri uri, string idPropertyName)
 {
     return(MongoDbUtility.BuildFilter <TObject>(idPropertyName, uri.ToString()));
 }