Example #1
0
        /// <summary>
        /// Create new instance of ProcessManager
        /// When multiple threads try to create new ProcessManager instance, only the first one is allowed.
        /// All subsequent threads will update data instead.
        /// </summary>
        /// <param name="data"></param>
        public void InsertData(IProcessManagerData data)
        {
            var collectionName = GetCollectionName(data);

            IMongoCollection <MongoDbSslData <IProcessManagerData> > collection = _mongoDatabase.GetCollection <MongoDbSslData <IProcessManagerData> >(collectionName);
            var indexOptions = new CreateIndexOptions();
            var indexKeys    = Builders <MongoDbSslData <IProcessManagerData> > .IndexKeys.Ascending("Data.CorrelationId");

            var indexModel = new CreateIndexModel <MongoDbSslData <IProcessManagerData> >(indexKeys, indexOptions);

            collection.Indexes.CreateOne(indexModel);

            var mongoDbData = new MongoDbSslData <IProcessManagerData>
            {
                Data    = data,
                Version = 1,
                //Id = Guid.NewGuid()
            };

            var filter = Builders <MongoDbSslData <IProcessManagerData> > .Filter.Eq("Data.CorrelationId", mongoDbData.Data.CorrelationId);

            collection.ReplaceOne(filter, mongoDbData, new ReplaceOptions {
                IsUpsert = true
            });
        }
Example #2
0
        /// <summary>
        /// Create new instance of ProcessManager
        /// When multiple threads try to create new ProcessManager instance, only the first one is allowed.
        /// All subsequent threads will update data instead.
        /// </summary>
        /// <param name="data"></param>
        public void InsertData(IProcessManagerData data)
        {
            var collectionName = GetCollectionName(data);

            MongoCollection collection = _mongoDatabase.GetCollection(collectionName);

            collection.CreateIndex("CorrelationId");

            var mongoDbData = new MongoDbSslData <IProcessManagerData>
            {
                Data    = data,
                Version = 1,
                Id      = Guid.NewGuid()
            };

            collection.FindAndModify(Query.EQ("CorrelationId", mongoDbData.Data.CorrelationId), SortBy.Null, Update.Replace(mongoDbData), false, true);
        }